Skip to content

Commit

Permalink
🚧 Start the ingest process
Browse files Browse the repository at this point in the history
  • Loading branch information
henryhamon committed May 8, 2024
1 parent 72387ba commit 576a36b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
iris:
environment:
- OPENAPI_KEY=${OPENAPI_KEY}
- TELEGRAM_TOKEN=7194686883:AAHGvYjsfPqjUjdfekwnDdfYZ0uvwH2ERjI
- TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
build:
context: .
dockerfile: Dockerfile
Expand Down
48 changes: 43 additions & 5 deletions src/dc/irisMediCopilot/core/MediCopilot.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Property CollectionName As %String;

Property SSLConfiguration As %String;

Property Model As %String [ InitialExpression = "gpt-3.5-turbo" ];

Method %OnNew(collectionName As %String, apiKey As %String, ssl As %String) As %Status [ Private ]
{
If ( (collectionName="") || (apiKey="") || (ssl="") ) {
Expand All @@ -23,15 +25,13 @@ Method %OnNew(collectionName As %String, apiKey As %String, ssl As %String) As %
Method ExecuteRequest(question As %String, sessionId As %String = "") As %DynamicObject
{
Set response = ..RetrieveAnswer(..ApiKey, ..CollectionName, question, sessionId)
/*
If (response.error '="") {
$$$LOGINFO("API ERROR: "_response."error")
$$$LOGINFO("API ERROR: "_response.error)
}
*/
Return ##class(%Library.DynamicObject).%FromJSON(response)
}

ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, question As %String, sessionId As %String = "") [ Language = python ]
ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, question As %String, sessionId As %String = "", model As %String = "gpt-3.5-turbo") [ Language = python ]
{
import json
from langchain_iris import IRISVector
Expand All @@ -47,7 +47,7 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio

try:

llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0, api_key=apiKey)
llm = ChatOpenAI(model= model, temperature=0, api_key=apiKey)
embeddings = OpenAIEmbeddings()

vectorstore = IRISVector.from_documents(
Expand Down Expand Up @@ -120,4 +120,42 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
return json.dumps({"error": "API ERROR"})
}

ClassMethod Ingest(apiKey As %String, collectionName As %String, filePath As %String, model As %String = "gpt-3.5-turbo-0125") As %String [ Language = python ]
{
import json
from langchain_iris import IRISVector
from langchain_community.chat_message_histories import ChatMessageHistory
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_community.document_loaders.csv_loader import CSVLoader
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_text_splitters import RecursiveCharacterTextSplitter

try:
llm = ChatOpenAI(model=model, temperature=0, api_key=apiKey)
embeddings = OpenAIEmbeddings()

loader = CSVLoader(file_path= filePath)
docs = loader.load()

text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
splits = text_splitter.split_documents(docs)

vectorstore = IRISVector.from_documents(
documents=splits,
embedding_function=embeddings,
dimension=1536,
collection_name=collectionName,
)

retriever = vectorstore.as_retriever()

return json.dumps({"status": true})
except:
return json.dumps({"error": "API ERROR"})
}

}

0 comments on commit 576a36b

Please sign in to comment.