import { ChatGoogle, ChatGoogleInput } from "@langchain/google-gauth"; //#region src/chat_models.d.ts /** * Input to a Google Vertex AI chat model class. */ interface ChatVertexAIInput extends ChatGoogleInput {} /** * Integration with Google Vertex AI chat models. * * Setup: * Install `@langchain/google-vertexai` and set your stringified * Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`. * * ```bash * npm install @langchain/google-vertexai * export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials" * ``` * * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_google_vertexai.index.ChatVertexAI.html#constructor.new_ChatVertexAI) * * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html) * * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc. * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below: * * ```typescript * // When calling `.withConfig`, call options should be passed via the first argument * const llmWithArgsBound = llm.withConfig({ * stop: ["\n"], * tools: [...], * }); * * // When calling `.bindTools`, call options should be passed via the second argument * const llmWithTools = llm.bindTools( * [...], * { * tool_choice: "auto", * } * ); * ``` * * ## Examples * *
* Instantiate * * ```typescript * import { ChatVertexAI } from '@langchain/google-vertexai'; * * const llm = new ChatVertexAI({ * model: "gemini-1.5-pro", * temperature: 0, * // other params... * }); * ``` *
* *
* *
* Invoking * * ```typescript * const input = `Translate "I love programming" into French.`; * * // Models also accept a list of chat messages or a formatted prompt * const result = await llm.invoke(input); * console.log(result); * ``` * * ```txt * AIMessageChunk { * "content": "\"J'adore programmer\" \n\nHere's why this is the best translation:\n\n* **J'adore** means \"I love\" and conveys a strong passion.\n* **Programmer** is the French verb for \"to program.\"\n\nThis translation is natural and idiomatic in French. \n", * "additional_kwargs": {}, * "response_metadata": {}, * "tool_calls": [], * "tool_call_chunks": [], * "invalid_tool_calls": [], * "usage_metadata": { * "input_tokens": 9, * "output_tokens": 63, * "total_tokens": 72 * } * } * ``` *
* *
* *
* Streaming Chunks * * ```typescript * for await (const chunk of await llm.stream(input)) { * console.log(chunk); * } * ``` * * ```txt * AIMessageChunk { * "content": "\"", * "additional_kwargs": {}, * "response_metadata": {}, * "tool_calls": [], * "tool_call_chunks": [], * "invalid_tool_calls": [] * } * AIMessageChunk { * "content": "J'adore programmer\" \n", * "additional_kwargs": {}, * "response_metadata": {}, * "tool_calls": [], * "tool_call_chunks": [], * "invalid_tool_calls": [] * } * AIMessageChunk { * "content": "", * "additional_kwargs": {}, * "response_metadata": {}, * "tool_calls": [], * "tool_call_chunks": [], * "invalid_tool_calls": [] * } * AIMessageChunk { * "content": "", * "additional_kwargs": {}, * "response_metadata": { * "finishReason": "stop" * }, * "tool_calls": [], * "tool_call_chunks": [], * "invalid_tool_calls": [], * "usage_metadata": { * "input_tokens": 9, * "output_tokens": 8, * "total_tokens": 17 * } * } * ``` *
* *
* *
* Aggregate Streamed Chunks * * ```typescript * import { AIMessageChunk } from '@langchain/core/messages'; * import { concat } from '@langchain/core/utils/stream'; * * const stream = await llm.stream(input); * let full: AIMessageChunk | undefined; * for await (const chunk of stream) { * full = !full ? chunk : concat(full, chunk); * } * console.log(full); * ``` * * ```txt * AIMessageChunk { * "content": "\"J'adore programmer\" \n", * "additional_kwargs": {}, * "response_metadata": { * "finishReason": "stop" * }, * "tool_calls": [], * "tool_call_chunks": [], * "invalid_tool_calls": [], * "usage_metadata": { * "input_tokens": 9, * "output_tokens": 8, * "total_tokens": 17 * } * } * ``` *
* *
* *
* Bind tools * * ```typescript * import { z } from 'zod'; * * const GetWeather = { * name: "GetWeather", * description: "Get the current weather in a given location", * schema: z.object({ * location: z.string().describe("The city and state, e.g. San Francisco, CA") * }), * } * * const GetPopulation = { * name: "GetPopulation", * description: "Get the current population in a given location", * schema: z.object({ * location: z.string().describe("The city and state, e.g. San Francisco, CA") * }), * } * * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]); * const aiMsg = await llmWithTools.invoke( * "Which city is hotter today and which is bigger: LA or NY?" * ); * console.log(aiMsg.tool_calls); * ``` * * ```txt * [ * { * name: 'GetPopulation', * args: { location: 'New York City, NY' }, * id: '33c1c1f47e2f492799c77d2800a43912', * type: 'tool_call' * } * ] * ``` *
* *
* *
* Structured Output * * ```typescript * import { z } from 'zod'; * * const Joke = z.object({ * setup: z.string().describe("The setup of the joke"), * punchline: z.string().describe("The punchline to the joke"), * rating: z.number().optional().describe("How funny the joke is, from 1 to 10") * }).describe('Joke to tell user.'); * * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" }); * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats"); * console.log(jokeResult); * ``` * * ```txt * { * setup: 'What do you call a cat that loves to bowl?', * punchline: 'An alley cat!' * } * ``` *
* *
* *
* Usage Metadata * * ```typescript * const aiMsgForMetadata = await llm.invoke(input); * console.log(aiMsgForMetadata.usage_metadata); * ``` * * ```txt * { input_tokens: 9, output_tokens: 8, total_tokens: 17 } * ``` *
* *
* *
* Stream Usage Metadata * * ```typescript * const streamForMetadata = await llm.stream( * input, * { * streamUsage: true * } * ); * let fullForMetadata: AIMessageChunk | undefined; * for await (const chunk of streamForMetadata) { * fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk); * } * console.log(fullForMetadata?.usage_metadata); * ``` * * ```txt * { input_tokens: 9, output_tokens: 8, total_tokens: 17 } * ``` *
* *
*/ declare class ChatVertexAI extends ChatGoogle { lc_namespace: string[]; static lc_name(): string; constructor(model: string, params?: Omit); constructor(fields?: ChatVertexAIInput); } //#endregion export { ChatVertexAI, ChatVertexAIInput }; //# sourceMappingURL=chat_models.d.ts.map