Skip to content

Commit

Permalink
Set stream_usage to false by default for Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Jun 27, 2024
1 parent dfa4c6d commit e4fc975
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 5 additions & 3 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,6 @@ export class ChatOpenAI<
this.stopSequences = this?.stop;
this.user = fields?.user;

this.streaming = fields?.streaming ?? false;
this.streamUsage = fields?.streamUsage ?? this.streamUsage;

if (this.azureOpenAIApiKey || this.azureADTokenProvider) {
if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
throw new Error("Azure OpenAI API instance name not found");
Expand All @@ -497,8 +494,13 @@ export class ChatOpenAI<
throw new Error("Azure OpenAI API version not found");
}
this.apiKey = this.apiKey ?? "";
// Streaming usage is not supported by Azure deployments, so default to false
this.streamUsage = false;
}

this.streaming = fields?.streaming ?? false;
this.streamUsage = fields?.streamUsage ?? this.streamUsage;

this.clientConfig = {
apiKey: this.apiKey,
organization: this.organization,
Expand Down
6 changes: 1 addition & 5 deletions libs/langchain-openai/src/tests/chat_models.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,7 @@ test("Finish reason is 'stop'", async () => {

test("Streaming tokens can be found in usage_metadata field", async () => {
const model = new ChatOpenAI();
const response = await model.stream("Hello, how are you?", {
stream_options: {
include_usage: true,
},
});
const response = await model.stream("Hello, how are you?");
let finalResult: AIMessageChunk | undefined;
for await (const chunk of response) {
if (finalResult) {
Expand Down

0 comments on commit e4fc975

Please sign in to comment.