Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add request config #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ export interface TypeChatLanguageModel {
* If none of these key variables are defined, an exception is thrown.
* @returns An instance of `TypeChatLanguageModel`.
*/
export function createLanguageModel(env: Record<string, string | undefined>): TypeChatLanguageModel {
export function createLanguageModel(env: Record<string, string | undefined>, requestConfig?: Record<string | symbol, any>): TypeChatLanguageModel {
if (env.OPENAI_API_KEY) {
const apiKey = env.OPENAI_API_KEY ?? missingEnvironmentVariable("OPENAI_API_KEY");
const model = env.OPENAI_MODEL ?? missingEnvironmentVariable("OPENAI_MODEL");
const endPoint = env.OPENAI_ENDPOINT ?? "https://api.openai.com/v1/chat/completions";
return createOpenAILanguageModel(apiKey, model, endPoint);
return createOpenAILanguageModel(apiKey, model, endPoint, requestConfig);
}
if (env.AZURE_OPENAI_API_KEY) {
const apiKey = env.AZURE_OPENAI_API_KEY ?? missingEnvironmentVariable("AZURE_OPENAI_API_KEY");
const endPoint = env.AZURE_OPENAI_ENDPOINT ?? missingEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
return createAzureOpenAILanguageModel(apiKey, endPoint);
return createAzureOpenAILanguageModel(apiKey, endPoint, requestConfig);
}
missingEnvironmentVariable("OPENAI_API_KEY or AZURE_OPENAI_API_KEY");
}
Expand All @@ -60,8 +60,8 @@ export function createLanguageModel(env: Record<string, string | undefined>): Ty
* @param endPoint The URL of the OpenAI REST API endpoint. Defaults to "https://api.openai.com/v1/chat/completions".
* @returns An instance of `TypeChatLanguageModel`.
*/
export function createOpenAILanguageModel(apiKey: string, model: string, endPoint = "https://api.openai.com/v1/chat/completions",): TypeChatLanguageModel {
return createAxiosLanguageModel(endPoint, { headers: { Authorization: `Bearer ${apiKey}` } }, { model });
export function createOpenAILanguageModel(apiKey: string, model: string, endPoint = "https://api.openai.com/v1/chat/completions", requestConfig: Record<string | symbol, any> = {}): TypeChatLanguageModel {
return createAxiosLanguageModel(endPoint, { ...requestConfig, headers: { Authorization: `Bearer ${apiKey}` } }, { model });
}

/**
Expand All @@ -72,8 +72,8 @@ export function createOpenAILanguageModel(apiKey: string, model: string, endPoin
* @param apiKey The Azure OpenAI API key.
* @returns An instance of `TypeChatLanguageModel`.
*/
export function createAzureOpenAILanguageModel(apiKey: string, endPoint: string,): TypeChatLanguageModel {
return createAxiosLanguageModel(endPoint, { headers: { "api-key": apiKey } }, {});
export function createAzureOpenAILanguageModel(apiKey: string, endPoint: string, requestConfig: Record<string | symbol, any> = {}): TypeChatLanguageModel {
return createAxiosLanguageModel(endPoint, { ...requestConfig, headers: { "api-key": apiKey } }, {});
}

/**
Expand Down