@blaxel/langgraph 0.2.49-dev.214 → 0.2.49-dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/types/tools.d.ts +6 -2
  3. package/dist/esm/.tsbuildinfo +1 -1
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.js +19 -0
  6. package/dist/model/cohere.d.ts +6 -0
  7. package/dist/model/cohere.js +172 -0
  8. package/dist/model/google-genai/chat_models.d.ts +557 -0
  9. package/dist/model/google-genai/chat_models.js +755 -0
  10. package/dist/model/google-genai/embeddings.d.ts +94 -0
  11. package/dist/model/google-genai/embeddings.js +111 -0
  12. package/dist/model/google-genai/index.d.ts +2 -0
  13. package/dist/model/google-genai/index.js +18 -0
  14. package/dist/model/google-genai/output_parsers.d.ts +20 -0
  15. package/dist/model/google-genai/output_parsers.js +50 -0
  16. package/dist/model/google-genai/types.d.ts +3 -0
  17. package/dist/model/google-genai/types.js +2 -0
  18. package/dist/model/google-genai/utils/common.d.ts +22 -0
  19. package/dist/model/google-genai/utils/common.js +386 -0
  20. package/dist/model/google-genai/utils/tools.d.ts +10 -0
  21. package/dist/model/google-genai/utils/tools.js +110 -0
  22. package/dist/model/google-genai/utils/zod_to_genai_parameters.d.ts +13 -0
  23. package/dist/model/google-genai/utils/zod_to_genai_parameters.js +46 -0
  24. package/dist/model/google-genai.d.ts +11 -0
  25. package/dist/model/google-genai.js +30 -0
  26. package/dist/model/xai.d.ts +41 -0
  27. package/dist/model/xai.js +82 -0
  28. package/dist/model.d.ts +2 -0
  29. package/dist/model.js +141 -0
  30. package/dist/telemetry.d.ts +1 -0
  31. package/dist/telemetry.js +24 -0
  32. package/dist/tools.d.ts +15 -0
  33. package/dist/tools.js +24 -0
  34. package/package.json +2 -2
@@ -0,0 +1,94 @@
1
+ import { TaskType } from "@google/generative-ai";
2
+ import { Embeddings, EmbeddingsParams } from "@langchain/core/embeddings";
3
+ /**
4
+ * Interface that extends EmbeddingsParams and defines additional
5
+ * parameters specific to the GoogleGenerativeAIEmbeddings class.
6
+ */
7
+ export interface GoogleGenerativeAIEmbeddingsParams extends EmbeddingsParams {
8
+ /**
9
+ * Model Name to use
10
+ *
11
+ * Alias for `model`
12
+ *
13
+ * Note: The format must follow the pattern - `{model}`
14
+ */
15
+ modelName?: string;
16
+ /**
17
+ * Model Name to use
18
+ *
19
+ * Note: The format must follow the pattern - `{model}`
20
+ */
21
+ model?: string;
22
+ /**
23
+ * Type of task for which the embedding will be used
24
+ *
25
+ * Note: currently only supported by `embedding-001` model
26
+ */
27
+ taskType?: TaskType;
28
+ /**
29
+ * An optional title for the text. Only applicable when TaskType is
30
+ * `RETRIEVAL_DOCUMENT`
31
+ *
32
+ * Note: currently only supported by `embedding-001` model
33
+ */
34
+ title?: string;
35
+ /**
36
+ * Whether to strip new lines from the input text. Default to true
37
+ */
38
+ stripNewLines?: boolean;
39
+ /**
40
+ * Google API key to use
41
+ */
42
+ apiKey?: string;
43
+ }
44
+ /**
45
+ * Class that extends the Embeddings class and provides methods for
46
+ * generating embeddings using the Google Palm API.
47
+ * @example
48
+ * ```typescript
49
+ * const model = new GoogleGenerativeAIEmbeddings({
50
+ * apiKey: "<YOUR API KEY>",
51
+ * modelName: "embedding-001",
52
+ * });
53
+ *
54
+ * // Embed a single query
55
+ * const res = await model.embedQuery(
56
+ * "What would be a good company name for a company that makes colorful socks?"
57
+ * );
58
+ * console.log({ res });
59
+ *
60
+ * // Embed multiple documents
61
+ * const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
62
+ * console.log({ documentRes });
63
+ * ```
64
+ */
65
+ export declare class GoogleGenerativeAIEmbeddings extends Embeddings implements GoogleGenerativeAIEmbeddingsParams {
66
+ apiKey?: string;
67
+ modelName: string;
68
+ model: string;
69
+ taskType?: TaskType;
70
+ title?: string;
71
+ stripNewLines: boolean;
72
+ maxBatchSize: number;
73
+ private client;
74
+ constructor(fields?: GoogleGenerativeAIEmbeddingsParams);
75
+ private _convertToContent;
76
+ protected _embedQueryContent(text: string): Promise<number[]>;
77
+ protected _embedDocumentsContent(documents: string[]): Promise<number[][]>;
78
+ /**
79
+ * Method that takes a document as input and returns a promise that
80
+ * resolves to an embedding for the document. It calls the _embedText
81
+ * method with the document as the input.
82
+ * @param document Document for which to generate an embedding.
83
+ * @returns Promise that resolves to an embedding for the input document.
84
+ */
85
+ embedQuery(document: string): Promise<number[]>;
86
+ /**
87
+ * Method that takes an array of documents as input and returns a promise
88
+ * that resolves to a 2D array of embeddings for each document. It calls
89
+ * the _embedText method for each document in the array.
90
+ * @param documents Array of documents for which to generate embeddings.
91
+ * @returns Promise that resolves to a 2D array of embeddings for each input document.
92
+ */
93
+ embedDocuments(documents: string[]): Promise<number[][]>;
94
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleGenerativeAIEmbeddings = void 0;
4
+ const generative_ai_1 = require("@google/generative-ai");
5
+ const embeddings_1 = require("@langchain/core/embeddings");
6
+ const chunk_array_1 = require("@langchain/core/utils/chunk_array");
7
+ const env_1 = require("@langchain/core/utils/env");
8
+ /**
9
+ * Class that extends the Embeddings class and provides methods for
10
+ * generating embeddings using the Google Palm API.
11
+ * @example
12
+ * ```typescript
13
+ * const model = new GoogleGenerativeAIEmbeddings({
14
+ * apiKey: "<YOUR API KEY>",
15
+ * modelName: "embedding-001",
16
+ * });
17
+ *
18
+ * // Embed a single query
19
+ * const res = await model.embedQuery(
20
+ * "What would be a good company name for a company that makes colorful socks?"
21
+ * );
22
+ * console.log({ res });
23
+ *
24
+ * // Embed multiple documents
25
+ * const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
26
+ * console.log({ documentRes });
27
+ * ```
28
+ */
29
+ class GoogleGenerativeAIEmbeddings extends embeddings_1.Embeddings {
30
+ apiKey;
31
+ modelName = "embedding-001";
32
+ model = "embedding-001";
33
+ taskType;
34
+ title;
35
+ stripNewLines = true;
36
+ maxBatchSize = 100; // Max batch size for embedDocuments set by GenerativeModel client's batchEmbedContents call
37
+ client;
38
+ constructor(fields) {
39
+ super(fields ?? {});
40
+ this.modelName =
41
+ fields?.model?.replace(/^models\//, "") ??
42
+ fields?.modelName?.replace(/^models\//, "") ??
43
+ this.modelName;
44
+ this.model = this.modelName;
45
+ this.taskType = fields?.taskType ?? this.taskType;
46
+ this.title = fields?.title ?? this.title;
47
+ if (this.title && this.taskType !== generative_ai_1.TaskType.RETRIEVAL_DOCUMENT) {
48
+ throw new Error("title can only be specified with TaskType.RETRIEVAL_DOCUMENT");
49
+ }
50
+ this.apiKey = fields?.apiKey ?? (0, env_1.getEnvironmentVariable)("GOOGLE_API_KEY");
51
+ if (!this.apiKey) {
52
+ throw new Error("Please set an API key for Google GenerativeAI " +
53
+ "in the environmentb variable GOOGLE_API_KEY " +
54
+ "or in the `apiKey` field of the " +
55
+ "GoogleGenerativeAIEmbeddings constructor");
56
+ }
57
+ this.client = new generative_ai_1.GoogleGenerativeAI(this.apiKey).getGenerativeModel({
58
+ model: this.model,
59
+ });
60
+ }
61
+ _convertToContent(text) {
62
+ const cleanedText = this.stripNewLines ? text.replace(/\n/g, " ") : text;
63
+ return {
64
+ content: { role: "user", parts: [{ text: cleanedText }] },
65
+ taskType: this.taskType,
66
+ title: this.title,
67
+ };
68
+ }
69
+ async _embedQueryContent(text) {
70
+ const req = this._convertToContent(text);
71
+ const res = await this.client.embedContent(req);
72
+ return res.embedding.values ?? [];
73
+ }
74
+ async _embedDocumentsContent(documents) {
75
+ const batchEmbedChunks = (0, chunk_array_1.chunkArray)(documents, this.maxBatchSize);
76
+ const batchEmbedRequests = batchEmbedChunks.map((chunk) => ({
77
+ requests: chunk.map((doc) => this._convertToContent(doc)),
78
+ }));
79
+ const responses = await Promise.allSettled(batchEmbedRequests.map((req) => this.client.batchEmbedContents(req)));
80
+ const embeddings = responses.flatMap((res, idx) => {
81
+ if (res.status === "fulfilled") {
82
+ return res.value.embeddings.map((e) => e.values || []);
83
+ }
84
+ else {
85
+ return Array(batchEmbedChunks[idx].length).fill([]);
86
+ }
87
+ });
88
+ return embeddings;
89
+ }
90
+ /**
91
+ * Method that takes a document as input and returns a promise that
92
+ * resolves to an embedding for the document. It calls the _embedText
93
+ * method with the document as the input.
94
+ * @param document Document for which to generate an embedding.
95
+ * @returns Promise that resolves to an embedding for the input document.
96
+ */
97
+ embedQuery(document) {
98
+ return this.caller.call(this._embedQueryContent.bind(this), document);
99
+ }
100
+ /**
101
+ * Method that takes an array of documents as input and returns a promise
102
+ * that resolves to a 2D array of embeddings for each document. It calls
103
+ * the _embedText method for each document in the array.
104
+ * @param documents Array of documents for which to generate embeddings.
105
+ * @returns Promise that resolves to a 2D array of embeddings for each input document.
106
+ */
107
+ embedDocuments(documents) {
108
+ return this.caller.call(this._embedDocumentsContent.bind(this), documents);
109
+ }
110
+ }
111
+ exports.GoogleGenerativeAIEmbeddings = GoogleGenerativeAIEmbeddings;
@@ -0,0 +1,2 @@
1
+ export * from "./chat_models.js";
2
+ export * from "./embeddings.js";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./chat_models.js"), exports);
18
+ __exportStar(require("./embeddings.js"), exports);
@@ -0,0 +1,20 @@
1
+ import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
2
+ import { JsonOutputKeyToolsParserParams } from "@langchain/core/output_parsers/openai_tools";
3
+ import { ChatGeneration } from "@langchain/core/outputs";
4
+ import type { z } from "zod";
5
+ interface GoogleGenerativeAIToolsOutputParserParams<T extends Record<string, any>> extends JsonOutputKeyToolsParserParams<T> {
6
+ }
7
+ export declare class GoogleGenerativeAIToolsOutputParser<T extends Record<string, any> = Record<string, any>> extends BaseLLMOutputParser<T> {
8
+ static lc_name(): string;
9
+ lc_namespace: string[];
10
+ returnId: boolean;
11
+ /** The type of tool calls to return. */
12
+ keyName: string;
13
+ /** Whether to return only the first tool call. */
14
+ returnSingle: boolean;
15
+ zodSchema?: z.ZodType<T>;
16
+ constructor(params: GoogleGenerativeAIToolsOutputParserParams<T>);
17
+ protected _validateResult(result: unknown): Promise<T>;
18
+ parseResult(generations: ChatGeneration[]): Promise<T>;
19
+ }
20
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleGenerativeAIToolsOutputParser = void 0;
4
+ const output_parsers_1 = require("@langchain/core/output_parsers");
5
+ class GoogleGenerativeAIToolsOutputParser extends output_parsers_1.BaseLLMOutputParser {
6
+ static lc_name() {
7
+ return "GoogleGenerativeAIToolsOutputParser";
8
+ }
9
+ lc_namespace = ["langchain", "google_genai", "output_parsers"];
10
+ returnId = false;
11
+ /** The type of tool calls to return. */
12
+ keyName;
13
+ /** Whether to return only the first tool call. */
14
+ returnSingle = false;
15
+ zodSchema;
16
+ constructor(params) {
17
+ super(params);
18
+ this.keyName = params.keyName;
19
+ this.returnSingle = params.returnSingle ?? this.returnSingle;
20
+ this.zodSchema = params.zodSchema;
21
+ }
22
+ async _validateResult(result) {
23
+ if (this.zodSchema === undefined) {
24
+ return result;
25
+ }
26
+ const zodParsedResult = await this.zodSchema.safeParseAsync(result);
27
+ if (zodParsedResult.success) {
28
+ return zodParsedResult.data;
29
+ }
30
+ else {
31
+ throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.errors)}`, JSON.stringify(result, null, 2));
32
+ }
33
+ }
34
+ async parseResult(generations) {
35
+ const tools = generations.flatMap((generation) => {
36
+ const { message } = generation;
37
+ if (!("tool_calls" in message) || !Array.isArray(message.tool_calls)) {
38
+ return [];
39
+ }
40
+ return message.tool_calls;
41
+ });
42
+ if (tools[0] === undefined) {
43
+ throw new Error("No parseable tool calls provided to GoogleGenerativeAIToolsOutputParser.");
44
+ }
45
+ const [tool] = tools;
46
+ const validatedResult = await this._validateResult(tool.args);
47
+ return validatedResult;
48
+ }
49
+ }
50
+ exports.GoogleGenerativeAIToolsOutputParser = GoogleGenerativeAIToolsOutputParser;
@@ -0,0 +1,3 @@
1
+ import { CodeExecutionTool, FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, GoogleSearchRetrievalTool } from "@google/generative-ai";
2
+ import { BindToolsInput } from "@langchain/core/language_models/chat_models";
3
+ export type GoogleGenerativeAIToolType = BindToolsInput | GoogleGenerativeAIFunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ import { Content, EnhancedGenerateContentResponse, POSSIBLE_ROLES, Part, type FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool } from "@google/generative-ai";
2
+ import { BaseMessage, UsageMetadata } from "@langchain/core/messages";
3
+ import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
4
+ import { GoogleGenerativeAIToolType } from "../types.js";
5
+ export declare function getMessageAuthor(message: BaseMessage): string;
6
+ /**
7
+ * Maps a message type to a Google Generative AI chat author.
8
+ * @param message The message to map.
9
+ * @param model The model to use for mapping.
10
+ * @returns The message type mapped to a Google Generative AI chat author.
11
+ */
12
+ export declare function convertAuthorToRole(author: string): (typeof POSSIBLE_ROLES)[number];
13
+ export declare function convertMessageContentToParts(message: BaseMessage, isMultimodalModel: boolean): Part[];
14
+ export declare function convertBaseMessagesToContent(messages: BaseMessage[], isMultimodalModel: boolean, convertSystemMessageToHumanContent?: boolean): Content[];
15
+ export declare function mapGenerateContentResultToChatResult(response: EnhancedGenerateContentResponse, extra?: {
16
+ usageMetadata: UsageMetadata | undefined;
17
+ }): ChatResult;
18
+ export declare function convertResponseContentToChatGenerationChunk(response: EnhancedGenerateContentResponse, extra: {
19
+ usageMetadata?: UsageMetadata | undefined;
20
+ index: number;
21
+ }): ChatGenerationChunk | null;
22
+ export declare function convertToGenerativeAITools(tools: GoogleGenerativeAIToolType[]): GoogleGenerativeAIFunctionDeclarationsTool[];