1
- import type { BaseChatModel } from '@langchain/core/language_models/chat_models'
1
+ import type { BaseChatModel , BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'
2
2
import type { AIMessageChunk , BaseMessageLike } from '@langchain/core/messages'
3
3
import type { StructuredTool } from '@langchain/core/tools'
4
4
import { concat } from '@langchain/core/utils/stream'
@@ -11,8 +11,12 @@ import type { User } from '../../../shared/user'
11
11
import { AZURE_API_KEY , AZURE_RESOURCE } from '../../util/config'
12
12
import { ToolResultStore } from './fileSearchResultsStore'
13
13
import { MockModel } from './MockModel'
14
+ import { Runnable } from '@langchain/core/runnables'
15
+ import { BaseLanguageModelInput } from '@langchain/core/language_models/base'
14
16
15
- const getChatModel = ( model : string , tools : StructuredTool [ ] ) : BaseChatModel => {
17
+ type ChatModel = Runnable < BaseLanguageModelInput , AIMessageChunk , BaseChatModelCallOptions >
18
+
19
+ const getChatModel = ( model : string , tools : StructuredTool [ ] ) : ChatModel => {
16
20
const deploymentName = validModels . find ( ( m ) => m . name === model ) ?. deployment
17
21
if ( ! deploymentName ) {
18
22
throw new Error ( `Invalid model: ${ model } ` )
@@ -29,9 +33,7 @@ const getChatModel = (model: string, tools: StructuredTool[]): BaseChatModel =>
29
33
azureOpenAIApiInstanceName : AZURE_RESOURCE ,
30
34
} )
31
35
32
- chatModel . bindTools ( tools )
33
-
34
- return chatModel
36
+ return chatModel . bindTools ( tools )
35
37
}
36
38
37
39
type WriteEventFunction = ( data : ChatEvent ) => Promise < void >
@@ -92,13 +94,7 @@ export const streamChat = async ({
92
94
}
93
95
}
94
96
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 ) => {
102
98
const stream = await model . stream ( messages )
103
99
104
100
const startTS = Date . now ( )
0 commit comments