Feat/update ollama for function calling (#2892)
update ollama for function calling
This commit is contained in:
parent
1338501658
commit
3e54d53692
|
|
@ -56,7 +56,10 @@
|
||||||
"onlyBuiltDependencies": [
|
"onlyBuiltDependencies": [
|
||||||
"faiss-node",
|
"faiss-node",
|
||||||
"sqlite3"
|
"sqlite3"
|
||||||
]
|
],
|
||||||
|
"overrides": {
|
||||||
|
"@langchain/core": "0.2.18"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.15.0 <19.0.0 || ^20",
|
"node": ">=18.15.0 <19.0.0 || ^20",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { ChatOllama } from '@langchain/community/chat_models/ollama'
|
import { ChatOllama, ChatOllamaInput } from '@langchain/ollama'
|
||||||
|
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
|
||||||
import { BaseCache } from '@langchain/core/caches'
|
import { BaseCache } from '@langchain/core/caches'
|
||||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
import { getBaseClasses } from '../../../src/utils'
|
import { getBaseClasses } from '../../../src/utils'
|
||||||
import { OllamaInput } from '@langchain/community/llms/ollama'
|
|
||||||
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
|
|
||||||
|
|
||||||
class ChatOllama_ChatModels implements INode {
|
class ChatOllama_ChatModels implements INode {
|
||||||
label: string
|
label: string
|
||||||
|
|
@ -20,7 +19,7 @@ class ChatOllama_ChatModels implements INode {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'ChatOllama'
|
this.label = 'ChatOllama'
|
||||||
this.name = 'chatOllama'
|
this.name = 'chatOllama'
|
||||||
this.version = 2.0
|
this.version = 3.0
|
||||||
this.type = 'ChatOllama'
|
this.type = 'ChatOllama'
|
||||||
this.icon = 'Ollama.svg'
|
this.icon = 'Ollama.svg'
|
||||||
this.category = 'Chat Models'
|
this.category = 'Chat Models'
|
||||||
|
|
@ -55,6 +54,15 @@ class ChatOllama_ChatModels implements INode {
|
||||||
default: 0.9,
|
default: 0.9,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Keep Alive',
|
||||||
|
name: 'keepAlive',
|
||||||
|
type: 'string',
|
||||||
|
description: 'How long to keep connection alive. A duration string (such as "10m" or "24h")',
|
||||||
|
default: '5m',
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Top P',
|
label: 'Top P',
|
||||||
name: 'topP',
|
name: 'topP',
|
||||||
|
|
@ -115,16 +123,6 @@ class ChatOllama_ChatModels implements INode {
|
||||||
optional: true,
|
optional: true,
|
||||||
additionalParams: true
|
additionalParams: true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: 'Number of GQA groups',
|
|
||||||
name: 'numGqa',
|
|
||||||
type: 'number',
|
|
||||||
description:
|
|
||||||
'The number of GQA groups in the transformer layer. Required for some models, for example it is 8 for llama2:70b. Refer to <a target="_blank" href="https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values">docs</a> for more details',
|
|
||||||
step: 1,
|
|
||||||
optional: true,
|
|
||||||
additionalParams: true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Number of GPU',
|
label: 'Number of GPU',
|
||||||
name: 'numGpu',
|
name: 'numGpu',
|
||||||
|
|
@ -199,17 +197,16 @@ class ChatOllama_ChatModels implements INode {
|
||||||
const mirostatEta = nodeData.inputs?.mirostatEta as string
|
const mirostatEta = nodeData.inputs?.mirostatEta as string
|
||||||
const mirostatTau = nodeData.inputs?.mirostatTau as string
|
const mirostatTau = nodeData.inputs?.mirostatTau as string
|
||||||
const numCtx = nodeData.inputs?.numCtx as string
|
const numCtx = nodeData.inputs?.numCtx as string
|
||||||
const numGqa = nodeData.inputs?.numGqa as string
|
const keepAlive = nodeData.inputs?.keepAlive as string
|
||||||
const numGpu = nodeData.inputs?.numGpu as string
|
const numGpu = nodeData.inputs?.numGpu as string
|
||||||
const numThread = nodeData.inputs?.numThread as string
|
const numThread = nodeData.inputs?.numThread as string
|
||||||
const repeatLastN = nodeData.inputs?.repeatLastN as string
|
const repeatLastN = nodeData.inputs?.repeatLastN as string
|
||||||
const repeatPenalty = nodeData.inputs?.repeatPenalty as string
|
const repeatPenalty = nodeData.inputs?.repeatPenalty as string
|
||||||
const stop = nodeData.inputs?.stop as string
|
|
||||||
const tfsZ = nodeData.inputs?.tfsZ as string
|
const tfsZ = nodeData.inputs?.tfsZ as string
|
||||||
|
|
||||||
const cache = nodeData.inputs?.cache as BaseCache
|
const cache = nodeData.inputs?.cache as BaseCache
|
||||||
|
|
||||||
const obj: OllamaInput & BaseChatModelParams = {
|
const obj: ChatOllamaInput & BaseChatModelParams = {
|
||||||
baseUrl,
|
baseUrl,
|
||||||
temperature: parseFloat(temperature),
|
temperature: parseFloat(temperature),
|
||||||
model: modelName
|
model: modelName
|
||||||
|
|
@ -221,16 +218,12 @@ class ChatOllama_ChatModels implements INode {
|
||||||
if (mirostatEta) obj.mirostatEta = parseFloat(mirostatEta)
|
if (mirostatEta) obj.mirostatEta = parseFloat(mirostatEta)
|
||||||
if (mirostatTau) obj.mirostatTau = parseFloat(mirostatTau)
|
if (mirostatTau) obj.mirostatTau = parseFloat(mirostatTau)
|
||||||
if (numCtx) obj.numCtx = parseFloat(numCtx)
|
if (numCtx) obj.numCtx = parseFloat(numCtx)
|
||||||
if (numGqa) obj.numGqa = parseFloat(numGqa)
|
|
||||||
if (numGpu) obj.numGpu = parseFloat(numGpu)
|
if (numGpu) obj.numGpu = parseFloat(numGpu)
|
||||||
if (numThread) obj.numThread = parseFloat(numThread)
|
if (numThread) obj.numThread = parseFloat(numThread)
|
||||||
if (repeatLastN) obj.repeatLastN = parseFloat(repeatLastN)
|
if (repeatLastN) obj.repeatLastN = parseFloat(repeatLastN)
|
||||||
if (repeatPenalty) obj.repeatPenalty = parseFloat(repeatPenalty)
|
if (repeatPenalty) obj.repeatPenalty = parseFloat(repeatPenalty)
|
||||||
if (tfsZ) obj.tfsZ = parseFloat(tfsZ)
|
if (tfsZ) obj.tfsZ = parseFloat(tfsZ)
|
||||||
if (stop) {
|
if (keepAlive) obj.keepAlive = keepAlive
|
||||||
const stopSequences = stop.split(',')
|
|
||||||
obj.stop = stopSequences
|
|
||||||
}
|
|
||||||
if (cache) obj.cache = cache
|
if (cache) obj.cache = cache
|
||||||
|
|
||||||
const model = new ChatOllama(obj)
|
const model = new ChatOllama(obj)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class ChatOllamaFunction_ChatModels implements INode {
|
||||||
this.type = 'ChatOllamaFunction'
|
this.type = 'ChatOllamaFunction'
|
||||||
this.icon = 'Ollama.svg'
|
this.icon = 'Ollama.svg'
|
||||||
this.category = 'Chat Models'
|
this.category = 'Chat Models'
|
||||||
|
this.badge = 'DEPRECATING'
|
||||||
this.description = 'Run open-source function-calling compatible LLM on Ollama'
|
this.description = 'Run open-source function-calling compatible LLM on Ollama'
|
||||||
this.baseClasses = [this.type, ...getBaseClasses(OllamaFunctions)]
|
this.baseClasses = [this.type, ...getBaseClasses(OllamaFunctions)]
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
|
||||||
sessionId
|
sessionId
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
mongoDBChatMessageHistory.getMessages = async (): Promise<BaseMessage[]> => {
|
mongoDBChatMessageHistory.getMessages = async (): Promise<BaseMessage[]> => {
|
||||||
const document = await collection.findOne({
|
const document = await collection.findOne({
|
||||||
sessionId: (mongoDBChatMessageHistory as any).sessionId
|
sessionId: (mongoDBChatMessageHistory as any).sessionId
|
||||||
|
|
@ -119,6 +120,7 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
|
||||||
return messages.map(mapStoredMessageToChatMessage)
|
return messages.map(mapStoredMessageToChatMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
mongoDBChatMessageHistory.addMessage = async (message: BaseMessage): Promise<void> => {
|
mongoDBChatMessageHistory.addMessage = async (message: BaseMessage): Promise<void> => {
|
||||||
const messages = [message].map((msg) => msg.toDict())
|
const messages = [message].map((msg) => msg.toDict())
|
||||||
await collection.updateOne(
|
await collection.updateOne(
|
||||||
|
|
@ -136,6 +138,7 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
|
||||||
|
|
||||||
return new BufferMemoryExtended({
|
return new BufferMemoryExtended({
|
||||||
memoryKey: memoryKey ?? 'chat_history',
|
memoryKey: memoryKey ?? 'chat_history',
|
||||||
|
// @ts-ignore
|
||||||
chatHistory: mongoDBChatMessageHistory,
|
chatHistory: mongoDBChatMessageHistory,
|
||||||
sessionId,
|
sessionId,
|
||||||
collection
|
collection
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,8 @@ class StructuredOutputParser implements INode {
|
||||||
const autoFix = nodeData.inputs?.autofixParser as boolean
|
const autoFix = nodeData.inputs?.autofixParser as boolean
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const structuredOutputParser = LangchainStructuredOutputParser.fromZodSchema(z.object(convertSchemaToZod(jsonStructure)))
|
const zodSchema = z.object(convertSchemaToZod(jsonStructure)) as any
|
||||||
|
const structuredOutputParser = LangchainStructuredOutputParser.fromZodSchema(zodSchema)
|
||||||
|
|
||||||
// NOTE: When we change Flowise to return a json response, the following has to be changed to: JsonStructuredOutputParser
|
// NOTE: When we change Flowise to return a json response, the following has to be changed to: JsonStructuredOutputParser
|
||||||
Object.defineProperty(structuredOutputParser, 'autoFix', {
|
Object.defineProperty(structuredOutputParser, 'autoFix', {
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ class ChatflowTool extends StructuredTool {
|
||||||
|
|
||||||
schema = z.object({
|
schema = z.object({
|
||||||
input: z.string().describe('input question')
|
input: z.string().describe('input question')
|
||||||
})
|
}) as any
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ export class DynamicStructuredTool<
|
||||||
|
|
||||||
func: DynamicStructuredToolInput['func']
|
func: DynamicStructuredToolInput['func']
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
schema: T
|
schema: T
|
||||||
private variables: any[]
|
private variables: any[]
|
||||||
private flowObj: any
|
private flowObj: any
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ export class ReadFileTool extends StructuredTool {
|
||||||
|
|
||||||
schema = z.object({
|
schema = z.object({
|
||||||
file_path: z.string().describe('name of file')
|
file_path: z.string().describe('name of file')
|
||||||
})
|
}) as any
|
||||||
|
|
||||||
name = 'read_file'
|
name = 'read_file'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class Retriever_Tools implements INode {
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
input: z.string().describe('input to look up in retriever')
|
input: z.string().describe('input to look up in retriever')
|
||||||
})
|
}) as any
|
||||||
|
|
||||||
const tool = new DynamicStructuredTool({ ...input, func, schema })
|
const tool = new DynamicStructuredTool({ ...input, func, schema })
|
||||||
return tool
|
return tool
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ export class WriteFileTool extends StructuredTool {
|
||||||
schema = z.object({
|
schema = z.object({
|
||||||
file_path: z.string().describe('name of file'),
|
file_path: z.string().describe('name of file'),
|
||||||
text: z.string().describe('text to write to file')
|
text: z.string().describe('text to write to file')
|
||||||
})
|
}) as any
|
||||||
|
|
||||||
name = 'write_file'
|
name = 'write_file'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@
|
||||||
"@langchain/anthropic": "^0.2.1",
|
"@langchain/anthropic": "^0.2.1",
|
||||||
"@langchain/cohere": "^0.0.7",
|
"@langchain/cohere": "^0.0.7",
|
||||||
"@langchain/community": "^0.2.17",
|
"@langchain/community": "^0.2.17",
|
||||||
"@langchain/core": "^0.2.14",
|
|
||||||
"@langchain/exa": "^0.0.5",
|
"@langchain/exa": "^0.0.5",
|
||||||
"@langchain/google-genai": "^0.0.22",
|
"@langchain/google-genai": "^0.0.22",
|
||||||
"@langchain/google-vertexai": "^0.0.19",
|
"@langchain/google-vertexai": "^0.0.19",
|
||||||
|
|
@ -45,6 +44,7 @@
|
||||||
"@langchain/langgraph": "^0.0.22",
|
"@langchain/langgraph": "^0.0.22",
|
||||||
"@langchain/mistralai": "^0.0.26",
|
"@langchain/mistralai": "^0.0.26",
|
||||||
"@langchain/mongodb": "^0.0.1",
|
"@langchain/mongodb": "^0.0.1",
|
||||||
|
"@langchain/ollama": "^0.0.2",
|
||||||
"@langchain/openai": "^0.0.30",
|
"@langchain/openai": "^0.0.30",
|
||||||
"@langchain/pinecone": "^0.0.3",
|
"@langchain/pinecone": "^0.0.3",
|
||||||
"@langchain/qdrant": "^0.0.5",
|
"@langchain/qdrant": "^0.0.5",
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
"jsdom": "^22.1.0",
|
"jsdom": "^22.1.0",
|
||||||
"jsonpointer": "^5.0.1",
|
"jsonpointer": "^5.0.1",
|
||||||
"langchain": "^0.2.8",
|
"langchain": "^0.2.11",
|
||||||
"langfuse": "3.3.4",
|
"langfuse": "3.3.4",
|
||||||
"langfuse-langchain": "^3.3.4",
|
"langfuse-langchain": "^3.3.4",
|
||||||
"langsmith": "0.1.6",
|
"langsmith": "0.1.6",
|
||||||
|
|
|
||||||
817
pnpm-lock.yaml
817
pnpm-lock.yaml
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue