Skip to content

Commit

Permalink
anthropic[patch]: Pass custom headers through to request (#6275)
Browse files Browse the repository at this point in the history
* anthropic[patch]: Pass custom headers through to request

* chore: lint files
  • Loading branch information
bracesproul authored Jul 30, 2024
1 parent 1218bf8 commit f4b4e0c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions libs/langchain-anthropic/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface ChatAnthropicCallOptions
* @default "auto"
*/
tool_choice?: AnthropicToolChoice;
/**
* Custom headers to pass to the Anthropic API
* when making a request.
*/
headers?: Record<string, string>;
}

function _toolsInParams(params: AnthropicMessageCreateParams): boolean {
Expand Down Expand Up @@ -422,11 +427,16 @@ export class ChatAnthropicMessages<
stream: false,
});

const stream = await this.createStreamWithRetry({
...params,
...formattedMessages,
stream: true,
});
const stream = await this.createStreamWithRetry(
{
...params,
...formattedMessages,
stream: true,
},
{
headers: options.headers,
}
);

for await (const data of stream) {
if (options.signal?.aborted) {
Expand Down Expand Up @@ -543,6 +553,7 @@ export class ChatAnthropicMessages<
} else {
return this._generateNonStreaming(messages, params, {
signal: options.signal,
headers: options.headers,
});
}
}
Expand Down

0 comments on commit f4b4e0c

Please sign in to comment.