Skip to content
Open
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
5 changes: 3 additions & 2 deletions convex/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,15 @@ export const semanticSearch = internalAction({
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) throw new Error("OPENAI_API_KEY not set");

const response = await fetch("https://api.openai.com/v1/embeddings", {
const baseUrl = process.env.OPENAI_BASE_URL || "https://api.openai.com/v1";
const response = await fetch(`${baseUrl}/embeddings`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "text-embedding-3-small",
model: process.env.OPENAI_EMBEDDING_MODEL || "text-embedding-3-small",
input: query.slice(0, 8000),
}),
});
Expand Down
7 changes: 4 additions & 3 deletions convex/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ function hashText(text: string): string {
return hash.toString(16);
}

// Generate embedding via OpenAI
// Generate embedding via OpenAI-compatible API
async function embed(text: string): Promise<number[]> {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) throw new Error("OPENAI_API_KEY not set");

const response = await fetch("https://api.openai.com/v1/embeddings", {
const baseUrl = process.env.OPENAI_BASE_URL || "https://api.openai.com/v1";
const response = await fetch(`${baseUrl}/embeddings`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "text-embedding-3-small",
model: process.env.OPENAI_EMBEDDING_MODEL || "text-embedding-3-small",
input: text.slice(0, 8000),
}),
});
Expand Down
7 changes: 4 additions & 3 deletions convex/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,19 +571,20 @@ export const loadSessionsFromEmbeddings = internalQuery({
},
});

// Helper: generate embedding via OpenAI
// Helper: generate embedding via OpenAI-compatible API
async function generateEmbedding(text: string): Promise<number[]> {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) throw new Error("OPENAI_API_KEY not set");

const response = await fetch("https://api.openai.com/v1/embeddings", {
const baseUrl = process.env.OPENAI_BASE_URL || "https://api.openai.com/v1";
const response = await fetch(`${baseUrl}/embeddings`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "text-embedding-3-small",
model: process.env.OPENAI_EMBEDDING_MODEL || "text-embedding-3-small",
input: text.slice(0, 8000),
}),
});
Expand Down