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

55 lines
8.4 KiB
Plaintext
Raw Normal View History

Ë
4êïh¶ãó<ddlZddlZddlZddlmZmZddlmZmZddl m
Z
m Z m Z ddl
mZddlmZddlmZddlmZdd lmZdd
lmZmZmZmZdd lmZdd lmZej@e!«Z"ejFd
«Z$ejJe«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/v1zopenai/gpt-4o-minir)Ú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ô 
ˆŒô *¬R°T·X±XÔ>ˆŒ ô
× "¨8¸ Bñ
Bà
Mðkñ
kð
 ô—(‘(Ø—,‘,×
ˆ
óquestionÚ
project_idÚreturncó|jjdd|fgiddi¬«}tj|«|ddj}tjd|«|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Úrecursion_limité2)ÚconfigéÿÿÿÿzAI Response:
)r+ÚinvokeÚloggerÚinfoÚcontentÚ_extract_fund_ids_from_responseÚ_fetch_funds_by_ids)r,r1r2ÚresponseÚfinal_message_contentÚfund_idss r.Ú
process_queryzQueryProcessor.process_query4sð—:
˜6  % 
ˆô  x"Ø (¨Ñ 4°RÑ 8× @Ñ @ÐÜ oÐ&;Ð%<Ð×7Ð8MÓNˆð×°*Ó=r0Ú ai_responsecó<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,rErGrCÚnumbersÚnumÚ
id_matchesÚid_strÚes r.r?z.QueryProcessor._extract_fund_ids_from_responseMãàˆð
ð—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ÂBrCc
ó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.¬
«Œ%} }