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

85 lines
11 KiB
Plaintext
Raw Normal View History

Ë
ŽÙ±hG%ãóºddlZddlmZmZmZmZmZddlZddlm Z ddl
m Z m Z ddl
mZddlmZddlmZddlmZGd „d
e«ZGd d «ZGd
d«Zy)éN)ÚAnyÚDictÚListÚOptionalÚ TypedDict)Ú
ChatOpenAI)ÚENDÚ
StateGraph)Útext)ÚSession)ÚQueryResponseList)ÚsettingscóleZdZUeed<eeeefed<eeeefed<ee ed<eeed<y)Ú
AgentStateÚqueryÚ sql_resultsÚvector_resultsÚfinal_responseÚerrorsN)
Ú__name__Ú
__module__Ú __qualname__ÚstrÚ__annotations__rrrrr
©óúS/home/oluwasanmi/Documents/Work/MKD/anton_wireframe/app/services/langgraph_agent.pyrrsCØ ƒJØd˜3 ˜8‘nј˜c 3˜h™ÑÐ ‰IÔrrcódeZdZdefdZdefdZdedefdZdedefdZ dedefdZ
d e de fd
Z
y ) ÚInvestorQueryAgentÚ sql_sessioncóþ||_ttjddd¬«|_t j d¬«|_|jjddd i¬
«|_ |j«|_ y) Nzhttps://openrouter.ai/api/v1zopenai/gpt-4o-minir)Úapi_keyÚbase_urlÚmodelÚ temperaturez ./chroma_db)ÚpathÚinvestor_descriptionsÚ descriptionz1Investor descriptions and investment thesis focus)ÚnameÚmetadata) r rrÚOPENROUTER_API_KEYÚllmÚchromadbÚPersistentClientÚvector_db_clientÚget_or_create_collectionÚ
collectionÚ _build_graphÚgraph©Úselfr s rÚ__init__zInvestorQueryAgent.__init__s{Ø&ˆÔÜÜ×ô 
ˆŒô!)× 9Ñ 9¸}Ô MˆÔØ×ÐðIó
ˆŒð×(ˆ
rÚreturncó~tt«}|jd|j«|jd|j«|jd|j
«|j
d«|jdd«|jdd«|jdt«|j«S)zBuild the LangGraph workflowÚ
sql_searchÚ
vector_searchÚcombine_results)
r
rÚadd_nodeÚ_sql_search_nodeÚ_vector_search_nodeÚ_combine_results_nodeÚset_entry_pointÚadd_edger Úcompile)r5Úworkflows rr2zInvestorQueryAgent._build_graph,äœjÓð ×ј,¨×(=Ñ(=Ô×ј/¨4×+CÑ+CÔ×ÑÐ+¨T×-GÑ-GÔ × Ñ  Ô×ј,¨Ô×ј/Ð+<Ô×ÑÐ+¬SÔ×ÑÓ!rÚstatecƒó4K |d}td«}d|j«d}|jj|d|i«}g}|D}|j |j
|j |j|j|j|j|j|j|j|jddœ «Œ…||d<|S#t$r5}|j!dg«d t#|«gz|d<g|d<Yd
}~|Sd
}~wwxYw­w) z.Search the SQL database for relevant investorsr
SELECT
name,
website,
investor_description,
investment_thesis_focus,
headquarters,
aum_amount,
funds_info,
crunchbase_extract,
linkedin_profile,
source_truth_profile
FROM investors
WHERE
LOWER(name) LIKE :search_term OR
LOWER(investor_description) LIKE :search_term OR
LOWER(investment_thesis_focus) LIKE :search_term OR
LOWER(headquarters) LIKE :search_term OR
LOWER(crunchbase_extract) LIKE :search_term OR
LOWER(linkedin_profile) LIKE :search_term OR
LOWER(source_truth_profile) LIKE :search_term
LIMIT 10
ú search_termÚsql) r)ÚwebsiteÚinvestor_descriptionÚinvestment_thesis_focusÚ headquartersÚ
aum_amountÚ
funds_infoÚcrunchbase_extractÚlinkedin_profileÚsource_truth_profileÚsourcerrzSQL search error: N)r Úlowerr ÚexecuteÚappendr)rIrJrKrLrMrNrOrPrQÚ ExceptionÚgetr) r5rDrÚ sql_queryrGÚresultrÚrowÚes rr=z#InvestorQueryAgent._sql_search_node=s0èø€ð5 &ؘ'NˆðóˆIð0˜eŸk™k›m˜_¨AÐ.ˆKØ×-¨i¸-ÈÐ9UÓVˆFàˆKØò
Ø×"à #§¡Ø#&§;¡;Ø03×0HÑ0HØ36×3NÑ3NØ(+×(8Ñ(8Ø&)§n¡nØ&)§n¡nØ.1×.DÑ.DØ,/×,@Ñ,@Ø03×0HÑ0HØ"'ñ õð
ð"$/ˆE ð ˆ øô ò#Ÿi™i¨°"Ó5Ð;MÌcÐRSËfÈXÐ9VÐ8WÑWˆE(‰OØ#%ˆE àˆ ûð  &üs/D„CCÃDà Dà *DÄ
DÄDÄDcƒó¶K |d}|jj|gdgd¢¬«}g}|dr`|ddrXt|dd«D]D\}}|ji|¥|ddr |dd|nd|d dr |d d|ndd
d œ¥«ŒF||d <|S#t$r5}|j d
g«dt
|«gz|d
<g|d <Yd}~|Sd}~wwxYw­w)z=Search the vector database for semantically similar investorsré
)Ú metadatasÚ documentsÚ distances)Ú query_textsÚ n_resultsÚincluder^rr_Úr`Úvector)ÚdocumentÚdistancerRrrzVector search error: N)r1rÚ enumeraterUrVrWr)r5rDrÚresultsrÚir*r[s rr>z&InvestorQueryAgent._vector_search_nodexsGèø€ð˜'‘Nˆ—oo×"˜ÚˆGð  ˆNذ Ñ(<¸QÒ(?Ü#,¨W°[Ñ-AÀ!Ñ-DÓ#Eò KA"× Ø ð ' 3°AÒ)0° Ñ(<¸QÑ(?ÀÒ(Bà!#à& 3°AÒ)0° Ñ(<¸QÑ(?ÀÒ(Bà!"Ø&.ò õ ð ð'5ˆ ˆ øô
ò#Ÿi™i¨°"Ó¨A« 9ñˆE(‰Oð')ˆ ˆ ûð
 )üs/C„BBÂC CÂ!*Cà CÃCÃCcƒóÚK |jdg«}|jdg«}|d}i}|D]*}|jdd«j«}|sŒ&|||<Œ,|D]/}|jdd«j«}|sŒ&||vsŒ+|||<Œ1t|j««}|st g¬«|d<|Sd|d t j |d
d d ¬
«d} |jjt«}
|
j| «ƒd
{} | |d<|S7Œ #t$r?} |jdg«dt| «gz|d<t g¬«|d<Yd
} ~ |Sd
} ~ wwxYw­w)z6Combine and rank results from both databases using LLMrrrr)rd©Ú responsesrz$
Given the user query: "ad"
Analyze the following investor data and return the most relevant investors that match the query.
For each relevant investor, provide:
- name: The investor/firm name
- aum: Assets under management (extract number, use 0 if not available)
- check_size: Typical investment check size (extract from description, use "Unknown" if not available)
- sector_focus: Main sectors they invest in
- stage_focus: Investment stages they focus on (e.g., Seed, Series A, etc.)
- region: Geographic focus/headquarters location
- investment_thesis: Their investment philosophy/thesis
- investor_description: Brief description of the investor
- reason: Why this investor matches the query
Investor data: