Skip to content

Commit 2421afe

Browse files
committed
fix: discrepancy between mock / azure model tool binding
1 parent 6564838 commit 2421afe

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/server/services/langchain/MockModel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import { AIMessage, AIMessageChunk, type BaseMessage, isHumanMessage, isSystemMe
33
import type { ChatGenerationChunk, ChatResult } from '@langchain/core/outputs'
44
import { FakeStreamingChatModel } from '@langchain/core/utils/testing'
55
import { basicTestContent } from '../../util/azure/mocks/mockContent'
6+
import { StructuredTool } from '@langchain/core/tools'
67

78
/**
89
* See https://github.com/langchain-ai/langchainjs/blob/fe79533d36ddf92b830ea231297b522fce1c538f/langchain-core/src/utils/testing/index.ts#L219
910
*
1011
* FakeStreamingChatModel echoes the first input message out of the box.
1112
*/
1213
export class MockModel extends FakeStreamingChatModel {
13-
constructor() {
14+
constructor(tools: StructuredTool[]) {
1415
super({
1516
sleep: 5,
1617
})
18+
this.bindTools(tools)
1719
}
1820

1921
setupTestResponse(messages: BaseMessage[]) {

src/server/services/langchain/chat.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import type { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'
1+
import type { BaseLanguageModelInput } from '@langchain/core/language_models/base'
2+
import type { BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'
23
import type { AIMessageChunk, BaseMessageLike } from '@langchain/core/messages'
4+
import type { Runnable } from '@langchain/core/runnables'
35
import type { StructuredTool } from '@langchain/core/tools'
46
import { concat } from '@langchain/core/utils/stream'
57
import { AzureChatOpenAI } from '@langchain/openai'
@@ -11,8 +13,6 @@ import type { User } from '../../../shared/user'
1113
import { AZURE_API_KEY, AZURE_RESOURCE } from '../../util/config'
1214
import { ToolResultStore } from './fileSearchResultsStore'
1315
import { MockModel } from './MockModel'
14-
import { Runnable } from '@langchain/core/runnables'
15-
import { BaseLanguageModelInput } from '@langchain/core/language_models/base'
1616

1717
type ChatModel = Runnable<BaseLanguageModelInput, AIMessageChunk, BaseChatModelCallOptions>
1818

@@ -24,16 +24,16 @@ const getChatModel = (model: string, tools: StructuredTool[]): ChatModel => {
2424

2525
const chatModel =
2626
deploymentName === 'mock'
27-
? new MockModel()
27+
? new MockModel(tools)
2828
: new AzureChatOpenAI({
2929
model,
3030
azureOpenAIApiKey: AZURE_API_KEY,
3131
azureOpenAIApiVersion: '2023-05-15',
3232
azureOpenAIApiDeploymentName: deploymentName,
3333
azureOpenAIApiInstanceName: AZURE_RESOURCE,
34-
})
34+
}).bindTools(tools)
3535

36-
return chatModel.bindTools(tools)
36+
return chatModel
3737
}
3838

3939
type WriteEventFunction = (data: ChatEvent) => Promise<void>
@@ -164,7 +164,12 @@ const chatTurn = async (model: ChatModel, messages: BaseMessageLike[], toolsByNa
164164
callId: id,
165165
text: `Completed search for '${input.query}'`,
166166
input,
167-
result: { files: artifact.map((chunk) => ({ fileName: chunk.metadata.ragFileName, score: chunk.score })) },
167+
result: {
168+
files: artifact.map((chunk) => ({
169+
fileName: chunk.metadata.ragFileName,
170+
score: chunk.score,
171+
})),
172+
},
168173
})
169174
}
170175
}

0 commit comments

Comments
 (0)