Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use openai embeddings setting #252

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading