@@ -48,7 +48,7 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
48
48
try :
49
49
50
50
llm = ChatOpenAI (model = model , temperature =0 , api _key =apiKey )
51
- embeddings = OpenAIEmbeddings ()
51
+ embeddings = OpenAIEmbeddings (openai _ api _ key = apiKey )
52
52
53
53
vectorstore = IRISVector .from _documents (
54
54
embedding _function =embeddings ,
@@ -116,8 +116,8 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
116
116
)
117
117
118
118
return json .dumps ({" answer" : ai _msg _1 ['answer '], " context" : ai _msg _1 ['context ']})
119
- except :
120
- return json .dumps ({" error" : " API ERROR " })
119
+ except Exception as err :
120
+ return json .dumps ({" error" : str ( err ) })
121
121
}
122
122
123
123
ClassMethod Ingest (apiKey As %String , collectionName As %String , filePath As %String , model As %String = " gpt-3.5-turbo-0125" ) As %String [ Language = python ]
@@ -135,9 +135,6 @@ ClassMethod Ingest(apiKey As %String, collectionName As %String, filePath As %St
135
135
from langchain _text _splitters import RecursiveCharacterTextSplitter
136
136
137
137
try :
138
- llm = ChatOpenAI (model =model , temperature =0 , api _key =apiKey )
139
- embeddings = OpenAIEmbeddings ()
140
-
141
138
loader = CSVLoader (file _path = filePath )
142
139
docs = loader .load ()
143
140
@@ -146,16 +143,16 @@ ClassMethod Ingest(apiKey As %String, collectionName As %String, filePath As %St
146
143
147
144
vectorstore = IRISVector .from _documents (
148
145
documents =splits ,
149
- embedding _ function = embeddings ,
146
+ embedding = OpenAIEmbeddings ( openai _ api _ key = apiKey ) ,
150
147
dimension =1536 ,
151
148
collection _name =collectionName ,
152
149
)
153
150
154
151
retriever = vectorstore .as _retriever ()
155
152
156
153
return json .dumps ({" status" : true })
157
- except :
158
- return json .dumps ({" error" : " API ERROR " })
154
+ except Exception as err :
155
+ return json .dumps ({" error" : str ( err ) })
159
156
}
160
157
161
158
}
0 commit comments