From f7846d54fd472d11a34abf8304ccb562e531e81a Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Thu, 2 Jan 2025 09:41:31 -0800 Subject: [PATCH] fix(create-langchain-integration): Update integration template (#7458) --- .../template/package.json | 18 +++++++---- .../template/src/chat_models.ts | 30 ++++++++++++++++--- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/libs/create-langchain-integration/template/package.json b/libs/create-langchain-integration/template/package.json index 59ea14c9fe69..5ab717048eff 100644 --- a/libs/create-langchain-integration/template/package.json +++ b/libs/create-langchain-integration/template/package.json @@ -1,7 +1,7 @@ { "name": "langchain-integration", "version": "0.0.0", - "description": "Sample integration for LangChain.js", + "description": "Sample INTEGRATION_SHORT_NAME integration for LangChain.js", "type": "module", "engines": { "node": ">=18" @@ -12,7 +12,7 @@ "type": "git", "url": "git@github.com:langchain-ai/langchainjs.git" }, - "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-INTEGRATION_NAME/", + "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/INTEGRATION_NAME/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/INTEGRATION_NAME", "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", @@ -31,13 +31,14 @@ }, "author": "LangChain", "license": "MIT", - "dependencies": { + "peerDependencies": { "@langchain/core": ">=0.3.0 <0.4.0" }, "devDependencies": { "@jest/globals": "^29.5.0", "@swc/core": "^1.3.90", "@swc/jest": "^0.2.29", + "@langchain/core": "workspace:*", "@langchain/scripts": ">=0.1.0 <0.2.0", "@tsconfig/recommended": "^1.0.3", "@typescript-eslint/eslint-plugin": "^6.12.0", @@ -63,7 +64,11 @@ }, "exports": { ".": { - "types": "./index.d.ts", + "types": { + "import": "./index.d.ts", + "require": "./index.d.cts", + "default": "./index.d.ts" + }, "import": "./index.js", "require": "./index.cjs" }, @@ -73,6 +78,7 @@ "dist/", "index.cjs", "index.js", - "index.d.ts" + "index.d.ts", + "index.d.cts" ] -} \ No newline at end of file +} diff --git a/libs/create-langchain-integration/template/src/chat_models.ts b/libs/create-langchain-integration/template/src/chat_models.ts index 7ead127849b1..752361131153 100644 --- a/libs/create-langchain-integration/template/src/chat_models.ts +++ b/libs/create-langchain-integration/template/src/chat_models.ts @@ -16,6 +16,12 @@ import { // AIMessageChunk, // } from "@langchain/core/messages"; +// Uncomment if implementing tool calling + +// import { +// type BindToolsInput, +// } from "@langchain/core/language_models/chat_models"; + /** * Input to chat model class. */ @@ -24,10 +30,10 @@ export interface ChatIntegrationInput extends BaseChatModelParams {} /** * Integration with a chat model. */ -export class ChatIntegration< - CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions - > - extends SimpleChatModel +export class ChatIntegration + // Extend BaseLanguageModelCallOptions and pass it as the generic here + // to support typing for additional runtime parameters for your integration + extends SimpleChatModel implements ChatIntegrationInput { // Used for tracing, replace with the same name as your class @@ -98,6 +104,22 @@ export class ChatIntegration< // } // } + /** + * Implement to support tool calling. + * You must also pass the bound tools into your actual chat completion call. + * See {@link ../../langchain-cerberas/src/chat_model.ts} for + * an example. + */ + // override bindTools( + // tools: BindToolsInput[], + // kwargs?: Partial + // ): Runnable { + // return this.bind({ + // tools: tools.map((tool) => convertToIntegrationFormat(tool)), + // ...kwargs, + // }); + // } + /** @ignore */ _combineLLMOutput() { return [];