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

103 lines
14 KiB
Plaintext
Raw Normal View History

2025-09-11 16:23:22 +01:00
Ë
&âÂh-ãóª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óeZdZUdZeed<y)ÚInvestorOutputz Schema for LLM structured outputÚ
investor_dataN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r Ú__annotations__©óúQ/home/oluwasanmi/Documents/Work/MKD/anton_wireframe/app/services/openrouter_v2.pyrrs ÙÔrrcóºeZdZ ddeedeefdZdejdedee fdZ
d e e ddfd
Z d e e ddfd Z
dd ejd
ede 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 structured record.
Given the following CSV data row:
{question}
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 single comprehensive investor data record.Ú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­ð
CˆŒ
ô6—]‘]°Z°Lô
ˆŒ ôÜ×ô 
ˆŒð#Ÿh™h×=¼nÓÔØÔØ 0ˆÔä (× 9Ñ 9¸}Ô MˆÔØ×ÐðIó
ˆrÚrowÚrow_idxÚreturnc ƒóŠKi}|j«D]s\}}tj|«sŒt|«j dd«j dd«j dd«}dj d|D««}|||<Œudj |j«Dcgc] \}}|d|Œc}}«} t
d |d
zd «|jj|«ƒd {}|jr |jSy cc}}w7Œ##t$r} t
d
|d
zd| «Yd } ~ y d } ~ wwxYw­w)zProcess a single row of dataú
ú ú
ú Úc3óDK|]}t|«dk\s|dvr|Œy­w)é )r9r;r<N)Úord)Ú.0Úchars rú <genexpr>z1InvestorProcessor._process_row.<locals>.<genexpr>\s+èø€ò&àܘ4“y B¨$Ð2DÑ*Dôñ&ùs ú, z: zProcessing row éz...NzError processing row ) ÚitemsÚpdÚnotnaÚstrÚreplaceÚjoinÚprintr.ÚainvokerÚ Exception)
r3r5r6Ú cleaned_rowÚkeyÚvalueÚ clean_valueÚrow_strÚresultÚes
rÚ _process_rowzInvestorProcessor._process_rowLsGèø€ð
ˆ ØŸ)™)›+ò /‰JˆCÜx‰x˜ô˜“JßW˜T 3ÓW˜T W˜T ð!Ÿg™gñ&à +ô&ó ð
$/ ˜ ð /ð"—))Ø1<×1BÑ1BÓ1D× E¡: ˆuBu
Ó 
ˆð Ü O G¨a¡K =°Ð ×6°wÓ?ˆFØ××ùó
Fð
@ùôò Ü Ð)¨'°A©+¨°b¸¸Ð ûð üsS.E±A8EÂ)D
Â:EÃ0DÃ3DÃ4DÄEÄDÄ EÄ"D;Ä6EÄ;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'rYrZr[r\r]r^ÚaddÚflushÚsectorsÚqueryrÚfilterÚfirstÚappendÚportfolio_companiesrr_r`rarbÚ team_membersrrdrcÚidÚcommitrLÚlenrNÚrollback)r3rWrÚ db_investorÚ sector_dataÚexisting_sectorÚ db_sectorÚ company_dataÚexisting_companyÚ
db_companyÚteam_member_dataÚexisting_memberÚdb_team_memberrUs rÚ _save_to_sqlzInvestorProcessor._save_to_sqlqs”èø€à×ÒØ ð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
|jj|j|jdœ«|jd|d|j
j!dd«j!dd««Œ˜|r8 |j"j%|||¬«t'dt)|«d«yycc}wcc}
w#t*$r}
t'd|
«Yd}
~