Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Jan 24, 2025
1 parent c659b7e commit d15a45d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions libs/langchain-openai/src/tests/azure/chat_models.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { AzureChatOpenAI } from "../../azure/chat_models.js";

beforeEach(() => {
delete process.env.OPENAI_API_KEY;

Check failure on line 4 in libs/langchain-openai/src/tests/azure/chat_models.test.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected use of process.env
});

test("Test Azure OpenAI serialization from azure endpoint", async () => {
const chat = new AzureChatOpenAI({
azureOpenAIEndpoint: "https://foobar.openai.azure.com/",
Expand All @@ -8,7 +12,7 @@ test("Test Azure OpenAI serialization from azure endpoint", async () => {
azureOpenAIApiKey: "foo",
});
expect(JSON.stringify(chat)).toEqual(
`{"lc":1,"type":"constructor","id":["langchain","chat_models","azure_openai","AzureChatOpenAI"],"kwargs":{"azure_endpoint":"https://foobar.openai.azure.com/","openai_api_key":{"lc":1,"type":"secret","id":["OPENAI_API_KEY"]},"deployment_name":"gpt-4o"}}`
`{"lc":1,"type":"constructor","id":["langchain","chat_models","azure_openai","AzureChatOpenAI"],"kwargs":{"azure_endpoint":"https://foobar.openai.azure.com/","deployment_name":"gpt-4o","openai_api_version":"2024-08-01-preview","azure_open_ai_api_key":{"lc":1,"type":"secret","id":["AZURE_OPENAI_API_KEY"]}}}`
);
});

Expand All @@ -20,7 +24,7 @@ test("Test Azure OpenAI serialization from base path", async () => {
azureOpenAIApiKey: "foo",
});
expect(JSON.stringify(chat)).toEqual(
`{"lc":1,"type":"constructor","id":["langchain","chat_models","azure_openai","AzureChatOpenAI"],"kwargs":{"openai_api_key":{"lc":1,"type":"secret","id":["OPENAI_API_KEY"]},"azure_endpoint":"https://foobar.openai.azure.com","deployment_name":"gpt-4o"}}`
`{"lc":1,"type":"constructor","id":["langchain","chat_models","azure_openai","AzureChatOpenAI"],"kwargs":{"openai_api_version":"2024-08-01-preview","azure_open_ai_api_key":{"lc":1,"type":"secret","id":["AZURE_OPENAI_API_KEY"]},"azure_endpoint":"https://foobar.openai.azure.com","deployment_name":"gpt-4o-mini"}}`
);
});

Expand All @@ -32,6 +36,6 @@ test("Test Azure OpenAI serialization from instance name", async () => {
azureOpenAIApiKey: "foo",
});
expect(JSON.stringify(chat)).toEqual(
`{"lc":1,"type":"constructor","id":["langchain","chat_models","azure_openai","AzureChatOpenAI"],"kwargs":{"openai_api_key":{"lc":1,"type":"secret","id":["OPENAI_API_KEY"]},"azure_endpoint":"https://foobar.openai.azure.com/","deployment_name":"gpt-4o"}}`
`{"lc":1,"type":"constructor","id":["langchain","chat_models","azure_openai","AzureChatOpenAI"],"kwargs":{"azure_open_ai_api_instance_name":"foobar","deployment_name":"gpt-4o","openai_api_version":"2024-08-01-preview","azure_open_ai_api_key":{"lc":1,"type":"secret","id":["AZURE_OPENAI_API_KEY"]},"azure_endpoint":"https://foobar.openai.azure.com/"}}`
);
});
4 changes: 3 additions & 1 deletion libs/langchain-openai/src/tests/chat_models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ describe("strict tool calling", () => {
}),
{
strict: true,
method: "functionCalling",
}
);

Expand Down Expand Up @@ -238,7 +239,8 @@ describe("strict tool calling", () => {
const modelWithTools = model.withStructuredOutput(
z.object({
location: z.string().describe("The location to get the weather for"),
})
}),
{ method: "functionCalling" }
);

// This will fail since we're not returning a valid response in our mocked fetch function.
Expand Down

0 comments on commit d15a45d

Please sign in to comment.