Optional
auth?: OpenAiAuthConfigAuthentication configuration for OpenAI. If not supplied, it will be loaded from the environment.
Optional
client?: HttpClient<THttpClientOptions>HTTP client to use for requests. If not supplied, the built-in fetch-based implementation will be used.
The model ID as defined by OpenAI.
The OpenAI Model Provider with the OpenAiChatApi
If no auth is passed and OPENAI_API_KEY is not found in process.env
import { createOpenAiChatModelProvider } from "generative-ts";
const gpt = createOpenAiChatModelProvider({
modelId: "gpt-4-turbo", // OpenAI defined model ID
// you can explicitly pass auth here, otherwise by default it is read from process.env
});
const response = await gpt.sendRequest({
$prompt: "Brief History of NY Mets:",
max_tokens: 100,
// all other OpenAI ChatCompletion options available here
});
console.log(response.choices[0]?.message.content);
Creates a OpenAI ModelProvider with the OpenAiChatApi
Provider Setup and Notes
Create an API account at OpenAI
Obtain a OpenAI API key and either pass it explicitly in
auth
or set it in the environment asOPENAI_API_KEY
Model Parameters
Model IDs