Files
Anton_wireframe/app/services/__pycache__/querying.cpython-312.pyc
T

44 lines
7.2 KiB
Plaintext
Raw Normal View History

Ë
ä\æhTãóôddlZddlmZddlmZmZddlmZmZddl m
Z
ddl m Z ddl
mZddlmZdd lmZdd
lmZmZmZmZdd lmZe
j4d «Zej8e«ZGd
d«Zy)éN)ÚList)Ú DATABASE_URLÚget_db)Ú FundTableÚ
2025-09-25 17:00:38 +01:00
InvestorTable)Úhub)ÚSQLDatabaseToolkit)Ú SQLDatabase)Ú
ChatOpenAI)Úcreate_react_agent)ÚCompanyMinimalÚInvestmentResponseÚPaginatedResponseÚ
SectorMinimal)Ú selectinloadz$langchain-ai/sql-agent-system-promptcóZeZdZdZdedeefdZdedee fdZ
2025-09-25 17:00:38 +01:00
dee deefdZ y )
ÚQueryProcessorcóBttjd«ddd¬«|_t t
|j¬«|_tjdd¬ «d
2025-09-25 17:00:38 +01:00
zd zd zd
z}t|j|j j«|¬«|_ y)OPENROUTER_API_KEYzhttps://openrouter.ai/api/v1zx-ai/grok-4-fastr)Úapi_keyÚbase_urlÚmodelÚ temperature)ÚdbÚllmÚSQLiteé)ÚdialectÚtop_kzo
IMPORTANT: You must ONLY return the fund IDs (id field from the funds table) that match the user's criteria. z<Do NOT return any other information, explanations, or data. zZYour response should be ONLY a comma-separated list of numbers representing the fund IDs. zExample format: 1, 5, 12, 23)rÚtoolsÚprompt) r ÚosÚgetenvrr rÚtoolkitÚprompt_templateÚformatr Ú get_toolsÚagent)ÚselfÚsystem_message_updateds úL/home/oluwasanmi/Documents/Work/MKD/anton_wireframe/app/services/querying.pyÚ__init__zQueryProcessor.__init__ÜÜ—I‘IÐô 
ˆŒô *¬R°T·X±XÔ>ˆŒ ô
× "¨8¸ Bñ
Bà
Mðkñ
kð
 ô—(‘(Ø—,‘,×
ˆ
óÚquestionÚreturncóÐ|jjdd|fgi«}|jd«r|ddjnd}|j |«}|j |«S)zBProcess a query using the LLM and return investment response data.ÚmessagesÚuseréÿÿÿÿÚ)r(ÚinvokeÚgetÚcontentÚ_extract_fund_ids_from_responseÚ_fetch_funds_by_ids)r)r.ÚresponseÚ ai_responseÚfund_idss r+Ú
process_queryzQueryProcessor.process_query/stð—::×
˜6  
ˆð 19· ± ¸ZÔ0HˆH  Ñ ,Èbð ð
× ÓDˆð×Ó1r-r;có<ddl}g} |jd|«}|Dcgc]
}t|«Œ}}|jd|j««}|r|Dcgc]
}t|«Œ}}|Scc}wcc}w#t$r}t d|«gcYd}~Sd}~wwxYw)z"Extract fund IDs from AI response.rNz\b\d+\bz\bid[:\s]*(\d+)z$Error extracting IDs from response: )ÚreÚfindallÚintÚlowerÚ ExceptionÚprint) r)r;r?r<ÚnumbersÚnumÚ
id_matchesÚid_strÚes r+r8z.QueryProcessor._extract_fund_ids_from_responseAãàˆð
ð—j¨[Ó9ˆGØ,3Ö4 Sœ˜CÐ4ˆHПÐ$6¸ ×8IÑ8IÓ8KÓLˆØ6@ÖA¨FœC AÐ ˆùò5ùò
Bøäò Ü Ð¸Ð Iûð ús9ˆA8žA.°(A8ÁA3Á*A8Á.
A8Á8 BÂBÂBÂBr<c
óF|s#tgdd|rt|«d¬«Sdd¬«Stt««} |j t
«j
tt
j«jtj«tt
j«jtj«tt
j«jtj«tt
j«tt
j««jt