Skip to content

Commit 3e54d53

Browse files
authored
Feat/update ollama for function calling (#2892)
update ollama for function calling
1 parent 1338501 commit 3e54d53

File tree

12 files changed

+235
-190
lines changed

12 files changed

+235
-190
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
"onlyBuiltDependencies": [
5757
"faiss-node",
5858
"sqlite3"
59-
]
59+
],
60+
"overrides": {
61+
"@langchain/core": "0.2.18"
62+
}
6063
},
6164
"engines": {
6265
"node": ">=18.15.0 <19.0.0 || ^20",

packages/components/nodes/chatmodels/ChatOllama/ChatOllama.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { ChatOllama } from '@langchain/community/chat_models/ollama'
1+
import { ChatOllama, ChatOllamaInput } from '@langchain/ollama'
2+
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
23
import { BaseCache } from '@langchain/core/caches'
34
import { INode, INodeData, INodeParams } from '../../../src/Interface'
45
import { getBaseClasses } from '../../../src/utils'
5-
import { OllamaInput } from '@langchain/community/llms/ollama'
6-
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
76

87
class ChatOllama_ChatModels implements INode {
98
label: string
@@ -20,7 +19,7 @@ class ChatOllama_ChatModels implements INode {
2019
constructor() {
2120
this.label = 'ChatOllama'
2221
this.name = 'chatOllama'
23-
this.version = 2.0
22+
this.version = 3.0
2423
this.type = 'ChatOllama'
2524
this.icon = 'Ollama.svg'
2625
this.category = 'Chat Models'
@@ -55,6 +54,15 @@ class ChatOllama_ChatModels implements INode {
5554
default: 0.9,
5655
optional: true
5756
},
57+
{
58+
label: 'Keep Alive',
59+
name: 'keepAlive',
60+
type: 'string',
61+
description: 'How long to keep connection alive. A duration string (such as "10m" or "24h")',
62+
default: '5m',
63+
optional: true,
64+
additionalParams: true
65+
},
5866
{
5967
label: 'Top P',
6068
name: 'topP',
@@ -115,16 +123,6 @@ class ChatOllama_ChatModels implements INode {
115123
optional: true,
116124
additionalParams: true
117125
},
118-
{
119-
label: 'Number of GQA groups',
120-
name: 'numGqa',
121-
type: 'number',
122-
description:
123-
'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',
124-
step: 1,
125-
optional: true,
126-
additionalParams: true
127-
},
128126
{
129127
label: 'Number of GPU',
130128
name: 'numGpu',
@@ -199,17 +197,16 @@ class ChatOllama_ChatModels implements INode {
199197
const mirostatEta = nodeData.inputs?.mirostatEta as string
200198
const mirostatTau = nodeData.inputs?.mirostatTau as string
201199
const numCtx = nodeData.inputs?.numCtx as string
202-
const numGqa = nodeData.inputs?.numGqa as string
200+
const keepAlive = nodeData.inputs?.keepAlive as string
203201
const numGpu = nodeData.inputs?.numGpu as string
204202
const numThread = nodeData.inputs?.numThread as string
205203
const repeatLastN = nodeData.inputs?.repeatLastN as string
206204
const repeatPenalty = nodeData.inputs?.repeatPenalty as string
207-
const stop = nodeData.inputs?.stop as string
208205
const tfsZ = nodeData.inputs?.tfsZ as string
209206

210207
const cache = nodeData.inputs?.cache as BaseCache
211208

212-
const obj: OllamaInput & BaseChatModelParams = {
209+
const obj: ChatOllamaInput & BaseChatModelParams = {
213210
baseUrl,
214211
temperature: parseFloat(temperature),
215212
model: modelName
@@ -221,16 +218,12 @@ class ChatOllama_ChatModels implements INode {
221218
if (mirostatEta) obj.mirostatEta = parseFloat(mirostatEta)
222219
if (mirostatTau) obj.mirostatTau = parseFloat(mirostatTau)
223220
if (numCtx) obj.numCtx = parseFloat(numCtx)
224-
if (numGqa) obj.numGqa = parseFloat(numGqa)
225221
if (numGpu) obj.numGpu = parseFloat(numGpu)
226222
if (numThread) obj.numThread = parseFloat(numThread)
227223
if (repeatLastN) obj.repeatLastN = parseFloat(repeatLastN)
228224
if (repeatPenalty) obj.repeatPenalty = parseFloat(repeatPenalty)
229225
if (tfsZ) obj.tfsZ = parseFloat(tfsZ)
230-
if (stop) {
231-
const stopSequences = stop.split(',')
232-
obj.stop = stopSequences
233-
}
226+
if (keepAlive) obj.keepAlive = keepAlive
234227
if (cache) obj.cache = cache
235228

236229
const model = new ChatOllama(obj)

packages/components/nodes/chatmodels/ChatOllamaFunction/ChatOllamaFunction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ChatOllamaFunction_ChatModels implements INode {
4343
this.type = 'ChatOllamaFunction'
4444
this.icon = 'Ollama.svg'
4545
this.category = 'Chat Models'
46+
this.badge = 'DEPRECATING'
4647
this.description = 'Run open-source function-calling compatible LLM on Ollama'
4748
this.baseClasses = [this.type, ...getBaseClasses(OllamaFunctions)]
4849
this.inputs = [

packages/components/nodes/memory/MongoDBMemory/MongoDBMemory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
111111
sessionId
112112
})
113113

114+
// @ts-ignore
114115
mongoDBChatMessageHistory.getMessages = async (): Promise<BaseMessage[]> => {
115116
const document = await collection.findOne({
116117
sessionId: (mongoDBChatMessageHistory as any).sessionId
@@ -119,6 +120,7 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
119120
return messages.map(mapStoredMessageToChatMessage)
120121
}
121122

123+
// @ts-ignore
122124
mongoDBChatMessageHistory.addMessage = async (message: BaseMessage): Promise<void> => {
123125
const messages = [message].map((msg) => msg.toDict())
124126
await collection.updateOne(
@@ -136,6 +138,7 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
136138

137139
return new BufferMemoryExtended({
138140
memoryKey: memoryKey ?? 'chat_history',
141+
// @ts-ignore
139142
chatHistory: mongoDBChatMessageHistory,
140143
sessionId,
141144
collection

packages/components/nodes/outputparsers/StructuredOutputParser/StructuredOutputParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class StructuredOutputParser implements INode {
7171
const autoFix = nodeData.inputs?.autofixParser as boolean
7272

7373
try {
74-
const structuredOutputParser = LangchainStructuredOutputParser.fromZodSchema(z.object(convertSchemaToZod(jsonStructure)))
74+
const zodSchema = z.object(convertSchemaToZod(jsonStructure)) as any
75+
const structuredOutputParser = LangchainStructuredOutputParser.fromZodSchema(zodSchema)
7576

7677
// NOTE: When we change Flowise to return a json response, the following has to be changed to: JsonStructuredOutputParser
7778
Object.defineProperty(structuredOutputParser, 'autoFix', {

packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class ChatflowTool extends StructuredTool {
174174

175175
schema = z.object({
176176
input: z.string().describe('input question')
177-
})
177+
}) as any
178178

179179
constructor({
180180
name,

packages/components/nodes/tools/CustomTool/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class DynamicStructuredTool<
4242

4343
func: DynamicStructuredToolInput['func']
4444

45+
// @ts-ignore
4546
schema: T
4647
private variables: any[]
4748
private flowObj: any

packages/components/nodes/tools/ReadFile/ReadFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ReadFileTool extends StructuredTool {
6363

6464
schema = z.object({
6565
file_path: z.string().describe('name of file')
66-
})
66+
}) as any
6767

6868
name = 'read_file'
6969

packages/components/nodes/tools/RetrieverTool/RetrieverTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Retriever_Tools implements INode {
7777

7878
const schema = z.object({
7979
input: z.string().describe('input to look up in retriever')
80-
})
80+
}) as any
8181

8282
const tool = new DynamicStructuredTool({ ...input, func, schema })
8383
return tool

packages/components/nodes/tools/WriteFile/WriteFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class WriteFileTool extends StructuredTool {
6464
schema = z.object({
6565
file_path: z.string().describe('name of file'),
6666
text: z.string().describe('text to write to file')
67-
})
67+
}) as any
6868

6969
name = 'write_file'
7070

0 commit comments

Comments
 (0)