Adaptateurs Personnalisés
Créez vos propres adaptateurs LLM et base de données vectorielle pour Orka AI.
Adaptateur LLM Personnalisé
custom-adapter-llm.ts
import type { LLMAdapter, LLMGenerateOptions, LLMResult } from 'orkajs';//ouimport { LLMAdapter, LLMGenerateOptions, LLMResult } from 'orkajs/types'; //--class MyLLMAdapter implements LLMAdapter { readonly name = 'my-llm'; async generate(prompt: string, options?: LLMGenerateOptions): Promise<LLMResult> { const response = await fetch('https://my-llm-api.com/generate', { method: 'POST', body: JSON.stringify({ prompt, temperature: options?.temperature ?? 0.7, max_tokens: options?.maxTokens ?? 1024, }), }); const data = await response.json(); return { content: data.text, usage: { promptTokens: data.usage.input_tokens, completionTokens: data.usage.output_tokens, totalTokens: data.usage.total_tokens, }, model: 'my-model-v1', finishReason: 'stop', }; } async embed(texts: string | string[]): Promise<number[][]> { const input = Array.isArray(texts) ? texts: [texts]; const response = await fetch('https://my-llm-api.com/embed', { method: 'POST', body: JSON.stringify({ texts: input }), }); const data = await response.json(); return data.embeddings; }}Adaptateur VectorDB Personnalisé
custom-adapter-vectordb.ts
import type { VectorDBAdapter, VectorRecord, VectorSearchResult } from 'orkajs';//ouimport { VectorDBAdapter, VectorRecord, VectorSearchResult } from 'orkajs/types'; //---class MyVectorAdapter implements VectorDBAdapter { readonly name = 'my-vectordb'; private collections: Map<string, VectorRecord[]> = new Map(); async createCollection(name: string): Promise<void> { this.collections.set(name, []); } async deleteCollection(name: string): Promise<void> { this.collections.delete(name); } async upsert(collection: string, vectors: VectorRecord[]): Promise<void> { const existing = this.collections.get(collection) ?? []; for (const vector of vectors) { const idx = existing.findIndex(v => v.id === vector.id); if (idx >= 0) existing[idx] = vector; else existing.push(vector); } this.collections.set(collection, existing); } async search(collection: string, vector: number[]): Promise<VectorSearchResult[]> { // Implement your similarity search logic return []; } async delete(collection: string, ids: string[]): Promise<void> { const existing = this.collections.get(collection) ?? []; this.collections.set(collection, existing.filter(v => !ids.includes(v.id))); }}💡 Astuce
Les adaptateurs personnalisés sont des citoyens de première classe dans Orka AI. Ils fonctionnent avec toutes les fonctionnalités — RAG, workflows, agents, évaluation — exactement comme les adaptateurs intégrés.