openai fetch
v3.3.2
عميل Openai الحد الأدنى والرأي مدعوم من جلب.
لسوء الحظ ، تجلب تصحيحات حزمة Openai الرسمية بطرق إشكالية وهي متضخمة تمامًا.
openai-fetch :openai-fetch هو ~ 14 كيلو بايت و openai هو ~ 152 كيلو بايتopenai الرسمية إذا:npm install openai-fetch تتطلب هذه الحزمة node >= 18 أو بيئة بدعم fetch .
هذه الحزمة تصدير ESM. إذا كان مشروعك يستخدم CommonJs ، ففكر في التبديل إلى ESM أو استخدام وظيفة import() .
import { OpenAIClient } from 'openai-fetch' ;
const client = new OpenAIClient ( { apiKey : '<your api key>' } ) ; apiKey اختياري وسيتم قراءتها من process.env.OPENAI_API_KEY إذا كانت موجودة.
يتبع API Openai عن كثب ، لذلك يمكن استخدام وثائقها المرجعية عمومًا. يتم كتابة كل شيء بقوة ، لذلك ستعرف ما إذا كان أي شيء مختلفًا بمجرد توحيد TypeScript الكود الخاص بك.
// Generate a single chat completion
client . createChatCompletion ( params : ChatParams ) : Promise < ChatResponse > ;
// Stream a single completion via a ReadableStream
client . streamChatCompletion ( params : ChatStreamParams ) : Promise < ChatStreamResponse > ;
// Generate one or more completions
client . createCompletions ( params : CompletionParams ) : Promise < CompletionResponse > ;
// Stream a single completion via a ReadableStream
client . streamCompletion ( params : CompletionStreamParams ) : Promise < CompletionStreamResponse > ;
// Generate one or more embeddings
client . createEmbeddings ( params : EmbeddingParams ) : Promise < EmbeddingResponse >
// Checks for potentially harmful content
client . createModeration ( params : ModerationParams ) : Promise < ModerationResponse >
// Text-to-Speech
client . createSpeech ( params : SpeechParams ) : Promise < SpeechResponse >تعاريف النوع هي Avaible من خلال tsserver ، ويمكن العثور عليها هنا: التعريفات النوع.
MIT © Dexa