@@ -11,6 +11,7 @@ import { createMockStream } from './mocks/MockStream'
11
11
import { createFileSearchTool } from './util'
12
12
import { FileSearchResultsStore } from '../../services/azureFileSearch/fileSearchResultsStore'
13
13
import { getAzureOpenAIClient } from './client'
14
+ import { RagIndex } from '../../db/models'
14
15
15
16
const client = getAzureOpenAIClient ( process . env . GPT_4O_MINI ?? '' )
16
17
@@ -27,43 +28,40 @@ export class ResponsesClient {
27
28
temperature : number
28
29
tools : FileSearchTool [ ]
29
30
user : User
30
- ragIndexId ?: number
31
+ ragIndex ?: RagIndex
31
32
32
33
constructor ( {
33
34
model,
34
35
temperature,
35
- vectorStoreId,
36
36
instructions,
37
37
user,
38
- ragIndexId ,
38
+ ragIndex ,
39
39
} : {
40
40
model : string
41
41
temperature : number
42
- vectorStoreId ?: string
43
42
instructions ?: string
44
43
user : User
45
- ragIndexId ?: number
44
+ ragIndex ?: RagIndex
46
45
} ) {
47
46
const selectedModel = validModels . find ( ( m ) => m . name === model ) ?. deployment
48
47
49
48
if ( ! selectedModel ) throw new Error ( `Invalid model: ${ model } , not one of ${ validModels . map ( ( m ) => m . name ) . join ( ', ' ) } ` )
50
49
51
- const fileSearchTool =
52
- vectorStoreId && ragIndexId
53
- ? [
54
- createFileSearchTool ( {
55
- vectorStoreId,
56
- filters : { key : 'ragIndexId' , value : ragIndexId , type : 'eq' } ,
57
- } ) ,
58
- ]
59
- : [ ] // needs to retrun empty array for null
50
+ const fileSearchTool = ragIndex
51
+ ? [
52
+ createFileSearchTool ( {
53
+ vectorStoreId : ragIndex . metadata . azureVectorStoreId ,
54
+ filters : { key : 'ragIndexFilterValue' , value : ragIndex . metadata . ragIndexFilterValue , type : 'eq' } ,
55
+ } ) ,
56
+ ]
57
+ : [ ] // needs to retrun empty array for null
60
58
61
59
this . model = selectedModel
62
60
this . temperature = temperature
63
61
this . instructions = instructions ?? ''
64
62
this . tools = fileSearchTool
65
63
this . user = user
66
- this . ragIndexId = ragIndexId
64
+ this . ragIndex = ragIndex
67
65
}
68
66
69
67
async createResponse ( {
@@ -145,7 +143,7 @@ export class ResponsesClient {
145
143
146
144
case 'response.output_item.done' : {
147
145
if ( event . item . type === 'file_search_call' ) {
148
- if ( ! this . ragIndexId ) throw new Error ( 'how is this possible. you managed to invoke file search without ragIndexId' )
146
+ if ( ! this . ragIndex ) throw new Error ( 'how is this possible. you managed to invoke file search without ragIndexId' )
149
147
150
148
if ( event . item . results ) {
151
149
await FileSearchResultsStore . saveResults ( event . item . id , event . item . results , this . user )
@@ -159,7 +157,7 @@ export class ResponsesClient {
159
157
queries : event . item . queries ,
160
158
status : event . item . status ,
161
159
type : event . item . type ,
162
- ragIndexId : this . ragIndexId ,
160
+ ragIndexId : this . ragIndex . id ,
163
161
} ,
164
162
} ,
165
163
res ,
0 commit comments