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

110 lines
14 KiB
Plaintext
Raw Normal View History

Ë
T·he.ãóªddlZddlmZmZddlZddlZddlmZm Z m
Z
m Z ddl m
Z
ddlmZddlmZddlmZddlmZGd „d
e«ZGd d «Zy)
éN)ÚListÚOptional)Ú CompanyTableÚ
InvestorTableÚInvestorTeamMemberÚ SectorTable)ÚPromptTemplate)Ú
ChatOpenAI)Ú InvestorData)Ú BaseModel)Úsettingscó"eZdZUdZeeed<y)Ú InvestorListz Schema for LLM structured outputÚ
investor_listN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr Ú__annotations__©óúN/home/oluwasanmi/Documents/Work/MKD/anton_wireframe/app/services/openrouter.pyrrsÙ˜ Ñ%rrc
ó¾eZdZ ddeedeefdZdejdede e
fdZ d e e
ddfd
Z d e e
ddfd Z
dd ejd
edede e
fdZy)ÚInvestorProcessorNÚ sql_sessionÚvector_db_clientcórd|_t|jdg¬«|_ttj
ddd¬«|_|j jt«|_ ||_
||_ tjd¬ «|_ |jjd
d d i¬
«|_y)Na¡You are an expert data extraction assistant. Extract investor information from the provided CSV data and return it as a list of structured records.
Given the following CSV data rows:
{question}
For each row, extract and structure the following fields for the investor:
- name: The investor's full name
- description: Description of the investor
- aum: Assets under management (as integer, use 0 if not available)
- check_size_lower: Lower bound of investment check size (as integer)
- check_size_upper: Upper bound of investment check size (as integer)
- geographic_focus: Geographic region focus
- stage_focus: Investment stage focus (must be one of: seed, series_a, series_b, series_c, growth, late_stage)
- number_of_investments: Number of investments made (default 0)
Also extract related data:
- portfolio_companies: List of companies they've invested in
- team_members: List of team members with name, role, email
- sectors: List of sectors they focus on
Important:
- If a field is not available, use appropriate defaults
- stage_focus must be one of the valid enum values
- Return clean, valid JSON only
Return the data as a structured list of comprehensive investor data.Úquestion)ÚtemplateÚinput_variableszhttps://openrouter.ai/api/v1zgoogle/gemini-2.5-flash-liter)Úapi_keyÚbase_urlÚmodelÚ temperaturez ./chroma_db)ÚpathÚinvestor_descriptionsÚ descriptionz1Investor descriptions and investment thesis focus)ÚnameÚmetadata)rr Úpromptr
r
ÚOPENROUTER_API_KEYÚllmÚwith_structured_outputrÚstructured_llmrrÚchromadbÚPersistentClientÚget_or_create_collectionÚ
collection)Úselfrrs rÚ__init__zInvestorProcessor.__init__s­ð
HˆŒ
ô6—]‘]°Z°Lô
ˆŒ ôÜ×ô 
ˆŒð#Ÿh™h×=¼lÓÔØÔØ 0ˆÔä (× 9Ñ 9¸}Ô MˆÔØ×ÐðIó
ˆrÚbatchÚ batch_idxÚreturnc
ƒóÆKd}|j«D\}}i}|j«D]s\}}tj|«sŒt |«j dd«j dd«j dd«} dj
d| D««} | ||<Œudj
|j«Dcgc] \}}|d|Œc}}«}
|d |d
zd|
dz
}ŒÕ td |d
zd «|jj|«ƒd
{} | jScc}}w7Œ#t$r } td|d
zd| «gcYd
} ~ Sd
} ~ wwxYw­w)zProcess a single batch of dataÚú
ú ú
ú c3óDK|]}t|«dk\s|dvr|Œy­w)é )r:r<r=N)Úord)Ú.0Úchars rú <genexpr>z3InvestorProcessor._process_batch.<locals>.<genexpr>_s+èø€ò*à ܘt›9¨š?¨dÐ6HÑ.Hôñ*ùs ú, z: zRow ézProcessing batch z...NzError processing batch ) ÚiterrowsÚitemsÚpdÚnotnaÚstrÚreplaceÚjoinÚprintr.ÚainvokerÚ Exception)
r3r5r6Ú batch_strÚidxÚrowÚ cleaned_rowÚkeyÚvalueÚ clean_valueÚrow_strÚ
batch_resultsÚes
rÚ_process_batchz InvestorProcessor._process_batchLszèø€ð
ˆ ØŸÓ 7‰HˆCàˆKØ!Ÿi™i
3
—8‘8˜E•?ô˜E›
ß  sÓ  sÓ   ð#%§'¡'ñ*à$/ô*ó#
(3K Ò
3ð"—iiØ5@×5FÑ5FÓ5H×I¡z s¨EC5˜˜5˜ˆ
˜4  a¡˜y¨¨7¨)°2Ð 6‰Ið/ 7ð2 Ü Ð% i°!¡m _°CÐ 9Ø"&×"5Ñ"5×"=Ñ"=¸iÓ"H×Hˆ × .ùóJð Iùäò Ü Ð+¨I¸©M¨?¸"¸Q¸ Iûð üs[AE!Á A8E!ÃD- ÃE!Ã,0D5ÄD3ÄD5Ä,E!Ä3D5Ä5 EÄ>EÅEÅE!ÅEÅE!Úinvestor_data_listc ƒó¤K|jsy |D}t|jj|jj|jj
|jj |jj|jj|jj|jj¬«}|jj|«|jj«|jD}|jjt«j!tj|jk(«j#«}|sgt|j¬«}|jj|«|jj«|jj%|«ŒÃ||jvsŒÒ|jj%|«Œî|j&D]}|jjt(«j!t(j|jk(«j#«}|s“t)|j|j*|j,|j.|j0¬«} |jj| «|jj«|j&j%| «Œð||j&vsŒÿ|j&j%|«Œ|j2D}
|jjt4«j!t4j6|
j6k(«j#«} | rŒ]t5|
j|
j8|
j6|j:¬«} |jj| «Œ°ŒÏ|jj=«t?dtA|«d«y#tB$r.}
|jjE«t?d|
«d}
~
wwxYw­w) z/Save investors and related data to SQL databaseN)r(r'ÚaumÚcheck_size_lowerÚcheck_size_upperÚgeographic_focusÚ stage_focusÚnumber_of_investments)r()r(ÚindustryÚlocationÚ founded_yearÚwebsite)r(ÚroleÚemailÚ investor_idúSuccessfully saved z investors to databasezError saving to SQL database: )#rrÚinvestorr(r'r]r^r_r`rarbÚaddÚflushÚsectorsÚqueryrÚfilterÚfirstÚappendÚportfolio_companiesrrcrdrerfÚ team_membersrrhrgÚidÚcommitrMÚlenrOÚrollback)r3r[Ú
investor_dataÚ db_investorÚ sector_dataÚexisting_sectorÚ db_sectorÚ company_dataÚexisting_companyÚ
db_companyÚteam_member_dataÚexisting_memberÚdb_team_memberrYs rÚ _save_to_sqlzInvestorProcessor._save_to_sqlss”èø€à×ÒØ ðW Ø!3óN
=
ä&×/×4Ø -× 6Ñ 6× BÑ BØ%×.×2Ø%2×%;Ñ%;×%LÑ%LØ%2×%;Ñ%;×%LÑ%LØ%2×%;Ñ%;×%LÑ%LØ -× 6Ñ 6× BÑ BØ*7×*@Ñ*@×*VÑ*Vô  ð× Ñ ×$ [Ô× Ñ ×$1×#8Ñ#8òH×.¬{Ó¤ × 0Ñ 0°K×4DÑ4DÑ DÓð +Ü$/°[×5EÑ5EÔ$F˜ Ø×(×,¨YÔ×+×2°9Õ+°+×2EÑ2EÒ'×/×ÕGð#Hð(%2×$EÑ$EóU×(×.¬|Ó¤ × 1Ñ 1°\×5FÑ5FÑ FÓð ,Ü%1Ø!-×!2Ñ!2Ø%1×%:Ñ%:Ø%1×%:Ñ%:Ø)5×)BÑ)BØ$0×$8Ñ$8ô &˜
ð×,¨ZÔ×$×7×>¸,°;×3RÑ3RÒ'×;×BÐCSÖTð1Uð6)6×(BÑ(Bò×.Ô/AÓÔ 2× 8Ñ 8Ð<L×<RÑ<RÑ RÓð +Ü);Ø!1×!6Ñ!6Ø!1×!6Ñ!6Ø"2×"8Ñ"8Ø(3¯©ô *˜ð ×,¨^ÕN
=ð`
× Ñ × ÐÐ,>Ó(?Ð'@Ð@VÐ Xøäò Ø × Ñ × Ð2°1°#Ð ûð üs>QG PÇD'PÌBPÎ B PÐQÐ Q
Ð)QÑQ
Ñ
QcƒóJK|jsyg}g}g}t|«D]•\}}|j}dj|jDcgc]}|j
Œc}«} dj|j D
cgc]}
|
j
Œc}
«} d|j
d|jxsdd|jdd|jdd |jdd
|jd |jjd | d
| dj«} |j| «|j|j