feat: Claude client + Voyage AI embed helper
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFDuBhMKvoWjrWT3ZnGmmr
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import Anthropic from '@anthropic-ai/sdk'
|
||||
|
||||
export const anthropic = new Anthropic({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY ?? '',
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
export async function embedText(text: string): Promise<number[]> {
|
||||
if (!process.env.VOYAGE_API_KEY) throw new Error('VOYAGE_API_KEY is not set')
|
||||
const res = await fetch('https://api.voyageai.com/v1/embeddings', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${process.env.VOYAGE_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({ input: [text], model: 'voyage-3-lite' }),
|
||||
})
|
||||
if (!res.ok) throw new Error(`Voyage embed failed: ${res.status}`)
|
||||
const json = await res.json() as { data: Array<{ embedding: number[] }> }
|
||||
return json.data[0].embedding
|
||||
}
|
||||
Reference in New Issue
Block a user