openai fetch
v3.3.2
ไคลเอนต์ OpenAI ที่น้อยที่สุดและมีความคิดเห็นขับเคลื่อนโดย Fetch
น่าเสียดายที่แพตช์ OpenAi อย่างเป็นทางการดึงมาด้วยวิธีที่มีปัญหาและค่อนข้างป่อง
openai-fetch :openai-fetch คือ ~ 14kb และ openai คือ ~ 152kbopenai อย่างเป็นทางการหาก: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 Parses รหัสของคุณหรือไม่
// 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 >คำจำกัดความประเภทนั้นสามารถใช้งานได้ผ่าน TSServer และสามารถพบได้ที่นี่: คำจำกัดความประเภท
mit © dexa