1
- import { AzureChatOpenAI } from '@langchain/openai'
2
- import { AZURE_API_KEY , AZURE_RESOURCE } from '../../util/config'
3
- import { validModels } from '../../../config'
4
- import { ChatMessage , Message } from '../../../shared/llmTypes'
5
- import { Response } from 'express'
6
- import { AIMessageChunk , BaseMessage , BaseMessageLike } from '@langchain/core/messages'
7
- import { IterableReadableStream } from '@langchain/core/utils/stream'
8
- import { ResponseStreamEventData } from '../../../shared/types'
9
- import { Tiktoken } from '@dqbd/tiktoken'
10
- import { FakeStreamingChatModel } from '@langchain/core/utils/testing'
11
- import { MockModel } from './MockModel'
1
+ import { BaseChatModel } from '@langchain/core/language_models/chat_models'
2
+ import { AIMessageChunk , BaseMessageLike } from '@langchain/core/messages'
12
3
import { StructuredTool } from '@langchain/core/tools'
13
4
import { concat } from '@langchain/core/utils/stream'
14
- import { BaseChatModel } from '@langchain/core/language_models/chat_models'
15
- import { Runnable } from '@langchain/core/runnables'
16
- import logger from '../../util/logger'
17
- import { BaseLanguageModelInput } from '@langchain/core/language_models/base'
18
- import { ToolCall } from '@langchain/core/messages/tool'
5
+ import { AzureChatOpenAI } from '@langchain/openai'
6
+ import { validModels } from '../../../config'
7
+ import { ChatEvent } from '../../../shared/chat'
8
+ import { ChatMessage } from '../../../shared/llmTypes'
19
9
import { ChatToolDef } from '../../../shared/tools'
10
+ import { AZURE_API_KEY , AZURE_RESOURCE } from '../../util/config'
11
+ import { MockModel } from './MockModel'
20
12
21
13
const getChatModel = ( model : string , tools : StructuredTool [ ] ) : BaseChatModel => {
22
14
const deploymentName = validModels . find ( ( m ) => m . name === model ) ?. deployment
@@ -37,7 +29,7 @@ const getChatModel = (model: string, tools: StructuredTool[]): BaseChatModel =>
37
29
} ) . bindTools ( tools ) as BaseChatModel
38
30
}
39
31
40
- type WriteEventFunction = ( data : ResponseStreamEventData ) => Promise < void >
32
+ type WriteEventFunction = ( data : ChatEvent ) => Promise < void >
41
33
42
34
type ChatTool = StructuredTool < any , any , any , string >
43
35
@@ -115,9 +107,10 @@ const chatTurn = async (model: BaseChatModel, messages: BaseMessageLike[], tools
115
107
status : 'pending' ,
116
108
}
117
109
await writeEvent ( {
118
- type : 'toolCallStarting' ,
119
- name : toolCall . name as ChatToolDef [ 'name' ] ,
120
- id,
110
+ type : 'toolCallStatus' ,
111
+ toolName : toolCall . name as ChatToolDef [ 'name' ] ,
112
+ callId : id ,
113
+ text : 'Starting' ,
121
114
} )
122
115
}
123
116
}
@@ -143,21 +136,25 @@ const chatTurn = async (model: BaseChatModel, messages: BaseMessageLike[], tools
143
136
const input = toolCall . args as ChatToolDef [ 'input' ]
144
137
if ( id && tool ) {
145
138
await writeEvent ( {
146
- type : 'toolCallStarted ' ,
147
- name,
148
- input ,
149
- id ,
139
+ type : 'toolCallStatus ' ,
140
+ toolName : name ,
141
+ callId : id ,
142
+ text : `Searching for ' ${ input . query } '` ,
150
143
} )
151
144
const result = await tool . invoke ( toolCall )
152
145
messages . push ( result )
153
146
toolCallStatuses [ id ] = {
154
147
status : 'completed' ,
155
148
}
156
149
await writeEvent ( {
157
- type : 'toolCallCompleted' ,
158
- name,
159
- artifacts : result . artifact ,
160
- id,
150
+ type : 'toolCallStatus' ,
151
+ toolName : name ,
152
+ callId : id ,
153
+ text : 'Completed search' ,
154
+ result : {
155
+ artifacts : result . artifact ,
156
+ input,
157
+ } ,
161
158
} )
162
159
}
163
160
}
0 commit comments