Files
ds_update_stack/scripts/__pycache__/rag.cpython-312.pyc
T

34 lines
5.1 KiB
Plaintext
Raw Normal View History

2025-03-06 09:24:46 +01:00
Ë
ÃYÉg‡ãó¾ddlZddlmZddlmZddlmZddlmZddl m
Z
ddl m Z m
Z
ddlZddlmZdd lmZdd
lmZdd l m
Z
m Z ddlZdd lmZdd
lmZmZddlmZe«ej8d«xsdZee¬«Ze«ZGdde«Z ejCd«de fd«Z"dZ#dZ$dZ%e&dk(re
d¬«Z'e «Z(dZ)e#e)e'e(«Z*yy)éN)ÚInMemoryDocstore)ÚFAISS)ÚChatPromptTemplate)Úcreate_retrieval_chain)Úcreate_stuff_documents_chain)ÚOpenAIEmbeddingsÚ
ChatOpenAI)ÚOpenAI)Ú CSVLoader)ÚPath)r r)Ú load_dotenv)ÚFastAPIÚ
HTTPException)Ú BaseModelÚOPENAI_API_KEYz3sk-LXdMF1UrcGBpwUpV7GnIT3BlbkFJeffeLUsqpk6PukvwOzJO)Úapi_keycóeZdZUeed<y)ÚQuestionRequestÚquestionN)Ú__name__Ú
__module__Ú __qualname__ÚstrÚ__annotations__©óúE/Users/macbook/Desktop/blessing_ai/mkd/ds_update_stack/scripts/rag.pyrrsØ„Mrrz/update-stack/v1/askÚrequestcóº tt|j«}t|j|«}d|iS#t$r}t dt
|«¬«d}~wwxYw)answeriô)Ú status_codeÚdetail)Ú
get_answerÚ rag_chainrÚresponse_agentÚ Exceptionrr)rÚcalculation_dataÚfinal_responseÚes rÚ ask_questionr*sYð%¤i°×1AÑ1AÓÜ×(8Ñ(8Ð:JÓKˆØ˜)øÜ ò¨´C¸³FÔ;ûð<ús36¶ A¿AÁAcólt|¬«}|j«}tjt |j d«««}t
||t«i¬«}|j|¬«|j«}d}tjd|fdg«} t|| «}
t||
«S)N)Ú file_pathÚ )Úembedding_functionÚindexÚdocstoreÚindex_to_docstore_id)Ú documentszÃYou are an AI assistant that provides investment insights. Use the Relevant Data to answer the question. If you don't know the answer, say that you don't know. Keep the answer concise.
{context}Úsystem)Úhumanz{input})r Úload_and_splitÚfaissÚ IndexFlatL2ÚlenÚ embed_queryrrÚ
add_documentsÚ as_retrieverrÚ
from_messagesrr) r,Úllmr.ÚloaderÚdocsr/Ú vector_storeÚ retrieverÚ
system_promptÚpromptÚquestion_answer_chains rÚsetup_rag_systemrE(Ü
 Ô
+€FØ × Ñ Ó "€Dä × Ñ œcÐ"4×"@Ñ"@ÀÓ"EÓ G€EÜØÜô €Lð ×ѨÐÔ×+€Ið ðô ×
ð/ó€Fô
¸fÓÜ ! )Ð-BÓ Crcó2|jd|i«}|dS)inputr )Úinvoke)r$Ú
user_inputr s rr#r#Is"Ø
×
Ñ
˜
Ð