@langchain/google-common 2.1.18 → 2.1.19

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 (108) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/auth.cjs +1 -2
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts.map +1 -1
  5. package/dist/auth.d.ts.map +1 -1
  6. package/dist/auth.js +1 -2
  7. package/dist/auth.js.map +1 -1
  8. package/dist/chat_models.cjs +24 -27
  9. package/dist/chat_models.cjs.map +1 -1
  10. package/dist/chat_models.d.cts.map +1 -1
  11. package/dist/chat_models.d.ts.map +1 -1
  12. package/dist/chat_models.js +7 -9
  13. package/dist/chat_models.js.map +1 -1
  14. package/dist/connection.cjs +16 -26
  15. package/dist/connection.cjs.map +1 -1
  16. package/dist/connection.d.cts.map +1 -1
  17. package/dist/connection.d.ts.map +1 -1
  18. package/dist/connection.js +13 -22
  19. package/dist/connection.js.map +1 -1
  20. package/dist/embeddings.cjs +12 -22
  21. package/dist/embeddings.cjs.map +1 -1
  22. package/dist/embeddings.d.cts +0 -1
  23. package/dist/embeddings.d.cts.map +1 -1
  24. package/dist/embeddings.d.ts +0 -1
  25. package/dist/embeddings.d.ts.map +1 -1
  26. package/dist/embeddings.js +7 -16
  27. package/dist/embeddings.js.map +1 -1
  28. package/dist/experimental/media.cjs +41 -70
  29. package/dist/experimental/media.cjs.map +1 -1
  30. package/dist/experimental/media.d.cts.map +1 -1
  31. package/dist/experimental/media.d.ts.map +1 -1
  32. package/dist/experimental/media.js +36 -65
  33. package/dist/experimental/media.js.map +1 -1
  34. package/dist/experimental/utils/media_core.cjs +22 -39
  35. package/dist/experimental/utils/media_core.cjs.map +1 -1
  36. package/dist/experimental/utils/media_core.d.cts.map +1 -1
  37. package/dist/experimental/utils/media_core.d.ts.map +1 -1
  38. package/dist/experimental/utils/media_core.js +16 -33
  39. package/dist/experimental/utils/media_core.js.map +1 -1
  40. package/dist/index.cjs +1 -0
  41. package/dist/llms.cjs +14 -19
  42. package/dist/llms.cjs.map +1 -1
  43. package/dist/llms.d.cts.map +1 -1
  44. package/dist/llms.d.ts.map +1 -1
  45. package/dist/llms.js +4 -8
  46. package/dist/llms.js.map +1 -1
  47. package/dist/output_parsers.cjs +12 -29
  48. package/dist/output_parsers.cjs.map +1 -1
  49. package/dist/output_parsers.d.cts.map +1 -1
  50. package/dist/output_parsers.d.ts.map +1 -1
  51. package/dist/output_parsers.js +10 -26
  52. package/dist/output_parsers.js.map +1 -1
  53. package/dist/profiles.cjs +100 -17
  54. package/dist/profiles.cjs.map +1 -1
  55. package/dist/profiles.js +100 -17
  56. package/dist/profiles.js.map +1 -1
  57. package/dist/types-anthropic.d.cts.map +1 -1
  58. package/dist/types-anthropic.d.ts.map +1 -1
  59. package/dist/types.cjs +1 -0
  60. package/dist/types.cjs.map +1 -1
  61. package/dist/types.d.cts +0 -1
  62. package/dist/types.d.cts.map +1 -1
  63. package/dist/types.d.ts +0 -1
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js.map +1 -1
  66. package/dist/utils/anthropic.cjs +73 -113
  67. package/dist/utils/anthropic.cjs.map +1 -1
  68. package/dist/utils/anthropic.js +63 -102
  69. package/dist/utils/anthropic.js.map +1 -1
  70. package/dist/utils/common.cjs +10 -13
  71. package/dist/utils/common.cjs.map +1 -1
  72. package/dist/utils/common.d.cts.map +1 -1
  73. package/dist/utils/common.d.ts.map +1 -1
  74. package/dist/utils/common.js +6 -8
  75. package/dist/utils/common.js.map +1 -1
  76. package/dist/utils/failed_handler.cjs +1 -2
  77. package/dist/utils/failed_handler.cjs.map +1 -1
  78. package/dist/utils/failed_handler.d.cts.map +1 -1
  79. package/dist/utils/failed_handler.d.ts.map +1 -1
  80. package/dist/utils/failed_handler.js +1 -2
  81. package/dist/utils/failed_handler.js.map +1 -1
  82. package/dist/utils/gemini.cjs +83 -135
  83. package/dist/utils/gemini.cjs.map +1 -1
  84. package/dist/utils/gemini.d.cts.map +1 -1
  85. package/dist/utils/gemini.d.ts.map +1 -1
  86. package/dist/utils/gemini.js +58 -109
  87. package/dist/utils/gemini.js.map +1 -1
  88. package/dist/utils/index.cjs +1 -0
  89. package/dist/utils/palm.d.cts.map +1 -1
  90. package/dist/utils/palm.d.ts.map +1 -1
  91. package/dist/utils/safety.cjs.map +1 -1
  92. package/dist/utils/safety.d.cts.map +1 -1
  93. package/dist/utils/safety.d.ts.map +1 -1
  94. package/dist/utils/safety.js.map +1 -1
  95. package/dist/utils/stream.cjs +5 -9
  96. package/dist/utils/stream.cjs.map +1 -1
  97. package/dist/utils/stream.d.cts.map +1 -1
  98. package/dist/utils/stream.d.ts.map +1 -1
  99. package/dist/utils/stream.js +5 -9
  100. package/dist/utils/stream.js.map +1 -1
  101. package/dist/utils/zod_to_gemini_parameters.cjs +4 -7
  102. package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -1
  103. package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -1
  104. package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -1
  105. package/dist/utils/zod_to_gemini_parameters.js +2 -4
  106. package/dist/utils/zod_to_gemini_parameters.js.map +1 -1
  107. package/package.json +3 -3
  108. package/dist/_virtual/rolldown_runtime.cjs +0 -25
package/dist/llms.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llms.cjs","names":["AbstractGoogleLLMConnection","input: MessageContent","_parameters: GoogleAIModelParams","contents: GeminiContent[]","ChatGoogleBase","fields: ProxyChatInput<AuthOptions>","LLM","fields?: GoogleBaseLLMInput<AuthOptions>","ensureParams","copyAndValidateModelParamsInto","DefaultGeminiSafetyHandler","apiKey: string","ApiKeyGoogleAuth","fields?: GoogleAIBaseLLMInput<AuthOptions>","fields: GoogleBaseLLMInput<AuthOptions>","client: GoogleAbstractedClient","prompt: string","options: this[\"ParsedCallOptions\"]","copyAIModelParams","input: BaseLanguageModelInput","options?: BaseLanguageModelCallOptions","BaseLLM","CallbackManager","GenerationChunk","messages: BaseMessage[]","options?: string[] | BaseLanguageModelCallOptions","_callbacks?: Callbacks"],"sources":["../src/llms.ts"],"sourcesContent":["import { CallbackManager, Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { BaseLLM, LLM } from \"@langchain/core/language_models/llms\";\nimport {\n type BaseLanguageModelCallOptions,\n BaseLanguageModelInput,\n} from \"@langchain/core/language_models/base\";\nimport { BaseMessage, MessageContent } from \"@langchain/core/messages\";\nimport { GenerationChunk } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\n\nimport { AbstractGoogleLLMConnection } from \"./connection.js\";\nimport {\n GoogleAIBaseLLMInput,\n GoogleAIModelParams,\n GoogleAISafetySetting,\n GooglePlatformType,\n GeminiContent,\n GoogleAIResponseMimeType,\n} from \"./types.js\";\nimport {\n copyAIModelParams,\n copyAndValidateModelParamsInto,\n} from \"./utils/common.js\";\nimport { DefaultGeminiSafetyHandler } from \"./utils/gemini.js\";\nimport { ApiKeyGoogleAuth, GoogleAbstractedClient } from \"./auth.js\";\nimport { ensureParams } from \"./utils/failed_handler.js\";\nimport { ChatGoogleBase } from \"./chat_models.js\";\nimport type { GoogleBaseLLMInput, GoogleAISafetyHandler } from \"./types.js\";\n\nexport { GoogleBaseLLMInput };\n\nclass GoogleLLMConnection<AuthOptions> extends AbstractGoogleLLMConnection<\n MessageContent,\n AuthOptions\n> {\n async formatContents(\n input: MessageContent,\n _parameters: GoogleAIModelParams\n ): Promise<GeminiContent[]> {\n const parts = await this.api.messageContentToParts!(input);\n const contents: GeminiContent[] = [\n {\n role: \"user\", // Required by Vertex AI\n parts,\n },\n ];\n return contents;\n }\n}\n\ntype ProxyChatInput<AuthOptions> = GoogleAIBaseLLMInput<AuthOptions> & {\n connection: GoogleLLMConnection<AuthOptions>;\n};\n\nclass ProxyChatGoogle<AuthOptions> extends ChatGoogleBase<AuthOptions> {\n constructor(fields: ProxyChatInput<AuthOptions>) {\n super(fields);\n }\n\n buildAbstractedClient(\n fields: ProxyChatInput<AuthOptions>\n ): GoogleAbstractedClient {\n return fields.connection.client;\n }\n}\n\n/**\n * Integration with an LLM.\n */\nexport abstract class GoogleBaseLLM<AuthOptions>\n extends LLM<BaseLanguageModelCallOptions>\n implements GoogleBaseLLMInput<AuthOptions>\n{\n // Used for tracing, replace with the same name as your class\n static lc_name() {\n return \"GoogleLLM\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n authOptions: \"GOOGLE_AUTH_OPTIONS\",\n };\n }\n\n originalFields?: GoogleBaseLLMInput<AuthOptions>;\n\n lc_serializable = true;\n\n modelName = \"gemini-pro\";\n\n model = \"gemini-pro\";\n\n temperature = 0.7;\n\n maxOutputTokens = 1024;\n\n topP = 0.8;\n\n topK = 40;\n\n stopSequences: string[] = [];\n\n safetySettings: GoogleAISafetySetting[] = [];\n\n safetyHandler: GoogleAISafetyHandler;\n\n responseMimeType: GoogleAIResponseMimeType = \"text/plain\";\n\n protected connection: GoogleLLMConnection<AuthOptions>;\n\n protected streamedConnection: GoogleLLMConnection<AuthOptions>;\n\n constructor(fields?: GoogleBaseLLMInput<AuthOptions>) {\n super(ensureParams(fields));\n this.originalFields = fields;\n\n copyAndValidateModelParamsInto(fields, this);\n this.safetyHandler =\n fields?.safetyHandler ?? new DefaultGeminiSafetyHandler();\n\n const client = this.buildClient(fields);\n this.buildConnection(fields ?? {}, client);\n }\n\n abstract buildAbstractedClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient;\n\n buildApiKeyClient(apiKey: string): GoogleAbstractedClient {\n return new ApiKeyGoogleAuth(apiKey);\n }\n\n buildApiKey(fields?: GoogleAIBaseLLMInput<AuthOptions>): string | undefined {\n return fields?.apiKey ?? getEnvironmentVariable(\"GOOGLE_API_KEY\");\n }\n\n buildClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient {\n const apiKey = this.buildApiKey(fields);\n if (apiKey) {\n return this.buildApiKeyClient(apiKey);\n } else {\n return this.buildAbstractedClient(fields);\n }\n }\n\n buildConnection(\n fields: GoogleBaseLLMInput<AuthOptions>,\n client: GoogleAbstractedClient\n ) {\n this.connection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n false\n );\n\n this.streamedConnection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n true\n );\n }\n\n get platform(): GooglePlatformType {\n return this.connection.platform;\n }\n\n // Replace\n _llmType() {\n return \"googlellm\";\n }\n\n formatPrompt(prompt: string): MessageContent {\n return prompt;\n }\n\n /**\n * For some given input string and options, return a string output.\n *\n * Despite the fact that `invoke` is overridden below, we still need this\n * in order to handle public APi calls to `generate()`.\n */\n async _call(\n prompt: string,\n options: this[\"ParsedCallOptions\"]\n ): Promise<string> {\n const parameters = copyAIModelParams(this, options);\n const result = await this.connection.request(prompt, parameters, options);\n const ret = this.connection.api.responseToString(result);\n return ret;\n }\n\n // Normally, you should not override this method and instead should override\n // _streamResponseChunks. We are doing so here to allow for multimodal inputs into\n // the LLM.\n async *_streamIterator(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): AsyncGenerator<string> {\n // TODO: Refactor callback setup and teardown code into core\n const prompt = BaseLLM._convertInputToPromptValue(input);\n const [runnableConfig, callOptions] =\n this._separateRunnableConfigFromCallOptions(options);\n const callbackManager_ = await CallbackManager.configure(\n runnableConfig.callbacks,\n this.callbacks,\n runnableConfig.tags,\n this.tags,\n runnableConfig.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const extra = {\n options: callOptions,\n invocation_params: this?.invocationParams(callOptions),\n batch_size: 1,\n };\n const runManagers = await callbackManager_?.handleLLMStart(\n this.toJSON(),\n [prompt.toString()],\n undefined,\n undefined,\n extra,\n undefined,\n undefined,\n runnableConfig.runName\n );\n let generation = new GenerationChunk({\n text: \"\",\n });\n const proxyChat = this.createProxyChat();\n try {\n for await (const chunk of proxyChat._streamIterator(input, options)) {\n const stringValue = this.connection.api.chunkToString(chunk);\n const generationChunk = new GenerationChunk({\n text: stringValue,\n });\n generation = generation.concat(generationChunk);\n yield stringValue;\n }\n } catch (err) {\n await Promise.all(\n (runManagers ?? []).map((runManager) => runManager?.handleLLMError(err))\n );\n throw err;\n }\n await Promise.all(\n (runManagers ?? []).map((runManager) =>\n runManager?.handleLLMEnd({\n generations: [[generation]],\n })\n )\n );\n }\n\n async predictMessages(\n messages: BaseMessage[],\n options?: string[] | BaseLanguageModelCallOptions,\n _callbacks?: Callbacks\n ): Promise<BaseMessage> {\n const { content } = messages[0];\n const result = await this.connection.request(\n content,\n {},\n options as BaseLanguageModelCallOptions\n );\n const ret = this.connection.api.responseToBaseMessage(result);\n return ret;\n }\n\n /**\n * Internal implementation detail to allow Google LLMs to support\n * multimodal input by delegating to the chat model implementation.\n *\n * TODO: Replace with something less hacky.\n */\n protected createProxyChat(): ChatGoogleBase<AuthOptions> {\n return new ProxyChatGoogle<AuthOptions>({\n ...this.originalFields,\n connection: this.connection,\n });\n }\n\n // TODO: Remove the need to override this - we are doing it to\n // allow the LLM to handle multimodal types of input.\n async invoke(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): Promise<string> {\n const stream = await this._streamIterator(input, options);\n let generatedOutput = \"\";\n for await (const chunk of stream) {\n generatedOutput += chunk;\n }\n return generatedOutput;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,IAAM,sBAAN,cAA+CA,+CAG7C;CACA,MAAM,eACJC,OACAC,aAC0B;EAC1B,MAAM,QAAQ,MAAM,KAAK,IAAI,sBAAuB,MAAM;EAC1D,MAAMC,WAA4B,CAChC;GACE,MAAM;GACN;EACD,CACF;AACD,SAAO;CACR;AACF;AAMD,IAAM,kBAAN,cAA2CC,mCAA4B;CACrE,YAAYC,QAAqC;EAC/C,MAAM,OAAO;CACd;CAED,sBACEA,QACwB;AACxB,SAAO,OAAO,WAAW;CAC1B;AACF;;;;AAKD,IAAsB,gBAAtB,cACUC,0CAEV;C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,MAAM,KAAK,WAAW,IAAI,sBAAsB,OAAO;AAC7D,SAAO;CACR;;;;;;;CAQD,AAAU,kBAA+C;AACvD,SAAO,IAAI,gBAA6B;GACtC,GAAG,KAAK;GACR,YAAY,KAAK;EAClB;CACF;CAID,MAAM,OACJP,OACAC,SACiB;EACjB,MAAM,SAAS,MAAM,KAAK,gBAAgB,OAAO,QAAQ;EACzD,IAAI,kBAAkB;AACtB,aAAW,MAAM,SAAS,QACxB,mBAAmB;AAErB,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"llms.cjs","names":["AbstractGoogleLLMConnection","ChatGoogleBase","LLM","ensureParams","DefaultGeminiSafetyHandler","ApiKeyGoogleAuth","copyAIModelParams","BaseLLM","CallbackManager","GenerationChunk"],"sources":["../src/llms.ts"],"sourcesContent":["import { CallbackManager, Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { BaseLLM, LLM } from \"@langchain/core/language_models/llms\";\nimport {\n type BaseLanguageModelCallOptions,\n BaseLanguageModelInput,\n} from \"@langchain/core/language_models/base\";\nimport { BaseMessage, MessageContent } from \"@langchain/core/messages\";\nimport { GenerationChunk } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\n\nimport { AbstractGoogleLLMConnection } from \"./connection.js\";\nimport {\n GoogleAIBaseLLMInput,\n GoogleAIModelParams,\n GoogleAISafetySetting,\n GooglePlatformType,\n GeminiContent,\n GoogleAIResponseMimeType,\n} from \"./types.js\";\nimport {\n copyAIModelParams,\n copyAndValidateModelParamsInto,\n} from \"./utils/common.js\";\nimport { DefaultGeminiSafetyHandler } from \"./utils/gemini.js\";\nimport { ApiKeyGoogleAuth, GoogleAbstractedClient } from \"./auth.js\";\nimport { ensureParams } from \"./utils/failed_handler.js\";\nimport { ChatGoogleBase } from \"./chat_models.js\";\nimport type { GoogleBaseLLMInput, GoogleAISafetyHandler } from \"./types.js\";\n\nexport { GoogleBaseLLMInput };\n\nclass GoogleLLMConnection<AuthOptions> extends AbstractGoogleLLMConnection<\n MessageContent,\n AuthOptions\n> {\n async formatContents(\n input: MessageContent,\n _parameters: GoogleAIModelParams\n ): Promise<GeminiContent[]> {\n const parts = await this.api.messageContentToParts!(input);\n const contents: GeminiContent[] = [\n {\n role: \"user\", // Required by Vertex AI\n parts,\n },\n ];\n return contents;\n }\n}\n\ntype ProxyChatInput<AuthOptions> = GoogleAIBaseLLMInput<AuthOptions> & {\n connection: GoogleLLMConnection<AuthOptions>;\n};\n\nclass ProxyChatGoogle<AuthOptions> extends ChatGoogleBase<AuthOptions> {\n constructor(fields: ProxyChatInput<AuthOptions>) {\n super(fields);\n }\n\n buildAbstractedClient(\n fields: ProxyChatInput<AuthOptions>\n ): GoogleAbstractedClient {\n return fields.connection.client;\n }\n}\n\n/**\n * Integration with an LLM.\n */\nexport abstract class GoogleBaseLLM<AuthOptions>\n extends LLM<BaseLanguageModelCallOptions>\n implements GoogleBaseLLMInput<AuthOptions>\n{\n // Used for tracing, replace with the same name as your class\n static lc_name() {\n return \"GoogleLLM\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n authOptions: \"GOOGLE_AUTH_OPTIONS\",\n };\n }\n\n originalFields?: GoogleBaseLLMInput<AuthOptions>;\n\n lc_serializable = true;\n\n modelName = \"gemini-pro\";\n\n model = \"gemini-pro\";\n\n temperature = 0.7;\n\n maxOutputTokens = 1024;\n\n topP = 0.8;\n\n topK = 40;\n\n stopSequences: string[] = [];\n\n safetySettings: GoogleAISafetySetting[] = [];\n\n safetyHandler: GoogleAISafetyHandler;\n\n responseMimeType: GoogleAIResponseMimeType = \"text/plain\";\n\n protected connection: GoogleLLMConnection<AuthOptions>;\n\n protected streamedConnection: GoogleLLMConnection<AuthOptions>;\n\n constructor(fields?: GoogleBaseLLMInput<AuthOptions>) {\n super(ensureParams(fields));\n this.originalFields = fields;\n\n copyAndValidateModelParamsInto(fields, this);\n this.safetyHandler =\n fields?.safetyHandler ?? new DefaultGeminiSafetyHandler();\n\n const client = this.buildClient(fields);\n this.buildConnection(fields ?? {}, client);\n }\n\n abstract buildAbstractedClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient;\n\n buildApiKeyClient(apiKey: string): GoogleAbstractedClient {\n return new ApiKeyGoogleAuth(apiKey);\n }\n\n buildApiKey(fields?: GoogleAIBaseLLMInput<AuthOptions>): string | undefined {\n return fields?.apiKey ?? getEnvironmentVariable(\"GOOGLE_API_KEY\");\n }\n\n buildClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient {\n const apiKey = this.buildApiKey(fields);\n if (apiKey) {\n return this.buildApiKeyClient(apiKey);\n } else {\n return this.buildAbstractedClient(fields);\n }\n }\n\n buildConnection(\n fields: GoogleBaseLLMInput<AuthOptions>,\n client: GoogleAbstractedClient\n ) {\n this.connection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n false\n );\n\n this.streamedConnection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n true\n );\n }\n\n get platform(): GooglePlatformType {\n return this.connection.platform;\n }\n\n // Replace\n _llmType() {\n return \"googlellm\";\n }\n\n formatPrompt(prompt: string): MessageContent {\n return prompt;\n }\n\n /**\n * For some given input string and options, return a string output.\n *\n * Despite the fact that `invoke` is overridden below, we still need this\n * in order to handle public APi calls to `generate()`.\n */\n async _call(\n prompt: string,\n options: this[\"ParsedCallOptions\"]\n ): Promise<string> {\n const parameters = copyAIModelParams(this, options);\n const result = await this.connection.request(prompt, parameters, options);\n const ret = this.connection.api.responseToString(result);\n return ret;\n }\n\n // Normally, you should not override this method and instead should override\n // _streamResponseChunks. We are doing so here to allow for multimodal inputs into\n // the LLM.\n async *_streamIterator(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): AsyncGenerator<string> {\n // TODO: Refactor callback setup and teardown code into core\n const prompt = BaseLLM._convertInputToPromptValue(input);\n const [runnableConfig, callOptions] =\n this._separateRunnableConfigFromCallOptions(options);\n const callbackManager_ = await CallbackManager.configure(\n runnableConfig.callbacks,\n this.callbacks,\n runnableConfig.tags,\n this.tags,\n runnableConfig.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const extra = {\n options: callOptions,\n invocation_params: this?.invocationParams(callOptions),\n batch_size: 1,\n };\n const runManagers = await callbackManager_?.handleLLMStart(\n this.toJSON(),\n [prompt.toString()],\n undefined,\n undefined,\n extra,\n undefined,\n undefined,\n runnableConfig.runName\n );\n let generation = new GenerationChunk({\n text: \"\",\n });\n const proxyChat = this.createProxyChat();\n try {\n for await (const chunk of proxyChat._streamIterator(input, options)) {\n const stringValue = this.connection.api.chunkToString(chunk);\n const generationChunk = new GenerationChunk({\n text: stringValue,\n });\n generation = generation.concat(generationChunk);\n yield stringValue;\n }\n } catch (err) {\n await Promise.all(\n (runManagers ?? []).map((runManager) => runManager?.handleLLMError(err))\n );\n throw err;\n }\n await Promise.all(\n (runManagers ?? []).map((runManager) =>\n runManager?.handleLLMEnd({\n generations: [[generation]],\n })\n )\n );\n }\n\n async predictMessages(\n messages: BaseMessage[],\n options?: string[] | BaseLanguageModelCallOptions,\n _callbacks?: Callbacks\n ): Promise<BaseMessage> {\n const { content } = messages[0];\n const result = await this.connection.request(\n content,\n {},\n options as BaseLanguageModelCallOptions\n );\n const ret = this.connection.api.responseToBaseMessage(result);\n return ret;\n }\n\n /**\n * Internal implementation detail to allow Google LLMs to support\n * multimodal input by delegating to the chat model implementation.\n *\n * TODO: Replace with something less hacky.\n */\n protected createProxyChat(): ChatGoogleBase<AuthOptions> {\n return new ProxyChatGoogle<AuthOptions>({\n ...this.originalFields,\n connection: this.connection,\n });\n }\n\n // TODO: Remove the need to override this - we are doing it to\n // allow the LLM to handle multimodal types of input.\n async invoke(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): Promise<string> {\n const stream = await this._streamIterator(input, options);\n let generatedOutput = \"\";\n for await (const chunk of stream) {\n generatedOutput += chunk;\n }\n return generatedOutput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ACD,SAAM;;AAER,QAAM,QAAQ,KACX,eAAe,EAAE,EAAE,KAAK,eACvB,YAAY,aAAa,EACvB,aAAa,CAAC,CAAC,WAAW,CAAC,EAC5B,CAAC,CACH,CACF;;CAGH,MAAM,gBACJ,UACA,SACA,YACsB;EACtB,MAAM,EAAE,YAAY,SAAS;EAC7B,MAAM,SAAS,MAAM,KAAK,WAAW,QACnC,SACA,EAAE,EACF,QACD;AAED,SADY,KAAK,WAAW,IAAI,sBAAsB,OAAO;;;;;;;;CAU/D,AAAU,kBAA+C;AACvD,SAAO,IAAI,gBAA6B;GACtC,GAAG,KAAK;GACR,YAAY,KAAK;GAClB,CAAC;;CAKJ,MAAM,OACJ,OACA,SACiB;EACjB,MAAM,SAAS,MAAM,KAAK,gBAAgB,OAAO,QAAQ;EACzD,IAAI,kBAAkB;AACtB,aAAW,MAAM,SAAS,OACxB,oBAAmB;AAErB,SAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"llms.d.cts","names":["Callbacks","LLM","BaseLanguageModelCallOptions","BaseLanguageModelInput","BaseMessage","MessageContent","AbstractGoogleLLMConnection","GoogleAIBaseLLMInput","GoogleAIModelParams","GoogleAISafetySetting","GooglePlatformType","GeminiContent","GoogleAIResponseMimeType","GoogleAbstractedClient","ChatGoogleBase","GoogleBaseLLMInput","GoogleAISafetyHandler","GoogleLLMConnection","AuthOptions","Promise","GoogleBaseLLM","AsyncGenerator"],"sources":["../src/llms.d.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { LLM } from \"@langchain/core/language_models/llms\";\nimport { type BaseLanguageModelCallOptions, BaseLanguageModelInput } from \"@langchain/core/language_models/base\";\nimport { BaseMessage, MessageContent } from \"@langchain/core/messages\";\nimport { AbstractGoogleLLMConnection } from \"./connection.js\";\nimport { GoogleAIBaseLLMInput, GoogleAIModelParams, GoogleAISafetySetting, GooglePlatformType, GeminiContent, GoogleAIResponseMimeType } from \"./types.js\";\nimport { GoogleAbstractedClient } from \"./auth.js\";\nimport { ChatGoogleBase } from \"./chat_models.js\";\nimport type { GoogleBaseLLMInput, GoogleAISafetyHandler } from \"./types.js\";\nexport { GoogleBaseLLMInput };\ndeclare class GoogleLLMConnection<AuthOptions> extends AbstractGoogleLLMConnection<MessageContent, AuthOptions> {\n formatContents(input: MessageContent, _parameters: GoogleAIModelParams): Promise<GeminiContent[]>;\n}\n/**\n * Integration with an LLM.\n */\nexport declare abstract class GoogleBaseLLM<AuthOptions> extends LLM<BaseLanguageModelCallOptions> implements GoogleBaseLLMInput<AuthOptions> {\n static lc_name(): string;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n originalFields?: GoogleBaseLLMInput<AuthOptions>;\n lc_serializable: boolean;\n modelName: string;\n model: string;\n temperature: number;\n maxOutputTokens: number;\n topP: number;\n topK: number;\n stopSequences: string[];\n safetySettings: GoogleAISafetySetting[];\n safetyHandler: GoogleAISafetyHandler;\n responseMimeType: GoogleAIResponseMimeType;\n protected connection: GoogleLLMConnection<AuthOptions>;\n protected streamedConnection: GoogleLLMConnection<AuthOptions>;\n constructor(fields?: GoogleBaseLLMInput<AuthOptions>);\n abstract buildAbstractedClient(fields?: GoogleAIBaseLLMInput<AuthOptions>): GoogleAbstractedClient;\n buildApiKeyClient(apiKey: string): GoogleAbstractedClient;\n buildApiKey(fields?: GoogleAIBaseLLMInput<AuthOptions>): string | undefined;\n buildClient(fields?: GoogleAIBaseLLMInput<AuthOptions>): GoogleAbstractedClient;\n buildConnection(fields: GoogleBaseLLMInput<AuthOptions>, client: GoogleAbstractedClient): void;\n get platform(): GooglePlatformType;\n _llmType(): string;\n formatPrompt(prompt: string): MessageContent;\n /**\n * For some given input string and options, return a string output.\n *\n * Despite the fact that `invoke` is overridden below, we still need this\n * in order to handle public APi calls to `generate()`.\n */\n _call(prompt: string, options: this[\"ParsedCallOptions\"]): Promise<string>;\n _streamIterator(input: BaseLanguageModelInput, options?: BaseLanguageModelCallOptions): AsyncGenerator<string>;\n predictMessages(messages: BaseMessage[], options?: string[] | BaseLanguageModelCallOptions, _callbacks?: Callbacks): Promise<BaseMessage>;\n /**\n * Internal implementation detail to allow Google LLMs to support\n * multimodal input by delegating to the chat model implementation.\n *\n * TODO: Replace with something less hacky.\n */\n protected createProxyChat(): ChatGoogleBase<AuthOptions>;\n invoke(input: BaseLanguageModelInput, options?: BaseLanguageModelCallOptions): Promise<string>;\n}\n//# sourceMappingURL=llms.d.ts.map"],"mappings":";;;;;;;;;;AAS8B,cAChBiB,mBAAmBC,CAAAA,WAAAA,CAAAA,SAAsBZ,2BAAtB,CAAkDD,cAAlD,EAAkEa,WAAlE,CAAA,CAAA;EAAkDb,cAAAA,CAAAA,KAAAA,EACzDA,cADyDA,EAAAA,WAAAA,EAC5BG,mBAD4BH,CAAAA,EACNc,OADMd,CACEM,aADFN,EAAAA,CAAAA;;;;;AACNc,uBAK/CC,aAL+CD,CAAAA,WAAAA,CAAAA,SAKZlB,GALYkB,CAKRjB,4BALQiB,CAAAA,YAKiCJ,kBALjCI,CAKoDD,WALpDC,CAAAA,CAAAA;EADtBb,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAA2B,IAAA,UAAA,CAAA,CAAA,EAAA;IAMpDc,CAAAA,GAAAA,EAAAA,MAAa,CAAA,EAAA,MAAAF;EAA0BhB,CAAAA,GAAAA,SAAAA;EAA4DgB,cAAAA,CAAAA,EAK5GH,kBAL4GG,CAKzFA,WALyFA,CAAAA;EAKzFA,eAAAA,EAAAA,OAAAA;EAAnBH,SAAAA,EAAAA,MAAAA;EASDN,KAAAA,EAAAA,MAAAA;EACDO,WAAAA,EAAAA,MAAAA;EACGJ,eAAAA,EAAAA,MAAAA;EACwBM,IAAAA,EAAAA,MAAAA;EAApBD,IAAAA,EAAAA,MAAAA;EAC4BC,aAAAA,EAAAA,MAAAA,EAAAA;EAApBD,cAAAA,EAJdR,qBAIcQ,EAAAA;EACUC,aAAAA,EAJzBF,qBAIyBE;EAAnBH,gBAAAA,EAHH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WAAA;EAI1C,WAAA,CACE,MAAA,GAAS,oBAAA,CAAqB,WAAA,IAC7B,sBAAA;EASH,eAAA,CACE,MAAA,EAAQ,kBAAA,CAAmB,WAAA,GAC3B,MAAA,EAAQ,sBAAA;EAAA,IAiBN,QAAA,CAAA,GAAY,kBAAA;EAKhB,QAAA,CAAA;EAIA,YAAA,CAAa,MAAA,WAAiB,cAAA;EArEZ;;;;;;EA+EZ,KAAA,CACJ,MAAA,UACA,OAAA,8BACC,OAAA;EAUI,eAAA,CACL,KAAA,EAAO,sBAAA,EACP,OAAA,GAAU,4BAAA,GACT,cAAA;EAyDG,eAAA,CACJ,QAAA,EAAU,WAAA,IACV,OAAA,cAAqB,4BAAA,EACrB,UAAA,GAAa,SAAA,GACZ,OAAA,CAAQ,WAAA;EAxIR;;;;;;EAAA,UAyJO,eAAA,CAAA,GAAmB,cAAA,CAAe,WAAA;EAStC,MAAA,CACJ,KAAA,EAAO,sBAAA,EACP,OAAA,GAAU,4BAAA,GACT,OAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"llms.d.ts","names":["Callbacks","LLM","BaseLanguageModelCallOptions","BaseLanguageModelInput","BaseMessage","MessageContent","AbstractGoogleLLMConnection","GoogleAIBaseLLMInput","GoogleAIModelParams","GoogleAISafetySetting","GooglePlatformType","GeminiContent","GoogleAIResponseMimeType","GoogleAbstractedClient","ChatGoogleBase","GoogleBaseLLMInput","GoogleAISafetyHandler","GoogleLLMConnection","AuthOptions","Promise","GoogleBaseLLM","AsyncGenerator"],"sources":["../src/llms.d.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { LLM } from \"@langchain/core/language_models/llms\";\nimport { type BaseLanguageModelCallOptions, BaseLanguageModelInput } from \"@langchain/core/language_models/base\";\nimport { BaseMessage, MessageContent } from \"@langchain/core/messages\";\nimport { AbstractGoogleLLMConnection } from \"./connection.js\";\nimport { GoogleAIBaseLLMInput, GoogleAIModelParams, GoogleAISafetySetting, GooglePlatformType, GeminiContent, GoogleAIResponseMimeType } from \"./types.js\";\nimport { GoogleAbstractedClient } from \"./auth.js\";\nimport { ChatGoogleBase } from \"./chat_models.js\";\nimport type { GoogleBaseLLMInput, GoogleAISafetyHandler } from \"./types.js\";\nexport { GoogleBaseLLMInput };\ndeclare class GoogleLLMConnection<AuthOptions> extends AbstractGoogleLLMConnection<MessageContent, AuthOptions> {\n formatContents(input: MessageContent, _parameters: GoogleAIModelParams): Promise<GeminiContent[]>;\n}\n/**\n * Integration with an LLM.\n */\nexport declare abstract class GoogleBaseLLM<AuthOptions> extends LLM<BaseLanguageModelCallOptions> implements GoogleBaseLLMInput<AuthOptions> {\n static lc_name(): string;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n originalFields?: GoogleBaseLLMInput<AuthOptions>;\n lc_serializable: boolean;\n modelName: string;\n model: string;\n temperature: number;\n maxOutputTokens: number;\n topP: number;\n topK: number;\n stopSequences: string[];\n safetySettings: GoogleAISafetySetting[];\n safetyHandler: GoogleAISafetyHandler;\n responseMimeType: GoogleAIResponseMimeType;\n protected connection: GoogleLLMConnection<AuthOptions>;\n protected streamedConnection: GoogleLLMConnection<AuthOptions>;\n constructor(fields?: GoogleBaseLLMInput<AuthOptions>);\n abstract buildAbstractedClient(fields?: GoogleAIBaseLLMInput<AuthOptions>): GoogleAbstractedClient;\n buildApiKeyClient(apiKey: string): GoogleAbstractedClient;\n buildApiKey(fields?: GoogleAIBaseLLMInput<AuthOptions>): string | undefined;\n buildClient(fields?: GoogleAIBaseLLMInput<AuthOptions>): GoogleAbstractedClient;\n buildConnection(fields: GoogleBaseLLMInput<AuthOptions>, client: GoogleAbstractedClient): void;\n get platform(): GooglePlatformType;\n _llmType(): string;\n formatPrompt(prompt: string): MessageContent;\n /**\n * For some given input string and options, return a string output.\n *\n * Despite the fact that `invoke` is overridden below, we still need this\n * in order to handle public APi calls to `generate()`.\n */\n _call(prompt: string, options: this[\"ParsedCallOptions\"]): Promise<string>;\n _streamIterator(input: BaseLanguageModelInput, options?: BaseLanguageModelCallOptions): AsyncGenerator<string>;\n predictMessages(messages: BaseMessage[], options?: string[] | BaseLanguageModelCallOptions, _callbacks?: Callbacks): Promise<BaseMessage>;\n /**\n * Internal implementation detail to allow Google LLMs to support\n * multimodal input by delegating to the chat model implementation.\n *\n * TODO: Replace with something less hacky.\n */\n protected createProxyChat(): ChatGoogleBase<AuthOptions>;\n invoke(input: BaseLanguageModelInput, options?: BaseLanguageModelCallOptions): Promise<string>;\n}\n//# sourceMappingURL=llms.d.ts.map"],"mappings":";;;;;;;;;;AAS8B,cAChBiB,mBAAmBC,CAAAA,WAAAA,CAAAA,SAAsBZ,2BAAtB,CAAkDD,cAAlD,EAAkEa,WAAlE,CAAA,CAAA;EAAkDb,cAAAA,CAAAA,KAAAA,EACzDA,cADyDA,EAAAA,WAAAA,EAC5BG,mBAD4BH,CAAAA,EACNc,OADMd,CACEM,aADFN,EAAAA,CAAAA;;;;;AACNc,uBAK/CC,aAL+CD,CAAAA,WAAAA,CAAAA,SAKZlB,GALYkB,CAKRjB,4BALQiB,CAAAA,YAKiCJ,kBALjCI,CAKoDD,WALpDC,CAAAA,CAAAA;EADtBb,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAA2B,IAAA,UAAA,CAAA,CAAA,EAAA;IAMpDc,CAAAA,GAAAA,EAAAA,MAAa,CAAA,EAAA,MAAAF;EAA0BhB,CAAAA,GAAAA,SAAAA;EAA4DgB,cAAAA,CAAAA,EAK5GH,kBAL4GG,CAKzFA,WALyFA,CAAAA;EAKzFA,eAAAA,EAAAA,OAAAA;EAAnBH,SAAAA,EAAAA,MAAAA;EASDN,KAAAA,EAAAA,MAAAA;EACDO,WAAAA,EAAAA,MAAAA;EACGJ,eAAAA,EAAAA,MAAAA;EACwBM,IAAAA,EAAAA,MAAAA;EAApBD,IAAAA,EAAAA,MAAAA;EAC4BC,aAAAA,EAAAA,MAAAA,EAAAA;EAApBD,cAAAA,EAJdR,qBA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,MAAA,WAAiB,sBAAA;EAInC,WAAA,CAAY,MAAA,GAAS,oBAAA,CAAqB,WAAA;EAI1C,WAAA,CACE,MAAA,GAAS,oBAAA,CAAqB,WAAA,IAC7B,sBAAA;EASH,eAAA,CACE,MAAA,EAAQ,kBAAA,CAAmB,WAAA,GAC3B,MAAA,EAAQ,sBAAA;EAAA,IAiBN,QAAA,CAAA,GAAY,kBAAA;EAKhB,QAAA,CAAA;EAIA,YAAA,CAAa,MAAA,WAAiB,cAAA;EArEZ;;;;;;EA+EZ,KAAA,CACJ,MAAA,UACA,OAAA,8BACC,OAAA;EAUI,eAAA,CACL,KAAA,EAAO,sBAAA,EACP,OAAA,GAAU,4BAAA,GACT,cAAA;EAyDG,eAAA,CACJ,QAAA,EAAU,WAAA,IACV,OAAA,cAAqB,4BAAA,EACrB,UAAA,GAAa,SAAA,GACZ,OAAA,CAAQ,WAAA;EAxIR;;;;;;EAAA,UAyJO,eAAA,CAAA,GAAmB,cAAA,CAAe,WAAA;EAStC,MAAA,CACJ,KAAA,EAAO,sBAAA,EACP,OAAA,GAAU,4BAAA,GACT,OAAA;AAAA"}
package/dist/llms.js CHANGED
@@ -12,12 +12,10 @@ import { BaseLLM, LLM } from "@langchain/core/language_models/llms";
12
12
  //#region src/llms.ts
13
13
  var GoogleLLMConnection = class extends AbstractGoogleLLMConnection {
14
14
  async formatContents(input, _parameters) {
15
- const parts = await this.api.messageContentToParts(input);
16
- const contents = [{
15
+ return [{
17
16
  role: "user",
18
- parts
17
+ parts: await this.api.messageContentToParts(input)
19
18
  }];
20
- return contents;
21
19
  }
22
20
  };
23
21
  var ProxyChatGoogle = class extends ChatGoogleBase {
@@ -99,8 +97,7 @@ var GoogleBaseLLM = class extends LLM {
99
97
  async _call(prompt, options) {
100
98
  const parameters = copyAIModelParams(this, options);
101
99
  const result = await this.connection.request(prompt, parameters, options);
102
- const ret = this.connection.api.responseToString(result);
103
- return ret;
100
+ return this.connection.api.responseToString(result);
104
101
  }
105
102
  async *_streamIterator(input, options) {
106
103
  const prompt = BaseLLM._convertInputToPromptValue(input);
@@ -130,8 +127,7 @@ var GoogleBaseLLM = class extends LLM {
130
127
  async predictMessages(messages, options, _callbacks) {
131
128
  const { content } = messages[0];
132
129
  const result = await this.connection.request(content, {}, options);
133
- const ret = this.connection.api.responseToBaseMessage(result);
134
- return ret;
130
+ return this.connection.api.responseToBaseMessage(result);
135
131
  }
136
132
  /**
137
133
  * Internal implementation detail to allow Google LLMs to support
package/dist/llms.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llms.js","names":["input: MessageContent","_parameters: GoogleAIModelParams","contents: GeminiContent[]","fields: ProxyChatInput<AuthOptions>","fields?: GoogleBaseLLMInput<AuthOptions>","apiKey: string","fields?: GoogleAIBaseLLMInput<AuthOptions>","fields: GoogleBaseLLMInput<AuthOptions>","client: GoogleAbstractedClient","prompt: string","options: this[\"ParsedCallOptions\"]","input: BaseLanguageModelInput","options?: BaseLanguageModelCallOptions","messages: BaseMessage[]","options?: string[] | BaseLanguageModelCallOptions","_callbacks?: Callbacks"],"sources":["../src/llms.ts"],"sourcesContent":["import { CallbackManager, Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { BaseLLM, LLM } from \"@langchain/core/language_models/llms\";\nimport {\n type BaseLanguageModelCallOptions,\n BaseLanguageModelInput,\n} from \"@langchain/core/language_models/base\";\nimport { BaseMessage, MessageContent } from \"@langchain/core/messages\";\nimport { GenerationChunk } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\n\nimport { AbstractGoogleLLMConnection } from \"./connection.js\";\nimport {\n GoogleAIBaseLLMInput,\n GoogleAIModelParams,\n GoogleAISafetySetting,\n GooglePlatformType,\n GeminiContent,\n GoogleAIResponseMimeType,\n} from \"./types.js\";\nimport {\n copyAIModelParams,\n copyAndValidateModelParamsInto,\n} from \"./utils/common.js\";\nimport { DefaultGeminiSafetyHandler } from \"./utils/gemini.js\";\nimport { ApiKeyGoogleAuth, GoogleAbstractedClient } from \"./auth.js\";\nimport { ensureParams } from \"./utils/failed_handler.js\";\nimport { ChatGoogleBase } from \"./chat_models.js\";\nimport type { GoogleBaseLLMInput, GoogleAISafetyHandler } from \"./types.js\";\n\nexport { GoogleBaseLLMInput };\n\nclass GoogleLLMConnection<AuthOptions> extends AbstractGoogleLLMConnection<\n MessageContent,\n AuthOptions\n> {\n async formatContents(\n input: MessageContent,\n _parameters: GoogleAIModelParams\n ): Promise<GeminiContent[]> {\n const parts = await this.api.messageContentToParts!(input);\n const contents: GeminiContent[] = [\n {\n role: \"user\", // Required by Vertex AI\n parts,\n },\n ];\n return contents;\n }\n}\n\ntype ProxyChatInput<AuthOptions> = GoogleAIBaseLLMInput<AuthOptions> & {\n connection: GoogleLLMConnection<AuthOptions>;\n};\n\nclass ProxyChatGoogle<AuthOptions> extends ChatGoogleBase<AuthOptions> {\n constructor(fields: ProxyChatInput<AuthOptions>) {\n super(fields);\n }\n\n buildAbstractedClient(\n fields: ProxyChatInput<AuthOptions>\n ): GoogleAbstractedClient {\n return fields.connection.client;\n }\n}\n\n/**\n * Integration with an LLM.\n */\nexport abstract class GoogleBaseLLM<AuthOptions>\n extends LLM<BaseLanguageModelCallOptions>\n implements GoogleBaseLLMInput<AuthOptions>\n{\n // Used for tracing, replace with the same name as your class\n static lc_name() {\n return \"GoogleLLM\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n authOptions: \"GOOGLE_AUTH_OPTIONS\",\n };\n }\n\n originalFields?: GoogleBaseLLMInput<AuthOptions>;\n\n lc_serializable = true;\n\n modelName = \"gemini-pro\";\n\n model = \"gemini-pro\";\n\n temperature = 0.7;\n\n maxOutputTokens = 1024;\n\n topP = 0.8;\n\n topK = 40;\n\n stopSequences: string[] = [];\n\n safetySettings: GoogleAISafetySetting[] = [];\n\n safetyHandler: GoogleAISafetyHandler;\n\n responseMimeType: GoogleAIResponseMimeType = \"text/plain\";\n\n protected connection: GoogleLLMConnection<AuthOptions>;\n\n protected streamedConnection: GoogleLLMConnection<AuthOptions>;\n\n constructor(fields?: GoogleBaseLLMInput<AuthOptions>) {\n super(ensureParams(fields));\n this.originalFields = fields;\n\n copyAndValidateModelParamsInto(fields, this);\n this.safetyHandler =\n fields?.safetyHandler ?? new DefaultGeminiSafetyHandler();\n\n const client = this.buildClient(fields);\n this.buildConnection(fields ?? {}, client);\n }\n\n abstract buildAbstractedClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient;\n\n buildApiKeyClient(apiKey: string): GoogleAbstractedClient {\n return new ApiKeyGoogleAuth(apiKey);\n }\n\n buildApiKey(fields?: GoogleAIBaseLLMInput<AuthOptions>): string | undefined {\n return fields?.apiKey ?? getEnvironmentVariable(\"GOOGLE_API_KEY\");\n }\n\n buildClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient {\n const apiKey = this.buildApiKey(fields);\n if (apiKey) {\n return this.buildApiKeyClient(apiKey);\n } else {\n return this.buildAbstractedClient(fields);\n }\n }\n\n buildConnection(\n fields: GoogleBaseLLMInput<AuthOptions>,\n client: GoogleAbstractedClient\n ) {\n this.connection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n false\n );\n\n this.streamedConnection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n true\n );\n }\n\n get platform(): GooglePlatformType {\n return this.connection.platform;\n }\n\n // Replace\n _llmType() {\n return \"googlellm\";\n }\n\n formatPrompt(prompt: string): MessageContent {\n return prompt;\n }\n\n /**\n * For some given input string and options, return a string output.\n *\n * Despite the fact that `invoke` is overridden below, we still need this\n * in order to handle public APi calls to `generate()`.\n */\n async _call(\n prompt: string,\n options: this[\"ParsedCallOptions\"]\n ): Promise<string> {\n const parameters = copyAIModelParams(this, options);\n const result = await this.connection.request(prompt, parameters, options);\n const ret = this.connection.api.responseToString(result);\n return ret;\n }\n\n // Normally, you should not override this method and instead should override\n // _streamResponseChunks. We are doing so here to allow for multimodal inputs into\n // the LLM.\n async *_streamIterator(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): AsyncGenerator<string> {\n // TODO: Refactor callback setup and teardown code into core\n const prompt = BaseLLM._convertInputToPromptValue(input);\n const [runnableConfig, callOptions] =\n this._separateRunnableConfigFromCallOptions(options);\n const callbackManager_ = await CallbackManager.configure(\n runnableConfig.callbacks,\n this.callbacks,\n runnableConfig.tags,\n this.tags,\n runnableConfig.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const extra = {\n options: callOptions,\n invocation_params: this?.invocationParams(callOptions),\n batch_size: 1,\n };\n const runManagers = await callbackManager_?.handleLLMStart(\n this.toJSON(),\n [prompt.toString()],\n undefined,\n undefined,\n extra,\n undefined,\n undefined,\n runnableConfig.runName\n );\n let generation = new GenerationChunk({\n text: \"\",\n });\n const proxyChat = this.createProxyChat();\n try {\n for await (const chunk of proxyChat._streamIterator(input, options)) {\n const stringValue = this.connection.api.chunkToString(chunk);\n const generationChunk = new GenerationChunk({\n text: stringValue,\n });\n generation = generation.concat(generationChunk);\n yield stringValue;\n }\n } catch (err) {\n await Promise.all(\n (runManagers ?? []).map((runManager) => runManager?.handleLLMError(err))\n );\n throw err;\n }\n await Promise.all(\n (runManagers ?? []).map((runManager) =>\n runManager?.handleLLMEnd({\n generations: [[generation]],\n })\n )\n );\n }\n\n async predictMessages(\n messages: BaseMessage[],\n options?: string[] | BaseLanguageModelCallOptions,\n _callbacks?: Callbacks\n ): Promise<BaseMessage> {\n const { content } = messages[0];\n const result = await this.connection.request(\n content,\n {},\n options as BaseLanguageModelCallOptions\n );\n const ret = this.connection.api.responseToBaseMessage(result);\n return ret;\n }\n\n /**\n * Internal implementation detail to allow Google LLMs to support\n * multimodal input by delegating to the chat model implementation.\n *\n * TODO: Replace with something less hacky.\n */\n protected createProxyChat(): ChatGoogleBase<AuthOptions> {\n return new ProxyChatGoogle<AuthOptions>({\n ...this.originalFields,\n connection: this.connection,\n });\n }\n\n // TODO: Remove the need to override this - we are doing it to\n // allow the LLM to handle multimodal types of input.\n async invoke(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): Promise<string> {\n const stream = await this._streamIterator(input, options);\n let generatedOutput = \"\";\n for await (const chunk of stream) {\n generatedOutput += chunk;\n }\n return generatedOutput;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,IAAM,sBAAN,cAA+C,4BAG7C;CACA,MAAM,eACJA,OACAC,aAC0B;EAC1B,MAAM,QAAQ,MAAM,KAAK,IAAI,sBAAuB,MAAM;EAC1D,MAAMC,WAA4B,CAChC;GACE,MAAM;GACN;EACD,CACF;AACD,SAAO;CACR;AACF;AAMD,IAAM,kBAAN,cAA2C,eAA4B;CACrE,YAAYC,QAAqC;EAC/C,MAAM,OAAO;CACd;CAED,sBACEA,QACwB;AACxB,SAAO,OAAO,WAAW;CAC1B;AACF;;;;AAKD,IAAsB,gBAAtB,cACU,IAEV;CAEE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,aAAoD;AACtD,SAAO,EACL,aAAa,sBACd;CACF;CAED;CAEA,kBAAkB;CAElB,YAAY;CAEZ,QAAQ;CAER,cAAc;CAEd,kBAAkB;CAElB,OAAO;CAEP,OAAO;CAEP,gBAA0B,CAAE;CAE5B,iBAA0C,CAAE;CAE5C;CAEA,mBAA6C;CAE7C,AAAU;CAEV,AAAU;CAEV,YAAYC,QAA0C;EACpD,MAAM,aAAa,OAAO,CAAC;EAC3B,KAAK,iBAAiB;EAEtB,+BAA+B,QAAQ,KAAK;EAC5C,KAAK,gBACH,QAAQ,iBAAiB,IAAI;EAE/B,MAAM,SAAS,KAAK,YAAY,OAAO;EACvC,KAAK,gBAAgB,UAAU,CAAE,GAAE,OAAO;CAC3C;CAMD,kBAAkBC,QAAwC;AACxD,SAAO,IAAI,iBAAiB;CAC7B;CAED,YAAYC,QAAgE;AAC1E,SAAO,QAAQ,UAAU,uBAAuB,iBAAiB;CAClE;CAED,YACEA,Q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UAAU,gBAAgB,OAAO,QAAQ,EAAE;IACnE,MAAM,cAAc,KAAK,WAAW,IAAI,cAAc,MAAM;IAC5D,MAAM,kBAAkB,IAAI,gBAAgB,EAC1C,MAAM,YACP;IACD,aAAa,WAAW,OAAO,gBAAgB;IAC/C,MAAM;GACP;EACF,SAAQ,KAAK;GACZ,MAAM,QAAQ,KACX,eAAe,CAAE,GAAE,IAAI,CAAC,eAAe,YAAY,eAAe,IAAI,CAAC,CACzE;AACD,SAAM;EACP;EACD,MAAM,QAAQ,KACX,eAAe,CAAE,GAAE,IAAI,CAAC,eACvB,YAAY,aAAa,EACvB,aAAa,CAAC,CAAC,UAAW,CAAC,EAC5B,EAAC,CACH,CACF;CACF;CAED,MAAM,gBACJC,UACAC,SACAC,YACsB;EACtB,MAAM,EAAE,SAAS,GAAG,SAAS;EAC7B,MAAM,SAAS,MAAM,KAAK,WAAW,QACnC,SACA,CAAE,GACF,QACD;EACD,MAAM,MAAM,KAAK,WAAW,IAAI,sBAAsB,OAAO;AAC7D,SAAO;CACR;;;;;;;CAQD,AAAU,kBAA+C;AACvD,SAAO,IAAI,gBAA6B;GACtC,GAAG,KAAK;GACR,YAAY,KAAK;EAClB;CACF;CAID,MAAM,OACJJ,OACAC,SACiB;EACjB,MAAM,SAAS,MAAM,KAAK,gBAAgB,OAAO,QAAQ;EACzD,IAAI,kBAAkB;AACtB,aAAW,MAAM,SAAS,QACxB,mBAAmB;AAErB,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"llms.js","names":[],"sources":["../src/llms.ts"],"sourcesContent":["import { CallbackManager, Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { BaseLLM, LLM } from \"@langchain/core/language_models/llms\";\nimport {\n type BaseLanguageModelCallOptions,\n BaseLanguageModelInput,\n} from \"@langchain/core/language_models/base\";\nimport { BaseMessage, MessageContent } from \"@langchain/core/messages\";\nimport { GenerationChunk } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\n\nimport { AbstractGoogleLLMConnection } from \"./connection.js\";\nimport {\n GoogleAIBaseLLMInput,\n GoogleAIModelParams,\n GoogleAISafetySetting,\n GooglePlatformType,\n GeminiContent,\n GoogleAIResponseMimeType,\n} from \"./types.js\";\nimport {\n copyAIModelParams,\n copyAndValidateModelParamsInto,\n} from \"./utils/common.js\";\nimport { DefaultGeminiSafetyHandler } from \"./utils/gemini.js\";\nimport { ApiKeyGoogleAuth, GoogleAbstractedClient } from \"./auth.js\";\nimport { ensureParams } from \"./utils/failed_handler.js\";\nimport { ChatGoogleBase } from \"./chat_models.js\";\nimport type { GoogleBaseLLMInput, GoogleAISafetyHandler } from \"./types.js\";\n\nexport { GoogleBaseLLMInput };\n\nclass GoogleLLMConnection<AuthOptions> extends AbstractGoogleLLMConnection<\n MessageContent,\n AuthOptions\n> {\n async formatContents(\n input: MessageContent,\n _parameters: GoogleAIModelParams\n ): Promise<GeminiContent[]> {\n const parts = await this.api.messageContentToParts!(input);\n const contents: GeminiContent[] = [\n {\n role: \"user\", // Required by Vertex AI\n parts,\n },\n ];\n return contents;\n }\n}\n\ntype ProxyChatInput<AuthOptions> = GoogleAIBaseLLMInput<AuthOptions> & {\n connection: GoogleLLMConnection<AuthOptions>;\n};\n\nclass ProxyChatGoogle<AuthOptions> extends ChatGoogleBase<AuthOptions> {\n constructor(fields: ProxyChatInput<AuthOptions>) {\n super(fields);\n }\n\n buildAbstractedClient(\n fields: ProxyChatInput<AuthOptions>\n ): GoogleAbstractedClient {\n return fields.connection.client;\n }\n}\n\n/**\n * Integration with an LLM.\n */\nexport abstract class GoogleBaseLLM<AuthOptions>\n extends LLM<BaseLanguageModelCallOptions>\n implements GoogleBaseLLMInput<AuthOptions>\n{\n // Used for tracing, replace with the same name as your class\n static lc_name() {\n return \"GoogleLLM\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n authOptions: \"GOOGLE_AUTH_OPTIONS\",\n };\n }\n\n originalFields?: GoogleBaseLLMInput<AuthOptions>;\n\n lc_serializable = true;\n\n modelName = \"gemini-pro\";\n\n model = \"gemini-pro\";\n\n temperature = 0.7;\n\n maxOutputTokens = 1024;\n\n topP = 0.8;\n\n topK = 40;\n\n stopSequences: string[] = [];\n\n safetySettings: GoogleAISafetySetting[] = [];\n\n safetyHandler: GoogleAISafetyHandler;\n\n responseMimeType: GoogleAIResponseMimeType = \"text/plain\";\n\n protected connection: GoogleLLMConnection<AuthOptions>;\n\n protected streamedConnection: GoogleLLMConnection<AuthOptions>;\n\n constructor(fields?: GoogleBaseLLMInput<AuthOptions>) {\n super(ensureParams(fields));\n this.originalFields = fields;\n\n copyAndValidateModelParamsInto(fields, this);\n this.safetyHandler =\n fields?.safetyHandler ?? new DefaultGeminiSafetyHandler();\n\n const client = this.buildClient(fields);\n this.buildConnection(fields ?? {}, client);\n }\n\n abstract buildAbstractedClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient;\n\n buildApiKeyClient(apiKey: string): GoogleAbstractedClient {\n return new ApiKeyGoogleAuth(apiKey);\n }\n\n buildApiKey(fields?: GoogleAIBaseLLMInput<AuthOptions>): string | undefined {\n return fields?.apiKey ?? getEnvironmentVariable(\"GOOGLE_API_KEY\");\n }\n\n buildClient(\n fields?: GoogleAIBaseLLMInput<AuthOptions>\n ): GoogleAbstractedClient {\n const apiKey = this.buildApiKey(fields);\n if (apiKey) {\n return this.buildApiKeyClient(apiKey);\n } else {\n return this.buildAbstractedClient(fields);\n }\n }\n\n buildConnection(\n fields: GoogleBaseLLMInput<AuthOptions>,\n client: GoogleAbstractedClient\n ) {\n this.connection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n false\n );\n\n this.streamedConnection = new GoogleLLMConnection(\n { ...fields, ...this },\n this.caller,\n client,\n true\n );\n }\n\n get platform(): GooglePlatformType {\n return this.connection.platform;\n }\n\n // Replace\n _llmType() {\n return \"googlellm\";\n }\n\n formatPrompt(prompt: string): MessageContent {\n return prompt;\n }\n\n /**\n * For some given input string and options, return a string output.\n *\n * Despite the fact that `invoke` is overridden below, we still need this\n * in order to handle public APi calls to `generate()`.\n */\n async _call(\n prompt: string,\n options: this[\"ParsedCallOptions\"]\n ): Promise<string> {\n const parameters = copyAIModelParams(this, options);\n const result = await this.connection.request(prompt, parameters, options);\n const ret = this.connection.api.responseToString(result);\n return ret;\n }\n\n // Normally, you should not override this method and instead should override\n // _streamResponseChunks. We are doing so here to allow for multimodal inputs into\n // the LLM.\n async *_streamIterator(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): AsyncGenerator<string> {\n // TODO: Refactor callback setup and teardown code into core\n const prompt = BaseLLM._convertInputToPromptValue(input);\n const [runnableConfig, callOptions] =\n this._separateRunnableConfigFromCallOptions(options);\n const callbackManager_ = await CallbackManager.configure(\n runnableConfig.callbacks,\n this.callbacks,\n runnableConfig.tags,\n this.tags,\n runnableConfig.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const extra = {\n options: callOptions,\n invocation_params: this?.invocationParams(callOptions),\n batch_size: 1,\n };\n const runManagers = await callbackManager_?.handleLLMStart(\n this.toJSON(),\n [prompt.toString()],\n undefined,\n undefined,\n extra,\n undefined,\n undefined,\n runnableConfig.runName\n );\n let generation = new GenerationChunk({\n text: \"\",\n });\n const proxyChat = this.createProxyChat();\n try {\n for await (const chunk of proxyChat._streamIterator(input, options)) {\n const stringValue = this.connection.api.chunkToString(chunk);\n const generationChunk = new GenerationChunk({\n text: stringValue,\n });\n generation = generation.concat(generationChunk);\n yield stringValue;\n }\n } catch (err) {\n await Promise.all(\n (runManagers ?? []).map((runManager) => runManager?.handleLLMError(err))\n );\n throw err;\n }\n await Promise.all(\n (runManagers ?? []).map((runManager) =>\n runManager?.handleLLMEnd({\n generations: [[generation]],\n })\n )\n );\n }\n\n async predictMessages(\n messages: BaseMessage[],\n options?: string[] | BaseLanguageModelCallOptions,\n _callbacks?: Callbacks\n ): Promise<BaseMessage> {\n const { content } = messages[0];\n const result = await this.connection.request(\n content,\n {},\n options as BaseLanguageModelCallOptions\n );\n const ret = this.connection.api.responseToBaseMessage(result);\n return ret;\n }\n\n /**\n * Internal implementation detail to allow Google LLMs to support\n * multimodal input by delegating to the chat model implementation.\n *\n * TODO: Replace with something less hacky.\n */\n protected createProxyChat(): ChatGoogleBase<AuthOptions> {\n return new ProxyChatGoogle<AuthOptions>({\n ...this.originalFields,\n connection: this.connection,\n });\n }\n\n // TODO: Remove the need to override this - we are doing it to\n // allow the LLM to handle multimodal types of input.\n async invoke(\n input: BaseLanguageModelInput,\n options?: BaseLanguageModelCallOptions\n ): Promise<string> {\n const stream = await this._streamIterator(input, options);\n let generatedOutput = \"\";\n for await (const chunk of stream) {\n generatedOutput += chunk;\n }\n return generatedOutput;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,IAAM,sBAAN,cAA+C,4BAG7C;CACA,MAAM,eACJ,OACA,aAC0B;AAQ1B,SANkC,CAChC;GACE,MAAM;GACN,OAJU,MAAM,KAAK,IAAI,sBAAuB,MAAM;GAKvD,CACF;;;AASL,IAAM,kBAAN,cAA2C,eAA4B;CACrE,YAAY,QAAqC;AAC/C,QAAM,OAAO;;CAGf,sBACE,QACwB;AACxB,SAAO,OAAO,WAAW;;;;;;AAO7B,IAAsB,gBAAtB,cACU,IAEV;CAEE,OAAO,UAAU;AACf,SAAO;;CAGT,IAAI,aAAoD;AACtD,SAAO,EACL,aAAa,uBACd;;CAGH;CAEA,kBAAkB;CAElB,YAAY;CAEZ,QAAQ;CAER,cAAc;CAEd,kBAAkB;CAElB,OAAO;CAEP,OAAO;CAEP,gBAA0B,EAAE;CAE5B,iBAA0C,EAAE;CAE5C;CAEA,mBAA6C;CAE7C,AAAU;CAEV,AAAU;CAEV,YAAY,QAA0C;AACpD,QAAM,aAAa,OAAO,CAAC;AAC3B,OAAK,iBAAiB;AAEtB,iCAA+B,QAAQ,KAAK;AAC5C,OAAK,gBACH,QAAQ,iBAAiB,IAAI,4BAA4B;EAE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O,UAAU,CAAC,EACnB,QACA,QACA,OACA,QACA,QACA,eAAe,QAChB;EACD,IAAI,aAAa,IAAI,gBAAgB,EACnC,MAAM,IACP,CAAC;EACF,MAAM,YAAY,KAAK,iBAAiB;AACxC,MAAI;AACF,cAAW,MAAM,SAAS,UAAU,gBAAgB,OAAO,QAAQ,EAAE;IACnE,MAAM,cAAc,KAAK,WAAW,IAAI,cAAc,MAAM;IAC5D,MAAM,kBAAkB,IAAI,gBAAgB,EAC1C,MAAM,aACP,CAAC;AACF,iBAAa,WAAW,OAAO,gBAAgB;AAC/C,UAAM;;WAED,KAAK;AACZ,SAAM,QAAQ,KACX,eAAe,EAAE,EAAE,KAAK,eAAe,YAAY,eAAe,IAAI,CAAC,CACzE;AACD,SAAM;;AAER,QAAM,QAAQ,KACX,eAAe,EAAE,EAAE,KAAK,eACvB,YAAY,aAAa,EACvB,aAAa,CAAC,CAAC,WAAW,CAAC,EAC5B,CAAC,CACH,CACF;;CAGH,MAAM,gBACJ,UACA,SACA,YACsB;EACtB,MAAM,EAAE,YAAY,SAAS;EAC7B,MAAM,SAAS,MAAM,KAAK,WAAW,QACnC,SACA,EAAE,EACF,QACD;AAED,SADY,KAAK,WAAW,IAAI,sBAAsB,OAAO;;;;;;;;CAU/D,AAAU,kBAA+C;AACvD,SAAO,IAAI,gBAA6B;GACtC,GAAG,KAAK;GACR,YAAY,KAAK;GAClB,CAAC;;CAKJ,MAAM,OACJ,OACA,SACiB;EACjB,MAAM,SAAS,MAAM,KAAK,gBAAgB,OAAO,QAAQ;EACzD,IAAI,kBAAkB;AACtB,aAAW,MAAM,SAAS,OACxB,oBAAmB;AAErB,SAAO"}
@@ -1,8 +1,7 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- const __langchain_core_output_parsers = require_rolldown_runtime.__toESM(require("@langchain/core/output_parsers"));
1
+ let _langchain_core_output_parsers = require("@langchain/core/output_parsers");
3
2
 
4
3
  //#region src/output_parsers.ts
5
- var BaseGoogleSearchOutputParser = class extends __langchain_core_output_parsers.BaseLLMOutputParser {
4
+ var BaseGoogleSearchOutputParser = class extends _langchain_core_output_parsers.BaseLLMOutputParser {
6
5
  lc_namespace = ["google_common", "output_parsers"];
7
6
  generationToGroundingInfo(generation) {
8
7
  if ("message" in generation) {
@@ -14,14 +13,12 @@ var BaseGoogleSearchOutputParser = class extends __langchain_core_output_parsers
14
13
  supports
15
14
  };
16
15
  }
17
- return void 0;
18
16
  }
19
17
  generationsToGroundingInfo(generations) {
20
18
  for (const generation of generations) {
21
19
  const info = this.generationToGroundingInfo(generation);
22
20
  if (info !== void 0) return info;
23
21
  }
24
- return void 0;
25
22
  }
26
23
  generationToString(generation) {
27
24
  if ("message" in generation) {
@@ -43,9 +40,7 @@ var BaseGoogleSearchOutputParser = class extends __langchain_core_output_parsers
43
40
  const textBefore = text.substring(0, start);
44
41
  const textSegment = text.substring(start, end);
45
42
  const textAfter = text.substring(end);
46
- const textPrefix = this.segmentPrefix(grounding, support, index) ?? "";
47
- const textSuffix = this.segmentSuffix(grounding, support, index) ?? "";
48
- return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;
43
+ return `${textBefore}${this.segmentPrefix(grounding, support, index) ?? ""}${textSegment}${this.segmentSuffix(grounding, support, index) ?? ""}${textAfter}`;
49
44
  }
50
45
  annotateTextSegments(text, grounding) {
51
46
  let ret = text;
@@ -69,8 +64,7 @@ var BaseGoogleSearchOutputParser = class extends __langchain_core_output_parsers
69
64
  annotateText(text, grounding) {
70
65
  const prefix = this.textPrefix(text, grounding) ?? "";
71
66
  const suffix = this.textSuffix(text, grounding) ?? "";
72
- const body = this.annotateTextSegments(text, grounding);
73
- return `${prefix}${body}${suffix}`;
67
+ return `${prefix}${this.annotateTextSegments(text, grounding)}${suffix}`;
74
68
  }
75
69
  async parseResult(generations, _callbacks) {
76
70
  const text = this.generationsToString(generations);
@@ -80,12 +74,9 @@ var BaseGoogleSearchOutputParser = class extends __langchain_core_output_parsers
80
74
  }
81
75
  };
82
76
  var SimpleGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
83
- segmentPrefix(_grounding, _support, _index) {
84
- return void 0;
85
- }
77
+ segmentPrefix(_grounding, _support, _index) {}
86
78
  segmentSuffix(_grounding, support, _index) {
87
- const indices = support.groundingChunkIndices.map((i) => i + 1);
88
- return ` [${indices.join(", ")}]`;
79
+ return ` [${support.groundingChunkIndices.map((i) => i + 1).join(", ")}]`;
89
80
  }
90
81
  textPrefix(_text, _grounding) {
91
82
  return "Google Says:\n";
@@ -96,22 +87,18 @@ var SimpleGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser
96
87
  }
97
88
  textSuffix(_text, grounding) {
98
89
  let ret = "\n";
99
- const chunks = grounding?.metadata?.groundingChunks ?? [];
100
- chunks.forEach((chunk, index) => {
90
+ (grounding?.metadata?.groundingChunks ?? []).forEach((chunk, index) => {
101
91
  ret = `${ret}${this.chunkToString(chunk, index)}\n`;
102
92
  });
103
93
  return ret;
104
94
  }
105
95
  };
106
96
  var MarkdownGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
107
- segmentPrefix(_grounding, _support, _index) {
108
- return void 0;
109
- }
97
+ segmentPrefix(_grounding, _support, _index) {}
110
98
  chunkLink(grounding, index) {
111
99
  const chunk = grounding.metadata.groundingChunks[index];
112
100
  const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;
113
- const num = index + 1;
114
- return `[[${num}](${url})]`;
101
+ return `[[${index + 1}](${url})]`;
115
102
  }
116
103
  segmentSuffix(grounding, support, _index) {
117
104
  let ret = "";
@@ -121,20 +108,16 @@ var MarkdownGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParse
121
108
  });
122
109
  return ret;
123
110
  }
124
- textPrefix(_text, _grounding) {
125
- return void 0;
126
- }
111
+ textPrefix(_text, _grounding) {}
127
112
  chunkSuffixLink(chunk, index) {
128
113
  const num = index + 1;
129
114
  const info = chunk.retrievedContext ?? chunk.web;
130
115
  const url = info.uri;
131
- const site = info.title;
132
- return `${num}. [${site}](${url})`;
116
+ return `${num}. [${info.title}](${url})`;
133
117
  }
134
118
  textSuffix(_text, grounding) {
135
119
  let ret = "\n**Search Sources**\n";
136
- const chunks = grounding.metadata.groundingChunks;
137
- chunks.forEach((chunk, index) => {
120
+ grounding.metadata.groundingChunks.forEach((chunk, index) => {
138
121
  ret = `${ret}${this.chunkSuffixLink(chunk, index)}\n`;
139
122
  });
140
123
  const search = this.searchSuggestion(grounding);
@@ -1 +1 @@
1
- {"version":3,"file":"output_parsers.cjs","names":["BaseLLMOutputParser","generation: Generation | ChatGeneration","generations: Generations","content: MessageContent","text: string","grounding: GroundingInfo","support: GeminiGroundingSupport","index: number","_callbacks?: Callbacks","_grounding: GroundingInfo","_support: GeminiGroundingSupport","_index: number","indices: number[]","_text: string","chunk: GeminiGroundingChunk","chunks: GeminiGroundingChunk[]"],"sources":["../src/output_parsers.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { MessageContent } from \"@langchain/core/messages\";\nimport {\n GeminiGroundingChunk,\n GeminiGroundingMetadata,\n GeminiGroundingSupport,\n} from \"./types.js\";\n\ntype Generations = Generation[] | ChatGeneration[];\n\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\n\nexport abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[] = [\"google_common\", \"output_parsers\"];\n\n protected generationToGroundingInfo(\n generation: Generation | ChatGeneration\n ): GroundingInfo | undefined {\n if (\"message\" in generation) {\n const responseMetadata = generation?.message?.response_metadata;\n const metadata = responseMetadata?.groundingMetadata;\n const supports =\n responseMetadata?.groundingSupport ?? metadata?.groundingSupports ?? [];\n if (metadata) {\n return {\n metadata,\n supports,\n };\n }\n }\n return undefined;\n }\n\n protected generationsToGroundingInfo(\n generations: Generations\n ): GroundingInfo | undefined {\n for (const generation of generations) {\n const info = this.generationToGroundingInfo(generation);\n if (info !== undefined) {\n return info;\n }\n }\n return undefined;\n }\n\n protected generationToString(\n generation: Generation | ChatGeneration\n ): string {\n if (\"message\" in generation) {\n const content: MessageContent = generation?.message?.content;\n if (typeof content === \"string\") {\n return content;\n } else {\n return content\n .map((c) => {\n if (c?.type === \"text\") {\n return c?.text ?? \"\";\n } else {\n return \"\";\n }\n })\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n }\n return generation.text;\n }\n\n protected generationsToString(generations: Generations): string {\n return generations\n .map((generation) => this.generationToString(generation))\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n\n protected abstract segmentPrefix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected abstract segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected annotateSegment(\n text: string,\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string {\n const start = support.segment.startIndex ?? 0;\n const end = support.segment.endIndex;\n\n const textBefore = text.substring(0, start);\n const textSegment = text.substring(start, end);\n const textAfter = text.substring(end);\n\n const textPrefix = this.segmentPrefix(grounding, support, index) ?? \"\";\n const textSuffix = this.segmentSuffix(grounding, support, index) ?? \"\";\n\n return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;\n }\n\n protected annotateTextSegments(\n text: string,\n grounding: GroundingInfo\n ): string {\n // Go through each support info in reverse, since the segment info\n // is sorted, and we won't need to adjust string indexes this way.\n let ret = text;\n for (let co = grounding.supports.length - 1; co >= 0; co -= 1) {\n const support = grounding.supports[co];\n ret = this.annotateSegment(ret, grounding, support, co);\n }\n return ret;\n }\n\n protected abstract textPrefix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n protected abstract textSuffix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string {\n return grounding?.metadata?.searchEntryPoint?.renderedContent ?? \"\";\n }\n\n protected annotateText(text: string, grounding: GroundingInfo): string {\n const prefix = this.textPrefix(text, grounding) ?? \"\";\n const suffix = this.textSuffix(text, grounding) ?? \"\";\n const body = this.annotateTextSegments(text, grounding);\n return `${prefix}${body}${suffix}`;\n }\n\n async parseResult(\n generations: Generations,\n _callbacks?: Callbacks\n ): Promise<string> {\n const text = this.generationsToString(generations);\n\n const grounding = this.generationsToGroundingInfo(generations);\n if (!grounding) {\n return text;\n }\n\n return this.annotateText(text, grounding);\n }\n}\n\nexport class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected segmentSuffix(\n _grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n const indices: number[] = support.groundingChunkIndices.map((i) => i + 1);\n return ` [${indices.join(\", \")}]`;\n }\n\n protected textPrefix(_text: string, _grounding: GroundingInfo): string {\n return \"Google Says:\\n\";\n }\n\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string {\n const info = chunk.retrievedContext ?? chunk.web;\n return `${index + 1}. ${info.title} - ${info.uri}`;\n }\n\n protected textSuffix(_text: string, grounding: GroundingInfo): string {\n let ret = \"\\n\";\n const chunks: GeminiGroundingChunk[] =\n grounding?.metadata?.groundingChunks ?? [];\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkToString(chunk, index)}\\n`;\n });\n return ret;\n }\n}\n\nexport class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected chunkLink(grounding: GroundingInfo, index: number): string {\n const chunk = grounding.metadata.groundingChunks[index];\n const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;\n const num = index + 1;\n return `[[${num}](${url})]`;\n }\n\n protected segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n let ret = \"\";\n support.groundingChunkIndices.forEach((chunkIndex) => {\n const link = this.chunkLink(grounding, chunkIndex);\n ret = `${ret}${link}`;\n });\n return ret;\n }\n\n protected textPrefix(\n _text: string,\n _grounding: GroundingInfo\n ): string | undefined {\n return undefined;\n }\n\n protected chunkSuffixLink(\n chunk: GeminiGroundingChunk,\n index: number\n ): string {\n const num = index + 1;\n const info = chunk.retrievedContext ?? chunk.web;\n const url = info.uri;\n const site = info.title;\n return `${num}. [${site}](${url})`;\n }\n\n protected textSuffix(\n _text: string,\n grounding: GroundingInfo\n ): string | undefined {\n let ret = \"\\n**Search Sources**\\n\";\n const chunks: GeminiGroundingChunk[] = grounding.metadata.groundingChunks;\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkSuffixLink(chunk, index)}\\n`;\n });\n\n const search = this.searchSuggestion(grounding);\n ret = `${ret}\\n${search}`;\n\n return ret;\n }\n}\n"],"mappings":";;;;AAiBA,IAAsB,+BAAtB,cAA2DA,oDAA4B;CACrF,eAAyB,CAAC,iBAAiB,gBAAiB;CAE5D,AAAU,0BACRC,YAC2B;AAC3B,MAAI,aAAa,YAAY;GAC3B,MAAM,mBAAmB,YAAY,SAAS;GAC9C,MAAM,WAAW,kBAAkB;GACnC,MAAM,WACJ,kBAAkB,oBAAoB,UAAU,qBAAqB,CAAE;AACzE,OAAI,SACF,QAAO;IACL;IACA;GACD;EAEJ;AACD,SAAO;CACR;CAED,AAAU,2BACRC,aAC2B;AAC3B,OAAK,MAAM,cAAc,aAAa;GACpC,MAAM,OAAO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A0BE,OAAuB;EACnE,MAAM,QAAQ,UAAU,SAAS,gBAAgB;EACjD,MAAM,MAAM,MAAM,kBAAkB,OAAO,MAAM,KAAK;EACtD,MAAM,MAAM,QAAQ;AACpB,SAAO,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC;CAC5B;CAED,AAAU,cACRF,WACAC,SACAK,QACoB;EACpB,IAAI,MAAM;EACV,QAAQ,sBAAsB,QAAQ,CAAC,eAAe;GACpD,MAAM,OAAO,KAAK,UAAU,WAAW,WAAW;GAClD,MAAM,GAAG,MAAM,MAAM;EACtB,EAAC;AACF,SAAO;CACR;CAED,AAAU,WACRE,OACAJ,YACoB;AACpB,SAAO;CACR;CAED,AAAU,gBACRK,OACAP,OACQ;EACR,MAAM,MAAM,QAAQ;EACpB,MAAM,OAAO,MAAM,oBAAoB,MAAM;EAC7C,MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,KAAK;AAClB,SAAO,GAAG,IAAI,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;CACnC;CAED,AAAU,WACRM,OACAR,WACoB;EACpB,IAAI,MAAM;EACV,MAAMU,SAAiC,UAAU,SAAS;EAC1D,OAAO,QAAQ,CAAC,OAAO,UAAU;GAC/B,MAAM,GAAG,MAAM,KAAK,gBAAgB,OAAO,MAAM,CAAC,EAAE,CAAC;EACtD,EAAC;EAEF,MAAM,SAAS,KAAK,iBAAiB,UAAU;EAC/C,MAAM,GAAG,IAAI,EAAE,EAAE,QAAQ;AAEzB,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"output_parsers.cjs","names":["BaseLLMOutputParser"],"sources":["../src/output_parsers.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { MessageContent } from \"@langchain/core/messages\";\nimport {\n GeminiGroundingChunk,\n GeminiGroundingMetadata,\n GeminiGroundingSupport,\n} from \"./types.js\";\n\ntype Generations = Generation[] | ChatGeneration[];\n\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\n\nexport abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[] = [\"google_common\", \"output_parsers\"];\n\n protected generationToGroundingInfo(\n generation: Generation | ChatGeneration\n ): GroundingInfo | undefined {\n if (\"message\" in generation) {\n const responseMetadata = generation?.message?.response_metadata;\n const metadata = responseMetadata?.groundingMetadata;\n const supports =\n responseMetadata?.groundingSupport ?? metadata?.groundingSupports ?? [];\n if (metadata) {\n return {\n metadata,\n supports,\n };\n }\n }\n return undefined;\n }\n\n protected generationsToGroundingInfo(\n generations: Generations\n ): GroundingInfo | undefined {\n for (const generation of generations) {\n const info = this.generationToGroundingInfo(generation);\n if (info !== undefined) {\n return info;\n }\n }\n return undefined;\n }\n\n protected generationToString(\n generation: Generation | ChatGeneration\n ): string {\n if (\"message\" in generation) {\n const content: MessageContent = generation?.message?.content;\n if (typeof content === \"string\") {\n return content;\n } else {\n return content\n .map((c) => {\n if (c?.type === \"text\") {\n return c?.text ?? \"\";\n } else {\n return \"\";\n }\n })\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n }\n return generation.text;\n }\n\n protected generationsToString(generations: Generations): string {\n return generations\n .map((generation) => this.generationToString(generation))\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n\n protected abstract segmentPrefix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected abstract segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected annotateSegment(\n text: string,\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string {\n const start = support.segment.startIndex ?? 0;\n const end = support.segment.endIndex;\n\n const textBefore = text.substring(0, start);\n const textSegment = text.substring(start, end);\n const textAfter = text.substring(end);\n\n const textPrefix = this.segmentPrefix(grounding, support, index) ?? \"\";\n const textSuffix = this.segmentSuffix(grounding, support, index) ?? \"\";\n\n return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;\n }\n\n protected annotateTextSegments(\n text: string,\n grounding: GroundingInfo\n ): string {\n // Go through each support info in reverse, since the segment info\n // is sorted, and we won't need to adjust string indexes this way.\n let ret = text;\n for (let co = grounding.supports.length - 1; co >= 0; co -= 1) {\n const support = grounding.supports[co];\n ret = this.annotateSegment(ret, grounding, support, co);\n }\n return ret;\n }\n\n protected abstract textPrefix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n protected abstract textSuffix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string {\n return grounding?.metadata?.searchEntryPoint?.renderedContent ?? \"\";\n }\n\n protected annotateText(text: string, grounding: GroundingInfo): string {\n const prefix = this.textPrefix(text, grounding) ?? \"\";\n const suffix = this.textSuffix(text, grounding) ?? \"\";\n const body = this.annotateTextSegments(text, grounding);\n return `${prefix}${body}${suffix}`;\n }\n\n async parseResult(\n generations: Generations,\n _callbacks?: Callbacks\n ): Promise<string> {\n const text = this.generationsToString(generations);\n\n const grounding = this.generationsToGroundingInfo(generations);\n if (!grounding) {\n return text;\n }\n\n return this.annotateText(text, grounding);\n }\n}\n\nexport class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected segmentSuffix(\n _grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n const indices: number[] = support.groundingChunkIndices.map((i) => i + 1);\n return ` [${indices.join(\", \")}]`;\n }\n\n protected textPrefix(_text: string, _grounding: GroundingInfo): string {\n return \"Google Says:\\n\";\n }\n\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string {\n const info = chunk.retrievedContext ?? chunk.web;\n return `${index + 1}. ${info.title} - ${info.uri}`;\n }\n\n protected textSuffix(_text: string, grounding: GroundingInfo): string {\n let ret = \"\\n\";\n const chunks: GeminiGroundingChunk[] =\n grounding?.metadata?.groundingChunks ?? [];\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkToString(chunk, index)}\\n`;\n });\n return ret;\n }\n}\n\nexport class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected chunkLink(grounding: GroundingInfo, index: number): string {\n const chunk = grounding.metadata.groundingChunks[index];\n const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;\n const num = index + 1;\n return `[[${num}](${url})]`;\n }\n\n protected segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n let ret = \"\";\n support.groundingChunkIndices.forEach((chunkIndex) => {\n const link = this.chunkLink(grounding, chunkIndex);\n ret = `${ret}${link}`;\n });\n return ret;\n }\n\n protected textPrefix(\n _text: string,\n _grounding: GroundingInfo\n ): string | undefined {\n return undefined;\n }\n\n protected chunkSuffixLink(\n chunk: GeminiGroundingChunk,\n index: number\n ): string {\n const num = index + 1;\n const info = chunk.retrievedContext ?? chunk.web;\n const url = info.uri;\n const site = info.title;\n return `${num}. [${site}](${url})`;\n }\n\n protected textSuffix(\n _text: string,\n grounding: GroundingInfo\n ): string | undefined {\n let ret = \"\\n**Search Sources**\\n\";\n const chunks: GeminiGroundingChunk[] = grounding.metadata.groundingChunks;\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkSuffixLink(chunk, index)}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ACF,SAAO;;;AAIX,IAAa,mCAAb,cAAsD,6BAA6B;CACjF,AAAU,cACR,YACA,UACA,QACoB;CAItB,AAAU,UAAU,WAA0B,OAAuB;EACnE,MAAM,QAAQ,UAAU,SAAS,gBAAgB;EACjD,MAAM,MAAM,MAAM,kBAAkB,OAAO,MAAM,KAAK;AAEtD,SAAO,KADK,QAAQ,EACJ,IAAI,IAAI;;CAG1B,AAAU,cACR,WACA,SACA,QACoB;EACpB,IAAI,MAAM;AACV,UAAQ,sBAAsB,SAAS,eAAe;GACpD,MAAM,OAAO,KAAK,UAAU,WAAW,WAAW;AAClD,SAAM,GAAG,MAAM;IACf;AACF,SAAO;;CAGT,AAAU,WACR,OACA,YACoB;CAItB,AAAU,gBACR,OACA,OACQ;EACR,MAAM,MAAM,QAAQ;EACpB,MAAM,OAAO,MAAM,oBAAoB,MAAM;EAC7C,MAAM,MAAM,KAAK;AAEjB,SAAO,GAAG,IAAI,KADD,KAAK,MACM,IAAI,IAAI;;CAGlC,AAAU,WACR,OACA,WACoB;EACpB,IAAI,MAAM;AAEV,EADuC,UAAU,SAAS,gBACnD,SAAS,OAAO,UAAU;AAC/B,SAAM,GAAG,MAAM,KAAK,gBAAgB,OAAO,MAAM,CAAC;IAClD;EAEF,MAAM,SAAS,KAAK,iBAAiB,UAAU;AAC/C,QAAM,GAAG,IAAI,IAAI;AAEjB,SAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"output_parsers.d.cts","names":["BaseLLMOutputParser","Callbacks","ChatGeneration","Generation","GeminiGroundingChunk","GeminiGroundingMetadata","GeminiGroundingSupport","Generations","GroundingInfo","BaseGoogleSearchOutputParser","Promise","SimpleGoogleSearchOutputParser","MarkdownGoogleSearchOutputParser"],"sources":["../src/output_parsers.d.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { GeminiGroundingChunk, GeminiGroundingMetadata, GeminiGroundingSupport } from \"./types.js\";\ntype Generations = Generation[] | ChatGeneration[];\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\nexport declare abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[];\n protected generationToGroundingInfo(generation: Generation | ChatGeneration): GroundingInfo | undefined;\n protected generationsToGroundingInfo(generations: Generations): GroundingInfo | undefined;\n protected generationToString(generation: Generation | ChatGeneration): string;\n protected generationsToString(generations: Generations): string;\n protected abstract segmentPrefix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected abstract segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected annotateSegment(text: string, grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string;\n protected annotateTextSegments(text: string, grounding: GroundingInfo): string;\n protected abstract textPrefix(text: string, grounding: GroundingInfo): string | undefined;\n protected abstract textSuffix(text: string, grounding: GroundingInfo): string | undefined;\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string;\n protected annotateText(text: string, grounding: GroundingInfo): string;\n parseResult(generations: Generations, _callbacks?: Callbacks): Promise<string>;\n}\nexport declare class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected segmentSuffix(_grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string;\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string;\n}\nexport declare class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected chunkLink(grounding: GroundingInfo, index: number): string;\n protected segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string | undefined;\n protected chunkSuffixLink(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string | undefined;\n}\nexport {};\n//# sourceMappingURL=output_parsers.d.ts.map"],"mappings":";;;;;;KAIKO,WAAAA,GAAcJ,eAAeD;KAC7BM,aAAAA;EADAD,QAAAA,EAESF,uBAFKF;EACdK,QAAAA,EAESF,sBADAD,EAAAA;AAGd,CAAA;AAEoDF,uBAFtBM,4BAAAA,SAAqCT,mBAEfG,CAAAA,MAAAA,CAAAA,CAAAA;EAAaD,YAAAA,EAAAA,MAAAA,EAAAA;EAAiBM,UAAAA,yBAAAA,CAAAA,UAAAA,EAA9BL,UAA8BK,GAAjBN,cAAiBM,CAAAA,EAAAA,aAAAA,GAAAA,SAAAA;EAC5BD,UAAAA,0BAAAA,CAAAA,WAAAA,EAAAA,WAAAA,CAAAA,EAAcC,aAAdD,GAAAA,SAAAA;EAAcC,UAAAA,kBAAAA,CAAAA,UAAAA,EACvBL,UADuBK,GACVN,cADUM,CAAAA,EAAAA,MAAAA;EACvBL,UAAAA,mBAAAA,CAAAA,WAAAA,EACEI,WADFJ,CAAAA,EAAAA,MAAAA;EAAaD,mBAAAA,aAAAA,CAAAA,SAAAA,EAEVM,aAFUN,EAAAA,OAAAA,EAEcI,sBAFdJ,EAAAA,KAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EACXK,mBAAAA,aAAAA,CAAAA,SAAAA,EAECC,aAFDD,EAAAA,OAAAA,EAEyBD,sBAFzBC,EAAAA,KAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EACCC,UAAAA,eAAAA,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AA,EACZ,QAAA,EAAU,sBAAA,EACV,MAAA;EAAA,UAKQ,SAAA,CAAU,SAAA,EAAW,aAAA,EAAe,KAAA;EAAA,UAOpC,aAAA,CACR,SAAA,EAAW,aAAA,EACX,OAAA,EAAS,sBAAA,EACT,MAAA;EAAA,UAUQ,UAAA,CACR,KAAA,UACA,UAAA,EAAY,aAAA;EAAA,UAKJ,eAAA,CACR,KAAA,EAAO,oBAAA,EACP,KAAA;EAAA,UASQ,UAAA,CACR,KAAA,UACA,SAAA,EAAW,aAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"output_parsers.d.ts","names":["BaseLLMOutputParser","Callbacks","ChatGeneration","Generation","GeminiGroundingChunk","GeminiGroundingMetadata","GeminiGroundingSupport","Generations","GroundingInfo","BaseGoogleSearchOutputParser","Promise","SimpleGoogleSearchOutputParser","MarkdownGoogleSearchOutputParser"],"sources":["../src/output_parsers.d.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { GeminiGroundingChunk, GeminiGroundingMetadata, GeminiGroundingSupport } from \"./types.js\";\ntype Generations = Generation[] | ChatGeneration[];\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\nexport declare abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[];\n protected generationToGroundingInfo(generation: Generation | ChatGeneration): GroundingInfo | undefined;\n protected generationsToGroundingInfo(generations: Generations): GroundingInfo | undefined;\n protected generationToString(generation: Generation | ChatGeneration): string;\n protected generationsToString(generations: Generations): string;\n protected abstract segmentPrefix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected abstract segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected annotateSegment(text: string, grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string;\n protected annotateTextSegments(text: string, grounding: GroundingInfo): string;\n protected abstract textPrefix(text: string, grounding: GroundingInfo): string | undefined;\n protected abstract textSuffix(text: string, grounding: GroundingInfo): string | undefined;\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string;\n protected annotateText(text: string, grounding: GroundingInfo): string;\n parseResult(generations: Generations, _callbacks?: Callbacks): Promise<string>;\n}\nexport declare class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected segmentSuffix(_grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string;\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string;\n}\nexport declare class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected chunkLink(grounding: GroundingInfo, index: number): string;\n protected segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string | undefined;\n protected chunkSuffixLink(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string | undefined;\n}\nexport {};\n//# sourceMappingURL=output_parsers.d.ts.map"],"mappings":";;;;;;KAIKO,WAAAA,GAAcJ,eAAeD;KAC7BM,aAAAA;EADAD,QAAAA,EAESF,uBAFKF;EACdK,QAAAA,EAESF,sBADAD,EAAAA;AAGd,CAAA;AAEoDF,uBAFtBM,4BAAAA,SAAqCT,mBAEfG,CAAAA,MAAAA,CAAAA,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IAAA,UACA,SAAA,EAAW,aAAA;EAAA,mBAGM,UAAA,CACjB,IAAA,UACA,SAAA,EAAW,aAAA;EArHO;;;;;;;;EAAA,UAgIV,gBAAA,CAAiB,SAAA,EAAW,aAAA;EAAA,UAI5B,YAAA,CAAa,IAAA,UAAc,SAAA,EAAW,aAAA;EAO1C,WAAA,CACJ,WAAA,EAAa,WAAA,EACb,UAAA,GAAa,SAAA,GACZ,OAAA;AAAA;AAAA,cAYQ,8BAAA,SAAuC,4BAAA;EAAA,UACxC,aAAA,CACR,UAAA,EAAY,aAAA,EACZ,QAAA,EAAU,sBAAA,EACV,MAAA;EAAA,UAKQ,aAAA,CACR,UAAA,EAAY,aAAA,EACZ,OAAA,EAAS,sBAAA,EACT,MAAA;EAAA,UAMQ,UAAA,CAAW,KAAA,UAAe,UAAA,EAAY,aAAA;EAAA,UAItC,aAAA,CAAc,KAAA,EAAO,oBAAA,EAAsB,KAAA;EAAA,UAK3C,UAAA,CAAW,KAAA,UAAe,SAAA,EAAW,aAAA;AAAA;AAAA,cAWpC,gCAAA,SAAyC,4BAAA;EAAA,UAC1C,aAAA,CACR,UAAA,EAAY,aAAA,EACZ,QAAA,EAAU,sBAAA,EACV,MAAA;EAAA,UAKQ,SAAA,CAAU,SAAA,EAAW,aAAA,EAAe,KAAA;EAAA,UAOpC,aAAA,CACR,SAAA,EAAW,aAAA,EACX,OAAA,EAAS,sBAAA,EACT,MAAA;EAAA,UAUQ,UAAA,CACR,KAAA,UACA,UAAA,EAAY,aAAA;EAAA,UAKJ,eAAA,CACR,KAAA,EAAO,oBAAA,EACP,KAAA;EAAA,UASQ,UAAA,CACR,KAAA,UACA,SAAA,EAAW,aAAA;AAAA"}
@@ -13,14 +13,12 @@ var BaseGoogleSearchOutputParser = class extends BaseLLMOutputParser {
13
13
  supports
14
14
  };
15
15
  }
16
- return void 0;
17
16
  }
18
17
  generationsToGroundingInfo(generations) {
19
18
  for (const generation of generations) {
20
19
  const info = this.generationToGroundingInfo(generation);
21
20
  if (info !== void 0) return info;
22
21
  }
23
- return void 0;
24
22
  }
25
23
  generationToString(generation) {
26
24
  if ("message" in generation) {
@@ -42,9 +40,7 @@ var BaseGoogleSearchOutputParser = class extends BaseLLMOutputParser {
42
40
  const textBefore = text.substring(0, start);
43
41
  const textSegment = text.substring(start, end);
44
42
  const textAfter = text.substring(end);
45
- const textPrefix = this.segmentPrefix(grounding, support, index) ?? "";
46
- const textSuffix = this.segmentSuffix(grounding, support, index) ?? "";
47
- return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;
43
+ return `${textBefore}${this.segmentPrefix(grounding, support, index) ?? ""}${textSegment}${this.segmentSuffix(grounding, support, index) ?? ""}${textAfter}`;
48
44
  }
49
45
  annotateTextSegments(text, grounding) {
50
46
  let ret = text;
@@ -68,8 +64,7 @@ var BaseGoogleSearchOutputParser = class extends BaseLLMOutputParser {
68
64
  annotateText(text, grounding) {
69
65
  const prefix = this.textPrefix(text, grounding) ?? "";
70
66
  const suffix = this.textSuffix(text, grounding) ?? "";
71
- const body = this.annotateTextSegments(text, grounding);
72
- return `${prefix}${body}${suffix}`;
67
+ return `${prefix}${this.annotateTextSegments(text, grounding)}${suffix}`;
73
68
  }
74
69
  async parseResult(generations, _callbacks) {
75
70
  const text = this.generationsToString(generations);
@@ -79,12 +74,9 @@ var BaseGoogleSearchOutputParser = class extends BaseLLMOutputParser {
79
74
  }
80
75
  };
81
76
  var SimpleGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
82
- segmentPrefix(_grounding, _support, _index) {
83
- return void 0;
84
- }
77
+ segmentPrefix(_grounding, _support, _index) {}
85
78
  segmentSuffix(_grounding, support, _index) {
86
- const indices = support.groundingChunkIndices.map((i) => i + 1);
87
- return ` [${indices.join(", ")}]`;
79
+ return ` [${support.groundingChunkIndices.map((i) => i + 1).join(", ")}]`;
88
80
  }
89
81
  textPrefix(_text, _grounding) {
90
82
  return "Google Says:\n";
@@ -95,22 +87,18 @@ var SimpleGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser
95
87
  }
96
88
  textSuffix(_text, grounding) {
97
89
  let ret = "\n";
98
- const chunks = grounding?.metadata?.groundingChunks ?? [];
99
- chunks.forEach((chunk, index) => {
90
+ (grounding?.metadata?.groundingChunks ?? []).forEach((chunk, index) => {
100
91
  ret = `${ret}${this.chunkToString(chunk, index)}\n`;
101
92
  });
102
93
  return ret;
103
94
  }
104
95
  };
105
96
  var MarkdownGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
106
- segmentPrefix(_grounding, _support, _index) {
107
- return void 0;
108
- }
97
+ segmentPrefix(_grounding, _support, _index) {}
109
98
  chunkLink(grounding, index) {
110
99
  const chunk = grounding.metadata.groundingChunks[index];
111
100
  const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;
112
- const num = index + 1;
113
- return `[[${num}](${url})]`;
101
+ return `[[${index + 1}](${url})]`;
114
102
  }
115
103
  segmentSuffix(grounding, support, _index) {
116
104
  let ret = "";
@@ -120,20 +108,16 @@ var MarkdownGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParse
120
108
  });
121
109
  return ret;
122
110
  }
123
- textPrefix(_text, _grounding) {
124
- return void 0;
125
- }
111
+ textPrefix(_text, _grounding) {}
126
112
  chunkSuffixLink(chunk, index) {
127
113
  const num = index + 1;
128
114
  const info = chunk.retrievedContext ?? chunk.web;
129
115
  const url = info.uri;
130
- const site = info.title;
131
- return `${num}. [${site}](${url})`;
116
+ return `${num}. [${info.title}](${url})`;
132
117
  }
133
118
  textSuffix(_text, grounding) {
134
119
  let ret = "\n**Search Sources**\n";
135
- const chunks = grounding.metadata.groundingChunks;
136
- chunks.forEach((chunk, index) => {
120
+ grounding.metadata.groundingChunks.forEach((chunk, index) => {
137
121
  ret = `${ret}${this.chunkSuffixLink(chunk, index)}\n`;
138
122
  });
139
123
  const search = this.searchSuggestion(grounding);