Skip to content

Commit 8eb2cbe

Browse files
committed
🐛 Fix embeddings ApiKey
1 parent 41edbb8 commit 8eb2cbe

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/dc/irisMediCopilot/core/MediCopilot.cls

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
4848
try:
4949

5050
llm = ChatOpenAI(model= model, temperature=0, api_key=apiKey)
51-
embeddings = OpenAIEmbeddings()
51+
embeddings = OpenAIEmbeddings(openai_api_key=apiKey)
5252

5353
vectorstore = IRISVector.from_documents(
5454
embedding_function=embeddings,
@@ -116,8 +116,8 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
116116
)
117117

118118
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)})
121121
}
122122

123123
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
135135
from langchain_text_splitters import RecursiveCharacterTextSplitter
136136

137137
try:
138-
llm = ChatOpenAI(model=model, temperature=0, api_key=apiKey)
139-
embeddings = OpenAIEmbeddings()
140-
141138
loader = CSVLoader(file_path= filePath)
142139
docs = loader.load()
143140

@@ -146,16 +143,16 @@ ClassMethod Ingest(apiKey As %String, collectionName As %String, filePath As %St
146143

147144
vectorstore = IRISVector.from_documents(
148145
documents=splits,
149-
embedding_function=embeddings,
146+
embedding=OpenAIEmbeddings(openai_api_key=apiKey),
150147
dimension=1536,
151148
collection_name=collectionName,
152149
)
153150

154151
retriever = vectorstore.as_retriever()
155152

156153
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)})
159156
}
160157

161158
}

0 commit comments

Comments
 (0)