From 6015579f7f5b73eaae29b0530c4623a7d45dbdf8 Mon Sep 17 00:00:00 2001 From: bracesproul Date: Wed, 24 Jul 2024 17:03:35 -0700 Subject: [PATCH] chore: lint files --- libs/langchain-groq/src/chat_models.ts | 18 +++++---- .../src/tests/chat_models.int.test.ts | 38 ++++++++++++------- .../tests/chat_models.standard.int.test.ts | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/libs/langchain-groq/src/chat_models.ts b/libs/langchain-groq/src/chat_models.ts index 6c8844602b28..861c2aae6789 100644 --- a/libs/langchain-groq/src/chat_models.ts +++ b/libs/langchain-groq/src/chat_models.ts @@ -207,17 +207,17 @@ function groqResponseToChatMessage( } } -function _convertDeltaToolCallToToolCallChunk(toolCalls?: ChatCompletionsAPI.ChatCompletionChunk.Choice.Delta.ToolCall[]): ToolCallChunk[] | undefined { +function _convertDeltaToolCallToToolCallChunk( + toolCalls?: ChatCompletionsAPI.ChatCompletionChunk.Choice.Delta.ToolCall[] +): ToolCallChunk[] | undefined { if (!toolCalls?.length) return undefined; - return toolCalls.map((tc) => { - return { + return toolCalls.map((tc) => ({ id: tc.id, name: tc.function?.name, args: tc.function?.arguments, - type: "tool_call_chunk" - } - }) + type: "tool_call_chunk", + })); } function _convertDeltaToMessageChunk( @@ -359,7 +359,9 @@ export class ChatGroq extends BaseChatModel< async completionWithRetry( request: ChatCompletionCreateParams, options?: OpenAICoreRequestOptions - ): Promise | ChatCompletion> { + ): Promise< + AsyncIterable | ChatCompletion + > { return this.caller.call(async () => this.client.chat.completions.create(request, options) ); @@ -505,7 +507,7 @@ export class ChatGroq extends BaseChatModel< completion_tokens: completionTokens, prompt_tokens: promptTokens, total_tokens: totalTokens, - } = data.usage as CompletionsAPI.CompletionUsage + } = data.usage as CompletionsAPI.CompletionUsage; if (completionTokens) { tokenUsage.completionTokens = diff --git a/libs/langchain-groq/src/tests/chat_models.int.test.ts b/libs/langchain-groq/src/tests/chat_models.int.test.ts index b3c954b22faa..e28012be269f 100644 --- a/libs/langchain-groq/src/tests/chat_models.int.test.ts +++ b/libs/langchain-groq/src/tests/chat_models.int.test.ts @@ -1,9 +1,14 @@ import { test } from "@jest/globals"; -import { AIMessage, AIMessageChunk, HumanMessage, ToolMessage } from "@langchain/core/messages"; -import { ChatGroq } from "../chat_models.js"; +import { + AIMessage, + AIMessageChunk, + HumanMessage, + ToolMessage, +} from "@langchain/core/messages"; import { tool } from "@langchain/core/tools"; import { z } from "zod"; import { concat } from "@langchain/core/utils/stream"; +import { ChatGroq } from "../chat_models.js"; test("invoke", async () => { const chat = new ChatGroq({ @@ -205,19 +210,24 @@ test("Groq can stream tool calls", async () => { temperature: 0, }); - const weatherTool = tool((_) => { - return "The temperature is 24 degrees with hail."; - }, { - name: "get_current_weather", - schema: z.object({ - location: z.string().describe("The location to get the current weather for."), - }), - description: "Get the current weather in a given location.", - }) + const weatherTool = tool( + (_) => "The temperature is 24 degrees with hail.", + { + name: "get_current_weather", + schema: z.object({ + location: z + .string() + .describe("The location to get the current weather for."), + }), + description: "Get the current weather in a given location.", + } + ); const modelWithTools = model.bindTools([weatherTool]); - const stream = await modelWithTools.stream("What is the weather in San Francisco?"); + const stream = await modelWithTools.stream( + "What is the weather in San Francisco?" + ); let finalMessage: AIMessageChunk | undefined; for await (const chunk of stream) { @@ -231,5 +241,5 @@ test("Groq can stream tool calls", async () => { if (!finalMessage.tool_calls?.[0]) return; expect(finalMessage.tool_calls?.[0].name).toBe("get_current_weather"); - expect(finalMessage.tool_calls?.[0].args).toHaveProperty("location") -}) \ No newline at end of file + expect(finalMessage.tool_calls?.[0].args).toHaveProperty("location"); +}); diff --git a/libs/langchain-groq/src/tests/chat_models.standard.int.test.ts b/libs/langchain-groq/src/tests/chat_models.standard.int.test.ts index 8065a3c0103b..82c4e3c392f8 100644 --- a/libs/langchain-groq/src/tests/chat_models.standard.int.test.ts +++ b/libs/langchain-groq/src/tests/chat_models.standard.int.test.ts @@ -19,7 +19,7 @@ class ChatGroqStandardIntegrationTests extends ChatModelIntegrationTests< chatModelHasToolCalling: true, chatModelHasStructuredOutput: true, constructorArgs: { - model: "llama3-groq-70b-8192-tool-use-preview", + model: "llama-3.1-70b-versatile", }, }); }