Files
ds_sabaproject/__pycache__/utils.cpython-311.pyc
T

96 lines
7.0 KiB
Plaintext
Raw Normal View History

2024-11-13 00:41:30 +01:00
§
(ãóddlmZddlmZddlmZmZddlZddlZddl m
Z
ddl m Z e ¦«ej
d¦«ejd<ej
d¦«Zed ¬
¦«Zefd Zd ed
edefdZd
edefdZgd¢ZefdedefdZdS)é)Ú
ChatOpenAI)ÚPromptTemplate)ÚStrOutputParserÚJsonOutputParserN)Úlogger)Ú load_dotenvÚOPENAI_API_KEYÚPERPLEXITY_AI_APIzgpt-4o)Úmodelcó2d}ddddœd|dœgddd d
gd d d d
d d
ddœ
}d|ddœ}tj|||¬¦«}|jdkrI| ¦«} |dd
dd}|S#tt
f$rYdSwxYwd|jS)Nz*https://api.perplexity.ai/chat/completionsz!llama-3.1-sonar-small-128k-onlineÚsystemzBe precise and concise.)ÚroleÚcontentÚusergš™™™™™É?gÍÌÌÌÌÌì?Tz
perplexity.aiFÚmonthré)
r ÚmessagesÚ temperatureÚtop_pÚreturn_citationsÚsearch_domain_filterÚ
return_imagesÚreturn_related_questionsÚsearch_recency_filterÚtop_kÚstreamÚpresence_penaltyÚfrequency_penaltyzBearer zapplication/json)Ú
Authorizationz Content-Type)ÚjsonÚheaderséÈÚchoicesÚmessagerzUnexpected response format.z!Request failed with status code: )ÚrequestsÚpostÚ status_coder ÚKeyErrorÚ
IndexError)ÚpromptÚapi_keyÚurlÚpayloadr!ÚresponseÚ
response_dataÚmessage_contents úLc:\Users\timmy_3aupohg\Downloads\Manaknight Projects\ds_sabaproject\utils.pyÚget_chat_completionr2sØ
6€Cð
ð
ð
Ø
ð
ð 
ðØØ Ø!0Ð 1ØØ$)Ø!(ØØØØð-ð€Gð4- 7Ðð€Gõ
Œ}˜S w¸Ð@€HðÔ˜ Ÿ
š
œˆ
ð+¨IÔ6°qÔ9¸DÀYÔOˆ "øÝ 1øøøðJ°8Ô3GÐIsÁA7Á7B Â B Ú
search_resultr*Úreturncó¶tjd¦«tdddg¬¦«}|tzt ¦«z}| ||dœ¦«}|S)NzFormatting Influencer Dataa¬<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are a Influencer Data Extractor AI Agent tasked with extracting information from a search result
Backstory:
A business brand is looking for some influencer in a specific location or area. He used a tool called Perplexity AI to get this data.
This is an amazing too, and yet it can struggle a bit (ai isn't perfect you know).
The information returned by this ai can be incomplete, not properly structured and all.
This brand needs youe help.
This is how you will help the brand:
1. You will be given two things, the ai search result and the prompt used to query the ai.
2. Your major interest here is formatting and making the structure right.
3. You will process the ai result, create a JSON structure of the key information needed by the user and add the corresponding values to it.
4. The user prompt is your guide on of how the JSON should be formatted.
5. If there's are missing data or something in the ai response, send it back as NA.
6. At the end of your processing you want to return a structured response and also make sure it in the best order as expected by the user.
Return a structured JSON or dictionary as output.
Ensure that the data is properly arranged and in a good format.
Please do this carefully and excellently.
<|eot_id|><|start_header_id|>user<|end_header_id|>
AI_SEARCH_RESULT: {search_result}
PROMPT: {prompt}
<|eot_id|><|start_header_id|>assistant<|end_header_id|>r3r*©ÚtemplateÚinput_variables)r3r*)rÚinforÚllmrÚinvoke)r3r*Úinitiator_promptÚinitiator_routerÚoutputs r1Úinfluencer_datar?AspÝ
„KÐ?ð0-¨hÐ7ð3
ñ
ô
Ðð8(­-Õ0@Ñ0BÔ0BÑØ
×
$°mÈfÐ%UÐ%UÑ
V€FØ €Mócó”tjd¦«t|¦«}tjd¦«t||¦«}|S)Nz.Using Perplexity Ai to get the influencer datazFormatting the data with OpenAI)rr9r2r?)r*r3Úformatted_datas r1Úcombined_influencer_datarCdsJå
„KÐÑ/€Mõ „KÐ$ ]°FÑ;€Nð Ðr@)zBeauty & SkincarezFashion & LifestylezHealth & FitnesszTravel & AdventurezFood & BeveragezTechnology & GadgetszGaming & EsportszParenting & FamilyzFinance & BusinesszWellness & Mental HealthzAutomotive & MotorsportszEntertainment & Pop CulturezPhotography & Visual ArtszEducation & LearningzEnvironmental & SustainabilityÚ
product_listscó¶tjd¦«tdddg¬¦«}|tzt ¦«z}| ||dœ¦«}|S)NzCategorizing productsa<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are a Brand AI Agent tasked with categorizing products into categories
There are some categories given by the brand, these are the categories the products are expected to be categorized into.
You will be given a list of products and asked to categorize them.
You are meant to categorize all the given product into one category.
You take the following steps:
1. Looking into all the list of products.
2. Understand where they belong to.