File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
server/services/langchain Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ import type { ChatToolOutput } from '../../../shared/tools'
2
+ import type { User } from '../../../shared/user'
3
+ import { redisClient } from '../../util/redis'
4
+
5
+ export const ToolResultStore = {
6
+ getKey ( user : User , fileSearchId : string ) : string {
7
+ return `user-${ user . id } :fileSearch-${ fileSearchId } `
8
+ } ,
9
+
10
+ async saveResults ( fileSearchId : string , results : ChatToolOutput , user : User ) {
11
+ const key = this . getKey ( user , fileSearchId )
12
+ await redisClient . set ( key , JSON . stringify ( results ) , {
13
+ EX : 60 * 60 * 24 * 365 , // 365 day expiration time
14
+ } )
15
+ } ,
16
+ async getResults ( fileSearchId : string , user : User ) : Promise < ChatToolOutput | null > {
17
+ const key = this . getKey ( user , fileSearchId )
18
+ const results = ( await redisClient . get ( key ) ) as string
19
+ return results ? JSON . parse ( results ) : null
20
+ } ,
21
+ }
Original file line number Diff line number Diff line change
1
+ import type { ChatToolDef } from './tools'
2
+
3
+ /**
4
+ * Event emitted when text is added to a chat message
5
+ */
6
+ export type WritingEvent = {
7
+ type : 'writing'
8
+ text : string
9
+ }
10
+
11
+ export type CompleteEvent = {
12
+ type : 'complete'
13
+ prevResponseId : string // Not yet sure what to put here in v3
14
+ }
15
+
16
+ export type ToolCallStatusEvent = {
17
+ type : 'toolCallStatus'
18
+ callId : string
19
+ toolName : ChatToolDef [ 'name' ]
20
+ text : string
21
+ input ?: ChatToolDef [ 'input' ]
22
+ }
23
+
24
+ export type ToolCallResultEvent = ToolCallStatusEvent & {
25
+ input : ChatToolDef [ 'input' ]
26
+ result : ChatToolDef [ 'result' ]
27
+ }
28
+
29
+ export type ErrorEvent = {
30
+ type : 'error'
31
+ error : string
32
+ }
33
+
34
+ export type ChatEvent = WritingEvent | CompleteEvent | ToolCallStatusEvent | ToolCallResultEvent | ErrorEvent
You can’t perform that action at this time.
0 commit comments