embeddings fix for ollama
This commit is contained in:
		
							parent
							
								
									ec1969b2e2
								
							
						
					
					
						commit
						3a5e8e88b2
					
				@ -119,16 +119,22 @@ class EmbeddingsService {
 | 
				
			|||||||
    const apiKey = process.env.AI_EMBEDDINGS_API_KEY;
 | 
					    const apiKey = process.env.AI_EMBEDDINGS_API_KEY;
 | 
				
			||||||
    const model = process.env.AI_EMBEDDINGS_MODEL;
 | 
					    const model = process.env.AI_EMBEDDINGS_MODEL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!endpoint || !apiKey || !model) {
 | 
					    if (!endpoint || !model) {
 | 
				
			||||||
      throw new Error('Missing embeddings API configuration');
 | 
					      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, {
 | 
					    const response = await fetch(endpoint, {
 | 
				
			||||||
      method: 'POST',
 | 
					      method: 'POST',
 | 
				
			||||||
      headers: {
 | 
					      headers,
 | 
				
			||||||
        'Content-Type': 'application/json',
 | 
					 | 
				
			||||||
        'Authorization': `Bearer ${apiKey}`
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      body: JSON.stringify({
 | 
					      body: JSON.stringify({
 | 
				
			||||||
        model,
 | 
					        model,
 | 
				
			||||||
        input: contents
 | 
					        input: contents
 | 
				
			||||||
@ -141,7 +147,18 @@ class EmbeddingsService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const data = await response.json();
 | 
					    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> {
 | 
					  private async generateEmbeddings(toolsData: any, version: string): Promise<void> {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user