-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ollama[major]: Integration package (#5990)
* ollama[major]: Integration package * implement chat model * implemented tests * add standard tests * docs and deprecation warnings * added tool calling support, dropped experimental * updated docs with tool support content * throw if tool_choice is passed * cr * fix error * tests passing * fix * 0.0.1-rc.0 * cr * use sdk for tools
- Loading branch information
1 parent
c116ee1
commit fef3e16
Showing
36 changed files
with
1,786 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { tool } from "@langchain/core/tools"; | ||
import { ChatOllama } from "@langchain/ollama"; | ||
import { z } from "zod"; | ||
|
||
const weatherTool = tool((_) => "Da weather is weatherin", { | ||
name: "get_current_weather", | ||
description: "Get the current weather in a given location", | ||
schema: z.object({ | ||
location: z.string().describe("The city and state, e.g. San Francisco, CA"), | ||
}), | ||
}); | ||
|
||
// Define the model | ||
const model = new ChatOllama({ | ||
model: "llama3-groq-tool-use", | ||
}); | ||
|
||
// Bind the tool to the model | ||
const modelWithTools = model.bindTools([weatherTool]); | ||
|
||
const result = await modelWithTools.invoke( | ||
"What's the weather like today in San Francisco? Ensure you use the 'get_current_weather' tool." | ||
); | ||
|
||
console.log(result); | ||
/* | ||
AIMessage { | ||
"content": "", | ||
"tool_calls": [ | ||
{ | ||
"name": "get_current_weather", | ||
"args": { | ||
"location": "San Francisco, CA" | ||
}, | ||
"type": "tool_call" | ||
} | ||
], | ||
"usage_metadata": { | ||
"input_tokens": 177, | ||
"output_tokens": 30, | ||
"total_tokens": 207 | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ChatOllama } from "@langchain/ollama"; | ||
import { z } from "zod"; | ||
|
||
// Define the model | ||
const model = new ChatOllama({ | ||
model: "llama3-groq-tool-use", | ||
}); | ||
|
||
// Define the tool schema you'd like the model to use. | ||
const schema = z.object({ | ||
location: z.string().describe("The city and state, e.g. San Francisco, CA"), | ||
}); | ||
|
||
// Pass the schema to the withStructuredOutput method to bind it to the model. | ||
const modelWithTools = model.withStructuredOutput(schema, { | ||
name: "get_current_weather", | ||
}); | ||
|
||
const result = await modelWithTools.invoke( | ||
"What's the weather like today in San Francisco? Ensure you use the 'get_current_weather' tool." | ||
); | ||
console.log(result); | ||
/* | ||
{ location: 'San Francisco, CA' } | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module.exports = { | ||
extends: [ | ||
"airbnb-base", | ||
"eslint:recommended", | ||
"prettier", | ||
"plugin:@typescript-eslint/recommended", | ||
], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
parser: "@typescript-eslint/parser", | ||
project: "./tsconfig.json", | ||
sourceType: "module", | ||
}, | ||
plugins: ["@typescript-eslint", "no-instanceof"], | ||
ignorePatterns: [ | ||
".eslintrc.cjs", | ||
"scripts", | ||
"node_modules", | ||
"dist", | ||
"dist-cjs", | ||
"*.js", | ||
"*.cjs", | ||
"*.d.ts", | ||
], | ||
rules: { | ||
"no-process-env": 2, | ||
"no-instanceof/no-instanceof": 2, | ||
"@typescript-eslint/explicit-module-boundary-types": 0, | ||
"@typescript-eslint/no-empty-function": 0, | ||
"@typescript-eslint/no-shadow": 0, | ||
"@typescript-eslint/no-empty-interface": 0, | ||
"@typescript-eslint/no-use-before-define": ["error", "nofunc"], | ||
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }], | ||
"@typescript-eslint/no-floating-promises": "error", | ||
"@typescript-eslint/no-misused-promises": "error", | ||
camelcase: 0, | ||
"class-methods-use-this": 0, | ||
"import/extensions": [2, "ignorePackages"], | ||
"import/no-extraneous-dependencies": [ | ||
"error", | ||
{ devDependencies: ["**/*.test.ts"] }, | ||
], | ||
"import/no-unresolved": 0, | ||
"import/prefer-default-export": 0, | ||
"keyword-spacing": "error", | ||
"max-classes-per-file": 0, | ||
"max-len": 0, | ||
"no-await-in-loop": 0, | ||
"no-bitwise": 0, | ||
"no-console": 0, | ||
"no-restricted-syntax": 0, | ||
"no-shadow": 0, | ||
"no-continue": 0, | ||
"no-void": 0, | ||
"no-underscore-dangle": 0, | ||
"no-use-before-define": 0, | ||
"no-useless-constructor": 0, | ||
"no-return-await": 0, | ||
"consistent-return": 0, | ||
"no-else-return": 0, | ||
"func-names": 0, | ||
"no-lonely-if": 0, | ||
"prefer-rest-params": 0, | ||
"new-cap": ["error", { properties: false, capIsNew: false }], | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["**/*.test.ts"], | ||
rules: { | ||
"@typescript-eslint/no-unused-vars": "off", | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
index.cjs | ||
index.js | ||
index.d.ts | ||
index.d.cts | ||
node_modules | ||
dist | ||
.yarn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/prettierrc", | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"quoteProps": "as-needed", | ||
"jsxSingleQuote": false, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"arrowParens": "always", | ||
"requirePragma": false, | ||
"insertPragma": false, | ||
"proseWrap": "preserve", | ||
"htmlWhitespaceSensitivity": "css", | ||
"vueIndentScriptAndStyle": false, | ||
"endOfLine": "lf" | ||
} |
Oops, something went wrong.