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

73 lines
9.0 KiB
Plaintext
Raw Normal View History

Ë
1G÷h2"ãó<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ó„ttjd«ddd¬«|_t t
|j¬«|_tjdd¬ «d
zd zd zd
zdzdzdzdzdzdzdzdzdzdzdz}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_kz
=== IMPORTANT TERMINOLOGY ===zE
- When users say 'investors' or 'find me investors', they mean FUNDSz>
- Always query the 'funds' table for investment opportunitiesz?
- The 'investors' table is for parent company information onlyz.
- Relationship: investors (1) -> (many) fundsz
=== YOUR TASK ===z@
Return ONLY fund IDs (funds.id) that match the user's criteria.z:
Format: comma-separated numbers only (e.g., 1, 5, 12, 23)z
No explanations, no other data.z
=== QUERY GUIDELINES ===z7
1. For geographic searches: use funds.geographic_focusz5
2. For sector searches: JOIN with fund_sectors tablez>
3. For stage searches: JOIN with fund_investment_stages tablez,
2025-09-25 17:00:38 +01:00
4. If no results: respond with 'NO_RESULTS'z&
5. Never repeat the same failed query)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__sÜÜ—Iô 
ˆŒô *¬R°T·X±XÔ>ˆŒ ô
× "¨8¸ 

WðPñ
PðQñ 
Qð
@ñ 
@ð 

Rñ
RðLñ
Lð

Iñ
IðGñ
GðPñ
Pð

 ô$—(‘(Ø—,‘,×
ˆ
ó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_query?sð—:
˜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_responseXãàˆð
ð—j¨[Ó9ˆGØ,3Ö4 Sœ˜CÐ4ˆHПÐ$6¸ ×8IÑ8IÓ8KÓLˆØ6@ÖA¨FœC AÐ ˆùò5ùò