diff --git a/core/llm/llm.test.ts b/core/llm/llm.test.ts index 09777dae0..4831cf800 100644 --- a/core/llm/llm.test.ts +++ b/core/llm/llm.test.ts @@ -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, diff --git a/docs/docs/customize/model-providers/top-level/xAI.md b/docs/docs/customize/model-providers/top-level/xAI.md index fbdfa83ad..550cc0641 100644 --- a/docs/docs/customize/model-providers/top-level/xAI.md +++ b/docs/docs/customize/model-providers/top-level/xAI.md @@ -11,15 +11,15 @@ You can get an API key from the [xAI console](https://console.x.ai/) ## Chat model -We recommend configuring **grok-beta** as your chat model. +We recommend configuring **grok-2-latest** as your chat model. For information on other available models, visit [xAI Documentation](https://docs.x.ai/docs/models). ```json title="config.json" { "models": [ { - "title": "Grok Beta", + "title": "Grok 2", "provider": "xAI", - "model": "grok-beta", + "model": "grok-2-latest", "apiKey": "[API_KEY]" } ]