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

55 lines
8.1 KiB
Plaintext
Raw Normal View History

Ë
ˆyíhãóddlZddlmZmZddlmZmZddlmZm Z m
Z
ddl m Z ddl
mZddlmZddlmZdd lmZdd
lmZmZmZmZdd lmZdd lmZe j<d
«Zej@e«Z!Gdd«Z"y)éN)ÚListÚOptional)Ú DATABASE_URLÚget_db)Ú FundTableÚ
InvestorTableÚ ProjectTable)Úhub)ÚSQLDatabaseToolkit)Ú SQLDatabase)Ú
ChatOpenAI)Úcreate_react_agent)ÚCompanyMinimalÚInvestmentResponseÚPaginatedResponseÚ
2025-09-25 17:00:38 +01:00
SectorMinimal)Ú selectinload)Ú(calculate_project_investor_compatibilityz$langchain-ai/sql-agent-system-promptcóveZdZdZ d dedeedeefdZ dede
efdZ d d e
2025-09-25 17:00:38 +01:00
edeedeefd
Z 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Ú
project_idÚreturncóÒ|jjdd|fgi«}|jd«r|ddjnd}|j |«}|j ||«S)zÜProcess a query using the LLM and return investment response data.
Args:
question: The natural language query to process
project_id: Optional project ID for compatibility scoring
ÚmessagesÚuseréÿÿÿÿÚ)r+ÚinvokeÚgetÚcontentÚ_extract_fund_ids_from_responseÚ_fetch_funds_by_ids)r,r1r2ÚresponseÚ ai_responseÚfund_idss r.Ú
process_queryzQueryProcessor.process_query1svð—::×
˜6  
ˆð 19· ± ¸ZÔ0HˆH  Ñ ,Èbð ð
× ÓDˆð×°*Ó=r0r?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?rCr@ÚnumbersÚnumÚ
id_matchesÚid_strÚes r.r<z.QueryProcessor._extract_fund_ids_from_responseJãàˆð
ð—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
óD|s#tgdd|rt|«d¬«Sdd¬«Stt««} d}|i|j t
«j
tt
j««jt
j|k(«j«}|j t«j
ttj«jtj«ttj«jtj «ttj«jtj"«ttj$«ttj"««jtjj'|««j)«}g}|D]o}|j}d} |t+||d¬«} |jdd D
cgc]#}
t-|
j|
j.¬
«Œ%} }
|j$r3d j1|j$D cgc]} | j.Œc} «nd}