| 101 | } |
| 102 | |
| 103 | function buildOpenAIProvider(modelName: string, apiKey: string): ResolvedProvider['buildRequest'] { |
| 104 | return (inputs) => ({ |
| 105 | apiUrl: 'https://api.openai.com/v1/embeddings', |
| 106 | headers: { |
| 107 | Authorization: `Bearer ${apiKey}`, |
| 108 | 'Content-Type': 'application/json', |
| 109 | }, |
| 110 | body: { |
| 111 | input: inputs, |
| 112 | model: modelName, |
| 113 | encoding_format: 'float', |
| 114 | dimensions: EMBEDDING_DIMENSIONS, |
| 115 | }, |
| 116 | parse: (json) => { |
| 117 | const data = json as { data: Array<{ embedding: number[] }> } |
| 118 | return data.data.map((item) => item.embedding) |
| 119 | }, |
| 120 | }) |
| 121 | } |
| 122 | |
| 123 | function buildAzureOpenAIProvider( |
| 124 | deployment: string, |