Skip to content

Commit

Permalink
use openai embeddings setting
Browse files Browse the repository at this point in the history
  • Loading branch information
o-on-x committed Nov 10, 2024
1 parent 15f7ba8 commit 432362b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ X_SERVER_URL=
XAI_API_KEY=
XAI_MODEL=

#Leave blank to use local embeddings
USE_OPENAI_EMBEDDING= #TRUE

#OpenRouter (Use one model for everything or set individual for small, medium, large tasks)
#leave blank to use defaults hermes 70b for small tasks & 405b for medium/large tasks
OPENROUTER_MODEL=
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "./types.ts";
import fs from "fs";
import { trimTokens } from "./generation.ts";
import settings from "./settings.ts";

function getRootPath() {
const __filename = fileURLToPath(import.meta.url);
Expand All @@ -33,7 +34,8 @@ export async function embed(runtime: IAgentRuntime, input: string) {

if (
runtime.character.modelProvider !== ModelProviderName.OPENAI &&
runtime.character.modelProvider !== ModelProviderName.OLLAMA
runtime.character.modelProvider !== ModelProviderName.OLLAMA &&
!settings.USE_OPENAI_EMBEDDING
) {

// make sure to trim tokens to 8192
Expand Down Expand Up @@ -78,9 +80,10 @@ export async function embed(runtime: IAgentRuntime, input: string) {
headers: {
"Content-Type": "application/json",
// TODO: make this not hardcoded
...(runtime.modelProvider !== ModelProviderName.OLLAMA && {
// TODO: make this not hardcoded
...((runtime.modelProvider !== ModelProviderName.OLLAMA || settings.USE_OPENAI_EMBEDDING) ? {
Authorization: `Bearer ${runtime.token}`,
}),
} : {}),
},
body: JSON.stringify({
input,
Expand All @@ -92,7 +95,7 @@ export async function embed(runtime: IAgentRuntime, input: string) {
try {
const response = await fetch(
// TODO: make this not hardcoded
`${runtime.character.modelEndpointOverride || modelProvider.endpoint}${runtime.character.modelProvider === ModelProviderName.OLLAMA ? "/v1" : ""}/embeddings`,
`${runtime.character.modelEndpointOverride || modelProvider.endpoint}${(runtime.character.modelProvider === ModelProviderName.OLLAMA && !settings.USE_OPENAI_EMBEDDING) ? "/v1" : ""}/embeddings`,
requestOptions
);

Expand Down

0 comments on commit 432362b

Please sign in to comment.