forensic-ai #4
@ -119,16 +119,22 @@ class EmbeddingsService {
|
||||
const apiKey = process.env.AI_EMBEDDINGS_API_KEY;
|
||||
const model = process.env.AI_EMBEDDINGS_MODEL;
|
||||
|
||||
if (!endpoint || !apiKey || !model) {
|
||||
if (!endpoint || !model) {
|
||||
throw new Error('Missing embeddings API configuration');
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
// API key is optional for Ollama but required for Mistral/OpenAI
|
||||
if (apiKey) {
|
||||
headers['Authorization'] = `Bearer ${apiKey}`;
|
||||
}
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${apiKey}`
|
||||
},
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
model,
|
||||
input: contents
|
||||
@ -141,7 +147,18 @@ class EmbeddingsService {
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.data.map((item: any) => item.embedding);
|
||||
|
||||
// Detect Ollama format
|
||||
if (Array.isArray(data.embeddings)) {
|
||||
return data.embeddings;
|
||||
}
|
||||
|
||||
// Detect OpenAI/Mistral format
|
||||
if (Array.isArray(data.data)) {
|
||||
return data.data.map((item: any) => item.embedding);
|
||||
}
|
||||
|
||||
throw new Error('Unknown embeddings API response format');
|
||||
}
|
||||
|
||||
private async generateEmbeddings(toolsData: any, version: string): Promise<void> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user