Skip to content

Commit

Permalink
chore: add test verifying fallbacks work
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Oct 16, 2023
1 parent 2207f46 commit e2d087a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions langchain/src/agents/tests/agent.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,58 @@ test("Pass runnable to agent executor", async () => {
expect(res.output).not.toEqual("Agent stopped due to max iterations.");
});

test("Add a fallback method", async () => {
// Model should always fail since the model name passed does not exist.
const modelBase = new ChatOpenAI({
modelName: "fake-model",
temperature: 10,
maxTokens: 10,
});

const modelLarge = new ChatOpenAI({
modelName: "gpt-3.5-turbo-16k",
temperature: 0.6,
maxTokens: 10,
});

const model = modelBase.withFallbacks({
fallbacks: [modelLarge],
});

const prompt = ZeroShotAgent.createPrompt([]);
const outputParser = ZeroShotAgent.getDefaultOutputParser();

const runnable = RunnableSequence.from([
{
input: (i: { input: string }) => i.input,
agent_scratchpad: (i: { input: string }) => i.input,
},
prompt,
model,
outputParser,
]);

const agent = new ZeroShotAgent({
runnable,
});

const executor = AgentExecutor.fromAgentAndTools({
agent,
tools: [],
});
const res = await executor.invoke({
input: "Is the sky blue? Response with a concise answer",
});
console.log(
{
res,
},
"Pass runnable to agent executor"
);
expect(res.output).not.toEqual("");
expect(res.output).not.toEqual("Agent stopped due to max iterations.");
});

test("Run agent locally", async () => {
const model = new OpenAI({ temperature: 0, modelName: "text-babbage-001" });
const tools = [
Expand Down

0 comments on commit e2d087a

Please sign in to comment.