Skip to content

Commit

Permalink
feat(gpt-runner-core): add openai accessToken support
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jun 25, 2023
1 parent f69d078 commit 98793b1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/gpt-runner-core/src/langchain/llm.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export async function llmChain(params: LlmChainParams) {

if (model.type === ChatModelType.Openai) {
const { secrets, modelName, temperature, maxTokens, topP, frequencyPenalty, presencePenalty } = model
const hasAccessToken = secrets?.accessToken
const axiosBaseOptions: Record<string, any> = {
headers: {},
}

if (hasAccessToken) {
// if user provided an access token, use it even though api key is also provided
// see: https://github.com/openai/openai-node/blob/dc821be3018c832650e21285bade265099f99efb/common.ts#L70
axiosBaseOptions.headers.Authorization = `Bearer ${secrets?.accessToken}`
}

llm = new ChatOpenAI({
streaming: true,
maxRetries: 1,
Expand All @@ -40,6 +51,7 @@ export async function llmChain(params: LlmChainParams) {
presencePenalty,
configuration: {
...secrets,
baseOptions: axiosBaseOptions,
},
callbackManager: CallbackManager.fromHandlers({
handleLLMNewToken: async (token: string) => {
Expand Down

0 comments on commit 98793b1

Please sign in to comment.