Merge pull request #3915 from continuedev/dallin/o1-timeout
LLM Test timeout
This commit is contained in:
commit
ad35f02065
1 changed files with 117 additions and 88 deletions
|
|
@ -26,7 +26,13 @@ function testLLM(
|
|||
skip,
|
||||
testFim,
|
||||
testToolCall,
|
||||
}: { skip?: boolean; testFim?: boolean; testToolCall?: boolean },
|
||||
timeout,
|
||||
}: {
|
||||
skip?: boolean;
|
||||
testFim?: boolean;
|
||||
testToolCall?: boolean;
|
||||
timeout?: number;
|
||||
},
|
||||
) {
|
||||
if (skip) {
|
||||
return;
|
||||
|
|
@ -37,45 +43,29 @@ function testLLM(
|
|||
});
|
||||
|
||||
describe(llm.providerName + "/" + llm.model, () => {
|
||||
test("Stream Chat works", async () => {
|
||||
let total = "";
|
||||
for await (const chunk of llm.streamChat(
|
||||
[{ role: "user", content: "Hi" }],
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
total += chunk.content;
|
||||
}
|
||||
|
||||
expect(total.length).toBeGreaterThan(0);
|
||||
return;
|
||||
});
|
||||
|
||||
test("Stream Complete works", async () => {
|
||||
let total = "";
|
||||
for await (const chunk of llm.streamComplete(
|
||||
"Hi",
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
total += chunk;
|
||||
}
|
||||
|
||||
expect(total.length).toBeGreaterThan(0);
|
||||
return;
|
||||
});
|
||||
|
||||
test("Complete works", async () => {
|
||||
const completion = await llm.complete("Hi", new AbortController().signal);
|
||||
|
||||
expect(completion.length).toBeGreaterThan(0);
|
||||
return;
|
||||
});
|
||||
|
||||
if (testFim) {
|
||||
test("FIM works", async () => {
|
||||
test(
|
||||
"Stream Chat works",
|
||||
async () => {
|
||||
let total = "";
|
||||
for await (const chunk of llm.streamFim(
|
||||
for await (const chunk of llm.streamChat(
|
||||
[{ role: "user", content: "Hi" }],
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
total += chunk.content;
|
||||
}
|
||||
|
||||
expect(total.length).toBeGreaterThan(0);
|
||||
return;
|
||||
},
|
||||
timeout,
|
||||
);
|
||||
|
||||
test(
|
||||
"Stream Complete works",
|
||||
async () => {
|
||||
let total = "";
|
||||
for await (const chunk of llm.streamComplete(
|
||||
"Hi",
|
||||
"name is ChatGPT.",
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
total += chunk;
|
||||
|
|
@ -83,67 +73,106 @@ function testLLM(
|
|||
|
||||
expect(total.length).toBeGreaterThan(0);
|
||||
return;
|
||||
});
|
||||
},
|
||||
timeout,
|
||||
);
|
||||
|
||||
test(
|
||||
"Complete works",
|
||||
async () => {
|
||||
const completion = await llm.complete(
|
||||
"Hi",
|
||||
new AbortController().signal,
|
||||
);
|
||||
|
||||
expect(completion.length).toBeGreaterThan(0);
|
||||
return;
|
||||
},
|
||||
timeout,
|
||||
);
|
||||
|
||||
if (testFim) {
|
||||
test(
|
||||
"FIM works",
|
||||
async () => {
|
||||
let total = "";
|
||||
for await (const chunk of llm.streamFim(
|
||||
"Hi",
|
||||
"name is ChatGPT.",
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
total += chunk;
|
||||
}
|
||||
|
||||
expect(total.length).toBeGreaterThan(0);
|
||||
return;
|
||||
},
|
||||
timeout,
|
||||
);
|
||||
}
|
||||
|
||||
if (testToolCall) {
|
||||
test("Tool Call works", async () => {
|
||||
let args = "";
|
||||
let isFirstChunk = true;
|
||||
for await (const chunk of llm.streamChat(
|
||||
[{ role: "user", content: "Hi, my name is Nate." }],
|
||||
new AbortController().signal,
|
||||
{
|
||||
tools: [
|
||||
{
|
||||
displayTitle: "Say Hello",
|
||||
function: {
|
||||
name: "say_hello",
|
||||
description: "Say Hello",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: {
|
||||
type: "string",
|
||||
description: "The name of the person to greet",
|
||||
test(
|
||||
"Tool Call works",
|
||||
async () => {
|
||||
let args = "";
|
||||
let isFirstChunk = true;
|
||||
for await (const chunk of llm.streamChat(
|
||||
[{ role: "user", content: "Hi, my name is Nate." }],
|
||||
new AbortController().signal,
|
||||
{
|
||||
tools: [
|
||||
{
|
||||
displayTitle: "Say Hello",
|
||||
function: {
|
||||
name: "say_hello",
|
||||
description: "Say Hello",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: {
|
||||
type: "string",
|
||||
description: "The name of the person to greet",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
type: "function",
|
||||
wouldLikeTo: "Say hello",
|
||||
readonly: true,
|
||||
},
|
||||
],
|
||||
toolChoice: {
|
||||
type: "function",
|
||||
wouldLikeTo: "Say hello",
|
||||
readonly: true,
|
||||
},
|
||||
],
|
||||
toolChoice: {
|
||||
type: "function",
|
||||
function: {
|
||||
name: "say_hello",
|
||||
function: {
|
||||
name: "say_hello",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)) {
|
||||
const typedChunk = chunk as AssistantChatMessage;
|
||||
if (!typedChunk.toolCalls) {
|
||||
continue;
|
||||
)) {
|
||||
const typedChunk = chunk as AssistantChatMessage;
|
||||
if (!typedChunk.toolCalls) {
|
||||
continue;
|
||||
}
|
||||
const toolCall = typedChunk.toolCalls[0];
|
||||
args += toolCall.function?.arguments ?? "";
|
||||
|
||||
expect(chunk.role).toBe("assistant");
|
||||
expect(chunk.content).toBe("");
|
||||
expect(typedChunk.toolCalls).toHaveLength(1);
|
||||
|
||||
if (isFirstChunk) {
|
||||
isFirstChunk = false;
|
||||
expect(toolCall.id).toBeDefined();
|
||||
expect(toolCall.function!.name).toBe("say_hello");
|
||||
}
|
||||
}
|
||||
const toolCall = typedChunk.toolCalls[0];
|
||||
args += toolCall.function?.arguments ?? "";
|
||||
|
||||
expect(chunk.role).toBe("assistant");
|
||||
expect(chunk.content).toBe("");
|
||||
expect(typedChunk.toolCalls).toHaveLength(1);
|
||||
|
||||
if (isFirstChunk) {
|
||||
isFirstChunk = false;
|
||||
expect(toolCall.id).toBeDefined();
|
||||
expect(toolCall.function!.name).toBe("say_hello");
|
||||
}
|
||||
}
|
||||
|
||||
const parsedArgs = JSON.parse(args);
|
||||
expect(parsedArgs.name).toBe("Nate");
|
||||
});
|
||||
const parsedArgs = JSON.parse(args);
|
||||
expect(parsedArgs.name).toBe("Nate");
|
||||
},
|
||||
timeout,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -165,7 +194,7 @@ describe("LLM", () => {
|
|||
});
|
||||
testLLM(
|
||||
new OpenAI({ apiKey: process.env.OPENAI_API_KEY, model: "o1-preview" }),
|
||||
{ skip: false },
|
||||
{ skip: false, timeout: 20000 },
|
||||
);
|
||||
testLLM(new OpenAI({ apiKey: process.env.OPENAI_API_KEY, model: "o1" }), {
|
||||
skip: false,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue