diff --git a/.env.example b/.env.example index b66fecf35a..0c83f124a0 100644 --- a/.env.example +++ b/.env.example @@ -261,6 +261,9 @@ LARGE_AKASH_CHAT_API_MODEL= # Default: Meta-Llama-3-1-405B-Instruct-FP8 FAL_API_KEY= FAL_AI_LORA_PATH= +# Web search API Configuration +TAVILY_API_KEY= + # WhatsApp Cloud API Configuration WHATSAPP_ACCESS_TOKEN= # Permanent access token from Facebook Developer Console WHATSAPP_PHONE_NUMBER_ID= # Phone number ID from WhatsApp Business API diff --git a/agent/src/index.ts b/agent/src/index.ts index e7101cbd8c..c42c92bdaf 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -237,6 +237,7 @@ export function getTokenForProvider( character.settings?.secrets?.OPENAI_API_KEY || settings.OPENAI_API_KEY ); + case ModelProviderName.CLAUDE_VERTEX: case ModelProviderName.ANTHROPIC: return ( character.settings?.secrets?.ANTHROPIC_API_KEY || diff --git a/packages/core/src/generation.ts b/packages/core/src/generation.ts index 00fdf6060a..730a5b775e 100644 --- a/packages/core/src/generation.ts +++ b/packages/core/src/generation.ts @@ -1219,6 +1219,10 @@ export const generateWebSearch = async ( api_key: apiKey, query, include_answer: true, + max_results: 3, // 5 (default) + topic: "general", // "general"(default) "news" + search_depth: "basic", // "basic"(default) "advanced" + include_images: false, // false (default) true }), }); diff --git a/packages/plugin-web-search/src/index.ts b/packages/plugin-web-search/src/index.ts index 4d7d7be44c..68392a8967 100644 --- a/packages/plugin-web-search/src/index.ts +++ b/packages/plugin-web-search/src/index.ts @@ -8,8 +8,30 @@ import { State, } from "@ai16z/eliza"; import { generateWebSearch } from "@ai16z/eliza"; - import { SearchResult } from "@ai16z/eliza"; +import { encodingForModel, TiktokenModel } from "js-tiktoken"; + +const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000; +const DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo"; + +function getTotalTokensFromString( + str: string, + encodingName: TiktokenModel = DEFAULT_MODEL_ENCODING + ) { + const encoding = encodingForModel(encodingName); + return encoding.encode(str).length; + } + +function MaxTokens( + data: string, + maxTokens: number = DEFAULT_MAX_WEB_SEARCH_TOKENS + ): string { + + if (getTotalTokensFromString(data) >= maxTokens) { + return data.slice(0, maxTokens); + } + return data; + } const webSearch: Action = { name: "WEB_SEARCH", @@ -68,7 +90,7 @@ const webSearch: Action = { : ""; callback({ - text: responseList, + text: MaxTokens(responseList, DEFAULT_MAX_WEB_SEARCH_TOKENS), }); } else { elizaLogger.error("search failed or returned no data.");