@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
31 lines (25 loc) • 1.02 kB
text/typescript
import axios from 'axios';
import { AzureConfig } from './config';
import { AzureEmbeddingRequestBody, AzureEmbeddingResponse } from './types';
export async function embed(config: AzureConfig, text: string): Promise<number[]> {
const url = config.getApiUrl('embeddings');
const requestBody: AzureEmbeddingRequestBody = { input: text };
const response = await axios.post<AzureEmbeddingResponse>(url, requestBody, {
headers: {
'Content-Type': 'application/json',
'api-key': config.apiKey,
},
});
return response.data.data[0].embedding;
}
export async function embedBatch(config: AzureConfig, texts: string[]): Promise<number[][]> {
const url = config.getApiUrl('embeddings');
const requestBody: AzureEmbeddingRequestBody = { input: texts };
const response = await axios.post<AzureEmbeddingResponse>(url, requestBody, {
headers: {
'Content-Type': 'application/json',
'api-key': config.apiKey,
},
});
return response.data.data.map(item => item.embedding);
}