Skip to content

Commit

Permalink
Merge branch 'develop' into xpu_detect
Browse files Browse the repository at this point in the history
  • Loading branch information
odilitime authored Dec 20, 2024
2 parents 45eb657 + 2217ac0 commit 429ee13
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
});

Expand Down
26 changes: 24 additions & 2 deletions packages/plugin-web-search/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit 429ee13

Please sign in to comment.