Skip to content

Commit 6564838

Browse files
committed
fix: Tools not actually being binded to the model in use
1 parent 0a38e23 commit 6564838

File tree

1 file changed

+8
-12
lines changed
  • src/server/services/langchain

1 file changed

+8
-12
lines changed

src/server/services/langchain/chat.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BaseChatModel } from '@langchain/core/language_models/chat_models'
1+
import type { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'
22
import type { AIMessageChunk, BaseMessageLike } from '@langchain/core/messages'
33
import type { StructuredTool } from '@langchain/core/tools'
44
import { concat } from '@langchain/core/utils/stream'
@@ -11,8 +11,12 @@ import type { User } from '../../../shared/user'
1111
import { AZURE_API_KEY, AZURE_RESOURCE } from '../../util/config'
1212
import { ToolResultStore } from './fileSearchResultsStore'
1313
import { MockModel } from './MockModel'
14+
import { Runnable } from '@langchain/core/runnables'
15+
import { BaseLanguageModelInput } from '@langchain/core/language_models/base'
1416

15-
const getChatModel = (model: string, tools: StructuredTool[]): BaseChatModel => {
17+
type ChatModel = Runnable<BaseLanguageModelInput, AIMessageChunk, BaseChatModelCallOptions>
18+
19+
const getChatModel = (model: string, tools: StructuredTool[]): ChatModel => {
1620
const deploymentName = validModels.find((m) => m.name === model)?.deployment
1721
if (!deploymentName) {
1822
throw new Error(`Invalid model: ${model}`)
@@ -29,9 +33,7 @@ const getChatModel = (model: string, tools: StructuredTool[]): BaseChatModel =>
2933
azureOpenAIApiInstanceName: AZURE_RESOURCE,
3034
})
3135

32-
chatModel.bindTools(tools)
33-
34-
return chatModel
36+
return chatModel.bindTools(tools)
3537
}
3638

3739
type WriteEventFunction = (data: ChatEvent) => Promise<void>
@@ -92,13 +94,7 @@ export const streamChat = async ({
9294
}
9395
}
9496

95-
const chatTurn = async (
96-
model: BaseChatModel,
97-
messages: BaseMessageLike[],
98-
toolsByName: Record<string, ChatTool>,
99-
writeEvent: WriteEventFunction,
100-
user: User,
101-
) => {
97+
const chatTurn = async (model: ChatModel, messages: BaseMessageLike[], toolsByName: Record<string, ChatTool>, writeEvent: WriteEventFunction, user: User) => {
10298
const stream = await model.stream(messages)
10399

104100
const startTS = Date.now()

0 commit comments

Comments
 (0)