Skip to content

Commit be4ed5e

Browse files
Merge pull request #348 from UniversityOfHelsinkiCS/langchain-rag
Langchain rag
2 parents 2dbbb86 + 5fa4a86 commit be4ed5e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

src/shared/chat.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

0 commit comments

Comments
 (0)