medpromptjs 0.2.1 → 0.2.3
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.
- package/dist/agent.d.ts +3 -3
- package/dist/chain.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/medpromptjs.cjs.development.js +195 -227
- package/dist/medpromptjs.cjs.development.js.map +1 -1
- package/dist/medpromptjs.cjs.production.min.js +1 -1
- package/dist/medpromptjs.cjs.production.min.js.map +1 -1
- package/dist/medpromptjs.esm.js +195 -227
- package/dist/medpromptjs.esm.js.map +1 -1
- package/dist/tool.d.ts +1 -1
- package/package.json +18 -5
- package/src/agent.ts +59 -50
- package/src/chain.ts +61 -47
- package/src/index.ts +1 -1
- package/src/mydi.ts +8 -8
- package/src/tool.ts +46 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"medpromptjs.esm.js","sources":["../src/mydi.ts","../src/chain.ts","../src/agent.ts","../src/tool.ts"],"sourcesContent":["/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst mydi = (c:any, m:string, b:string) => {\n try {\n return c.resolve(m+\"_\"+b);\n } catch (e) {\n return c.resolve(b);\n }\n}\n\nexport default mydi;","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { LLM } from \"langchain/llms/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport mydi from \"./mydi\";\nimport { RunnablePassthrough, RunnableSequence } from \"@langchain/core/runnables\";\n\nexport class BaseChain {\n\n container: any;\n tools: ToolInterface[];\n name: string;\n description: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\n Summarize the following text:\n {input}\n `\n\n constructor(container: any, name: string, description: string, template: string=\"\") {\n this.container = container;\n this.name = name === \"\" ? this.camelize(this.constructor.name) : name;\n this.description = description === \"\" ? this.snake_case(this.constructor.name) : description;\n this.tools = this.resolve(\"tools\")\n this.prompt = this.resolve(\"prompt\") !== \"\" ? this.resolve(\"prompt\") : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve(\"main-llm\");\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n }).replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : \"_\" + word.toLowerCase();\n }).replace(/\\s+/g, '');\n }\n\n\n // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/\n //! Override this method\n chain(input: any) {\n const _chain = RunnableSequence.from([\n new RunnablePassthrough(),\n this.prompt,\n this.llm\n ])\n return _chain.invoke(input);\n }\n}","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { LLM } from \"langchain/llms/base\";\nimport { AgentExecutor, createReactAgent, createStructuredChatAgent } from \"langchain/agents\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport mydi from \"./mydi\";\n\nexport class BaseAgent {\n\n container: any;\n tools: ToolInterface[];\n name: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\n ## Question: {question}\n ## Answer: {answer}\n Given the above question and answer, generate a chain of thought explanation for the answer.\n First, start with the model generated chain of thought explanation.\n End the chain of though explanation with:\n Therefore, the answer is {answer}.\n `\n\n constructor(container: any) {\n this.container = container;\n this.name = this.camelize(this.constructor.name);\n this.tools = this.resolve(\"tools\")\n this.prompt = this.resolve(\"prompt\") !== \"\" ? this.resolve(\"prompt\") : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve(\"main-llm\");\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n }).replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : \"_\" + word.toLowerCase();\n }).replace(/\\s+/g, '');\n }\n\n async run(input: any) {\n const agent = await createStructuredChatAgent({\n llm: this.llm,\n tools: this.tools,\n prompt: this.prompt,\n });\n const agentExecutor = new AgentExecutor({\n agent: agent,\n tools: this.tools,\n // verbose: true,\n handleParsingErrors:\n \"Please try again, paying close attention to the final answer\",\n });\n return await agentExecutor.invoke(input);\n }\n\n}","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DynamicStructuredTool } from \"langchain/tools\";\nimport mydi from \"./mydi\";\n\nexport class BaseTool extends DynamicStructuredTool {\n\n container: any;\n name: string;\n description: string;\n schema: any;\n constructor(container: any, name: string, description: string, schema: any, func: any = null) {\n super({\n name: name,\n description: description,\n schema: schema,\n func: func\n });\n this.container = container;\n this.name = name === \"\" ? this.camelize(this.constructor.name) : name;\n this.description = description === \"\" ? this.snake_case(this.constructor.name) : description;\n this.schema = schema;\n }\n\n func = async (args: any) => {\n return \"override this\";\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n }).replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : \"_\" + word.toLowerCase();\n }).replace(/\\s+/g, '');\n }\n\n}"],"names":["mydi","c","m","b","resolve","e","BaseChain","container","name","description","template","tools","prompt","llm","camelize","constructor","snake_case","PromptTemplate","fromTemplate","_proto","prototype","str","replace","word","index","toLowerCase","toUpperCase","chain","input","_chain","RunnableSequence","from","RunnablePassthrough","invoke","BaseAgent","run","_run","_asyncToGenerator","_regeneratorRuntime","mark","_callee","agent","agentExecutor","wrap","_callee$","_context","prev","next","createStructuredChatAgent","sent","AgentExecutor","handleParsingErrors","abrupt","stop","_x","apply","arguments","BaseTool","_DynamicStructuredToo","schema","func","_this","call","_ref","args","_inheritsLoose","DynamicStructuredTool"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;A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AAA;IAChB,OAAOR,IAAI,CAAC,IAAI,CAACO,SAAS,EAAE,IAAI,CAACC,IAAI,EAAEA,IAAI,CAAC,CAAA;GAC/C,CAAA;AAAAW,EAAAA,MAAA,CAEDL,QAAQ,GAAR,SAAAA,QAAAA,CAASO,GAAW,EAAA;IAChB,OAAOA,GAAG,CAACC,OAAO,CAAC,qBAAqB,EAAE,UAASC,IAAI,EAAEC,KAAK,EAAA;AAC1D,MAAA,OAAOA,KAAK,KAAK,CAAC,GAAGD,IAAI,CAACE,WAAW,EAAE,GAAGF,IAAI,CAACG,WAAW,EAAE,CAAA;AAChE,KAAC,CAAC,CAACJ,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACzB,CAAA;AAAAH,EAAAA,MAAA,CAEDH,UAAU,GAAV,SAAAA,UAAAA,CAAWK,GAAW,EAAA;IAClB,OAAOA,GAAG,CAACC,OAAO,CAAC,qBAAqB,EAAE,UAASC,IAAI,EAAEC,KAAK,EAAA;AAC1D,MAAA,OAAOA,KAAK,KAAK,CAAC,GAAGD,IAAI,CAACE,WAAW,EAAE,GAAG,GAAG,GAAGF,IAAI,CAACE,WAAW,EAAE,CAAA;AACtE,KAAC,CAAC,CAACH,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACzB,CAAA;AAAA,EAAA,OAAAmC,QAAA,CAAA;AAAA,CAAA,CArCyBS,qBAAqB;;;;"}
|
|
1
|
+
{"version":3,"file":"medpromptjs.esm.js","sources":["../src/mydi.ts","../src/chain.ts","../src/agent.ts","../src/tool.ts"],"sourcesContent":["/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst mydi = (c: any, m: string, b: string) => {\n try {\n return c.resolve(m + '_' + b);\n } catch (e) {\n return c.resolve(b);\n }\n};\n\nexport default mydi;\n","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { LLM } from '@langchain/core/language_models/llms';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\nimport {\n RunnablePassthrough,\n RunnableSequence,\n} from '@langchain/core/runnables';\n\nexport class BaseChain {\n container: any;\n tools: ToolInterface[];\n name: string;\n description: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\n Summarize the following text:\n {input}\n `;\n\n constructor(\n container: any,\n name: string,\n description: string,\n template: string = ''\n ) {\n this.container = container;\n this.name = name === '' ? this.camelize(this.constructor.name) : name;\n this.description =\n description === '' ? this.snake_case(this.constructor.name) : description;\n this.tools = this.resolve('tools');\n this.prompt =\n this.resolve('prompt') !== ''\n ? this.resolve('prompt')\n : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve('main-llm');\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n\n // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/\n //! Override this method\n chain(input: any) {\n const _chain = RunnableSequence.from([\n new RunnablePassthrough(),\n this.prompt,\n this.llm,\n ]);\n return _chain.invoke(input);\n }\n}\n","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { LLM } from '@langchain/core/language_models/llms';\nimport {\n AgentExecutor,\n createReactAgent,\n createStructuredChatAgent,\n} from 'langchain/agents';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\n\nexport class BaseAgent {\n container: any;\n tools: ToolInterface[];\n name: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\n ## Question: {question}\n ## Answer: {answer}\n Given the above question and answer, generate a chain of thought explanation for the answer.\n First, start with the model generated chain of thought explanation.\n End the chain of though explanation with:\n Therefore, the answer is {answer}.\n `;\n\n constructor(container: any) {\n this.container = container;\n this.name = this.camelize(this.constructor.name);\n this.tools = this.resolve('tools');\n this.prompt =\n this.resolve('prompt') !== ''\n ? this.resolve('prompt')\n : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve('main-llm');\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n\n async run(input: any) {\n const agent = await createStructuredChatAgent({\n llm: this.llm,\n tools: this.tools,\n prompt: this.prompt,\n });\n const agentExecutor = new AgentExecutor({\n agent: agent,\n tools: this.tools,\n // verbose: true,\n handleParsingErrors:\n 'Please try again, paying close attention to the final answer',\n });\n return await agentExecutor.invoke(input);\n }\n}\n","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DynamicStructuredTool } from 'langchain/tools';\nimport mydi from './mydi';\n\nexport class BaseTool extends DynamicStructuredTool {\n container: any;\n name: string;\n description: string;\n schema: any;\n constructor(\n container: any,\n name: string,\n description: string,\n schema: any,\n func: any = null\n ) {\n super({\n name: name,\n description: description,\n schema: schema,\n func: func,\n });\n this.container = container;\n this.name = name === '' ? this.camelize(this.constructor.name) : name;\n this.description =\n description === '' ? this.snake_case(this.constructor.name) : description;\n this.schema = schema;\n }\n\n func = async (args: any) => {\n return 'override this';\n };\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n}\n"],"names":["mydi","c","m","b","resolve","e","BaseChain","container","name","description","template","tools","prompt","llm","camelize","constructor","snake_case","PromptTemplate","fromTemplate","_proto","prototype","str","replace","word","index","toLowerCase","toUpperCase","chain","input","_chain","RunnableSequence","from","RunnablePassthrough","invoke","BaseAgent","run","_run","_asyncToGenerator","_regeneratorRuntime","mark","_callee","agent","agentExecutor","wrap","_callee$","_context","prev","next","createStructuredChatAgent","sent","AgentExecutor","handleParsingErrors","abrupt","stop","_x","apply","arguments","BaseTool","_DynamicStructuredToo","schema","func","_this","call","_ref","args","_inheritsLoose","DynamicStructuredTool"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;AAcG;AAEH,IAAMA,IAAI,GAAG,SAAPA,IAAIA,CAAIC,CAAM,EAAEC,CAAS,EAAEC,CAAS,EAAI;EAC5C,IAAI;IACF,OAAOF,CAAC,CAACG,OAAO,CAACF,CAAC,GAAG,GAAG,GAAGC,CAAC,CAAC,CAAA;GAC9B,CAAC,OAAOE,CAAC,EAAE;AACV,IAAA,OAAOJ,CAAC,CAACG,OAAO,CAACD,CAAC,CAAC,CAAA;AACrB,GAAA;AACF,CAAC;;ACtBD;;;;;;;;;;;;;;AAcG;AAWH,IAAaG,SAAS,gBAAA,YAAA;EAYpB,SAAAA,SAAAA,CACEC,SAAc,EACdC,IAAY,EACZC,WAAmB,EACnBC,UAAqB;AAAA,IAAA,IAAA,CAfvBH,SAAS,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACTI,KAAK,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACLH,IAAI,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACJC,WAAW,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACXG,MAAM,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACNC,GAAG,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACHH,QAAQ,GAAA,wEAAA,CAAA;IAWN,IAAI,CAACH,SAAS,GAAGA,SAAS,CAA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+13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { DynamicStructuredTool } from
|
|
16
|
+
import { DynamicStructuredTool } from 'langchain/tools';
|
|
17
17
|
export declare class BaseTool extends DynamicStructuredTool {
|
|
18
18
|
container: any;
|
|
19
19
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "medpromptjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "A library of langchain base classes for building medical applications.",
|
|
4
5
|
"license": "Apache-2.0",
|
|
5
6
|
"author": "Bell Eapen",
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"module": "dist/medpromptjs.esm.js",
|
|
8
9
|
"typings": "dist/index.d.ts",
|
|
9
|
-
"
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/medpromptjs.esm.js",
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./dist/medpromptjs.esm.js": {
|
|
17
|
+
"import": "./dist/medpromptjs.esm.js",
|
|
18
|
+
"require": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
10
22
|
"files": [
|
|
11
23
|
"dist",
|
|
12
24
|
"src"
|
|
@@ -67,10 +79,11 @@
|
|
|
67
79
|
"dependencies": {
|
|
68
80
|
"cors": "^2.8.5",
|
|
69
81
|
"dotenv": "^16.3.1",
|
|
70
|
-
"express": "^
|
|
71
|
-
"langchain": "^0.
|
|
82
|
+
"express": "^5.1.0",
|
|
83
|
+
"langchain": "^0.3.27",
|
|
84
|
+
"@langchain/community": "0.3.44",
|
|
72
85
|
"reflect-metadata": "^0.2.1",
|
|
73
86
|
"tslog": "^4.9.2",
|
|
74
87
|
"tsyringe": "^4.8.0"
|
|
75
88
|
}
|
|
76
|
-
}
|
|
89
|
+
}
|
package/src/agent.ts
CHANGED
|
@@ -14,66 +14,75 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { PromptTemplate, ChatPromptTemplate } from
|
|
18
|
-
import { LLM } from
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
import { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';
|
|
18
|
+
import { LLM } from '@langchain/core/language_models/llms';
|
|
19
|
+
import {
|
|
20
|
+
AgentExecutor,
|
|
21
|
+
createReactAgent,
|
|
22
|
+
createStructuredChatAgent,
|
|
23
|
+
} from 'langchain/agents';
|
|
24
|
+
import type { ToolInterface } from '@langchain/core/tools';
|
|
25
|
+
import mydi from './mydi';
|
|
22
26
|
|
|
23
27
|
export class BaseAgent {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
template: string = `
|
|
28
|
+
container: any;
|
|
29
|
+
tools: ToolInterface[];
|
|
30
|
+
name: string;
|
|
31
|
+
prompt: PromptTemplate;
|
|
32
|
+
llm: LLM;
|
|
33
|
+
template: string = `
|
|
31
34
|
## Question: {question}
|
|
32
35
|
## Answer: {answer}
|
|
33
36
|
Given the above question and answer, generate a chain of thought explanation for the answer.
|
|
34
37
|
First, start with the model generated chain of thought explanation.
|
|
35
38
|
End the chain of though explanation with:
|
|
36
39
|
Therefore, the answer is {answer}.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
constructor(container: any) {
|
|
40
|
-
this.container = container;
|
|
41
|
-
this.name = this.camelize(this.constructor.name);
|
|
42
|
-
this.tools = this.resolve("tools")
|
|
43
|
-
this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : PromptTemplate.fromTemplate(this.template);
|
|
44
|
-
this.llm = this.resolve("main-llm");
|
|
45
|
-
}
|
|
40
|
+
`;
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
constructor(container: any) {
|
|
43
|
+
this.container = container;
|
|
44
|
+
this.name = this.camelize(this.constructor.name);
|
|
45
|
+
this.tools = this.resolve('tools');
|
|
46
|
+
this.prompt =
|
|
47
|
+
this.resolve('prompt') !== ''
|
|
48
|
+
? this.resolve('prompt')
|
|
49
|
+
: PromptTemplate.fromTemplate(this.template);
|
|
50
|
+
this.llm = this.resolve('main-llm');
|
|
51
|
+
}
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}).replace(/\s+/g, '');
|
|
55
|
-
}
|
|
53
|
+
resolve(name: string) {
|
|
54
|
+
return mydi(this.container, this.name, name);
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
camelize(str: string) {
|
|
58
|
+
return str
|
|
59
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
60
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
61
|
+
})
|
|
62
|
+
.replace(/\s+/g, '');
|
|
63
|
+
}
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
agent: agent,
|
|
71
|
-
tools: this.tools,
|
|
72
|
-
// verbose: true,
|
|
73
|
-
handleParsingErrors:
|
|
74
|
-
"Please try again, paying close attention to the final answer",
|
|
75
|
-
});
|
|
76
|
-
return await agentExecutor.invoke(input);
|
|
77
|
-
}
|
|
65
|
+
snake_case(str: string) {
|
|
66
|
+
return str
|
|
67
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
68
|
+
return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
|
|
69
|
+
})
|
|
70
|
+
.replace(/\s+/g, '');
|
|
71
|
+
}
|
|
78
72
|
|
|
79
|
-
|
|
73
|
+
async run(input: any) {
|
|
74
|
+
const agent = await createStructuredChatAgent({
|
|
75
|
+
llm: this.llm,
|
|
76
|
+
tools: this.tools,
|
|
77
|
+
prompt: this.prompt,
|
|
78
|
+
});
|
|
79
|
+
const agentExecutor = new AgentExecutor({
|
|
80
|
+
agent: agent,
|
|
81
|
+
tools: this.tools,
|
|
82
|
+
// verbose: true,
|
|
83
|
+
handleParsingErrors:
|
|
84
|
+
'Please try again, paying close attention to the final answer',
|
|
85
|
+
});
|
|
86
|
+
return await agentExecutor.invoke(input);
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/chain.ts
CHANGED
|
@@ -14,59 +14,73 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { PromptTemplate, ChatPromptTemplate } from
|
|
18
|
-
import { LLM } from
|
|
19
|
-
import type { ToolInterface } from
|
|
20
|
-
import mydi from
|
|
21
|
-
import {
|
|
17
|
+
import { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';
|
|
18
|
+
import { LLM } from '@langchain/core/language_models/llms';
|
|
19
|
+
import type { ToolInterface } from '@langchain/core/tools';
|
|
20
|
+
import mydi from './mydi';
|
|
21
|
+
import {
|
|
22
|
+
RunnablePassthrough,
|
|
23
|
+
RunnableSequence,
|
|
24
|
+
} from '@langchain/core/runnables';
|
|
22
25
|
|
|
23
26
|
export class BaseChain {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
template: string = `
|
|
27
|
+
container: any;
|
|
28
|
+
tools: ToolInterface[];
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
prompt: PromptTemplate;
|
|
32
|
+
llm: LLM;
|
|
33
|
+
template: string = `
|
|
32
34
|
Summarize the following text:
|
|
33
35
|
{input}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
constructor(container: any, name: string, description: string, template: string="") {
|
|
37
|
-
this.container = container;
|
|
38
|
-
this.name = name === "" ? this.camelize(this.constructor.name) : name;
|
|
39
|
-
this.description = description === "" ? this.snake_case(this.constructor.name) : description;
|
|
40
|
-
this.tools = this.resolve("tools")
|
|
41
|
-
this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : PromptTemplate.fromTemplate(this.template);
|
|
42
|
-
this.llm = this.resolve("main-llm");
|
|
43
|
-
}
|
|
36
|
+
`;
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
constructor(
|
|
39
|
+
container: any,
|
|
40
|
+
name: string,
|
|
41
|
+
description: string,
|
|
42
|
+
template: string = ''
|
|
43
|
+
) {
|
|
44
|
+
this.container = container;
|
|
45
|
+
this.name = name === '' ? this.camelize(this.constructor.name) : name;
|
|
46
|
+
this.description =
|
|
47
|
+
description === '' ? this.snake_case(this.constructor.name) : description;
|
|
48
|
+
this.tools = this.resolve('tools');
|
|
49
|
+
this.prompt =
|
|
50
|
+
this.resolve('prompt') !== ''
|
|
51
|
+
? this.resolve('prompt')
|
|
52
|
+
: PromptTemplate.fromTemplate(this.template);
|
|
53
|
+
this.llm = this.resolve('main-llm');
|
|
54
|
+
}
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}).replace(/\s+/g, '');
|
|
53
|
-
}
|
|
56
|
+
resolve(name: string) {
|
|
57
|
+
return mydi(this.container, this.name, name);
|
|
58
|
+
}
|
|
54
59
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
camelize(str: string) {
|
|
61
|
+
return str
|
|
62
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
63
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
64
|
+
})
|
|
65
|
+
.replace(/\s+/g, '');
|
|
66
|
+
}
|
|
60
67
|
|
|
68
|
+
snake_case(str: string) {
|
|
69
|
+
return str
|
|
70
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
71
|
+
return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
|
|
72
|
+
})
|
|
73
|
+
.replace(/\s+/g, '');
|
|
74
|
+
}
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
76
|
+
// https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/
|
|
77
|
+
//! Override this method
|
|
78
|
+
chain(input: any) {
|
|
79
|
+
const _chain = RunnableSequence.from([
|
|
80
|
+
new RunnablePassthrough(),
|
|
81
|
+
this.prompt,
|
|
82
|
+
this.llm,
|
|
83
|
+
]);
|
|
84
|
+
return _chain.invoke(input);
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/index.ts
CHANGED
package/src/mydi.ts
CHANGED
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
const mydi = (c:any, m:string, b:string) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
17
|
+
const mydi = (c: any, m: string, b: string) => {
|
|
18
|
+
try {
|
|
19
|
+
return c.resolve(m + '_' + b);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return c.resolve(b);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
24
|
|
|
25
|
-
export default mydi;
|
|
25
|
+
export default mydi;
|
package/src/tool.ts
CHANGED
|
@@ -14,46 +14,55 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { DynamicStructuredTool } from
|
|
18
|
-
import mydi from
|
|
17
|
+
import { DynamicStructuredTool } from 'langchain/tools';
|
|
18
|
+
import mydi from './mydi';
|
|
19
19
|
|
|
20
20
|
export class BaseTool extends DynamicStructuredTool {
|
|
21
|
+
container: any;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
schema: any;
|
|
25
|
+
constructor(
|
|
26
|
+
container: any,
|
|
27
|
+
name: string,
|
|
28
|
+
description: string,
|
|
29
|
+
schema: any,
|
|
30
|
+
func: any = null
|
|
31
|
+
) {
|
|
32
|
+
super({
|
|
33
|
+
name: name,
|
|
34
|
+
description: description,
|
|
35
|
+
schema: schema,
|
|
36
|
+
func: func,
|
|
37
|
+
});
|
|
38
|
+
this.container = container;
|
|
39
|
+
this.name = name === '' ? this.camelize(this.constructor.name) : name;
|
|
40
|
+
this.description =
|
|
41
|
+
description === '' ? this.snake_case(this.constructor.name) : description;
|
|
42
|
+
this.schema = schema;
|
|
43
|
+
}
|
|
21
44
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
schema: any;
|
|
26
|
-
constructor(container: any, name: string, description: string, schema: any, func: any = null) {
|
|
27
|
-
super({
|
|
28
|
-
name: name,
|
|
29
|
-
description: description,
|
|
30
|
-
schema: schema,
|
|
31
|
-
func: func
|
|
32
|
-
});
|
|
33
|
-
this.container = container;
|
|
34
|
-
this.name = name === "" ? this.camelize(this.constructor.name) : name;
|
|
35
|
-
this.description = description === "" ? this.snake_case(this.constructor.name) : description;
|
|
36
|
-
this.schema = schema;
|
|
37
|
-
}
|
|
45
|
+
func = async (args: any) => {
|
|
46
|
+
return 'override this';
|
|
47
|
+
};
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
resolve(name: string) {
|
|
50
|
+
return mydi(this.container, this.name, name);
|
|
51
|
+
}
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
camelize(str: string) {
|
|
54
|
+
return str
|
|
55
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
56
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
57
|
+
})
|
|
58
|
+
.replace(/\s+/g, '');
|
|
59
|
+
}
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
|
|
56
|
-
}).replace(/\s+/g, '');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}
|
|
61
|
+
snake_case(str: string) {
|
|
62
|
+
return str
|
|
63
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
64
|
+
return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
|
|
65
|
+
})
|
|
66
|
+
.replace(/\s+/g, '');
|
|
67
|
+
}
|
|
68
|
+
}
|