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

132 lines
12 KiB
Plaintext
Raw Normal View History

2024-11-13 00:41:30 +01:00
§
2024-11-29 14:59:00 +01:00
­ÆHg,ãó¤ddlmZddlmZddlmZmZddlZddlZddl m
2024-11-13 00:41:30 +01:00
Z
2024-11-29 14:59:00 +01:00
ddl m Z ddlZddl
mZddlmZe¦«ejd ¦«ejd <ejd
¦«Zejd ¦«Zed ¬
2024-11-13 00:41:30 +01:00
¦«ZefdZdededefdZdedefdZgd¢ZefdedefdZdefdZddZdefdZ e!e d¦«¦«dS)é)Ú
2024-11-29 14:59:00 +01:00
ChatOpenAI)ÚPromptTemplate)ÚStrOutputParserÚJsonOutputParserN)Úbuild)Ú HttpError)Úlogger)Ú load_dotenvÚOPENAI_API_KEYÚYOUTUBE_API_KEYÚPERPLEXITY_AI_APIzgpt-4o)Úmodelcó2d}ddddœd|dœgddd d
gd d d d
2024-11-13 00:41:30 +01:00
d d
ddœ
}d|ddœ}tj|||¬¦«}|jdkrI| ¦«} |dd
2024-11-29 14:59:00 +01:00
dd}|S#tt
2024-11-13 00:41:30 +01:00
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_completionr5sØ
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.
2024-11-29 14:59:00 +01:00
2024-11-13 00:41:30 +01:00
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.
2024-11-29 14:59:00 +01:00
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.
2024-11-13 00:41:30 +01:00
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|>r6r-©ÚtemplateÚinput_variables)r6r-)r ÚinforÚllmrÚinvoke)r6r-Úinitiator_promptÚinitiator_routerÚoutputs r4Úinfluencer_datarBEspÝ
„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)r r<r5rB)r-r6Úformatted_datas r4Úcombined_influencer_datarFhsJå
„KÐÑ/€Mõ „KÐ$ ]°FÑ;€Nð ÐrC)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
2024-11-29 14:59:00 +01:00
There are some categories given by the brand, these are the categories the products are expected to be categorized into.
2024-11-13 00:41:30 +01:00
You will be given a list of products and asked to categorize them.
2024-11-29 14:59:00 +01:00
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.
3. Look into the kist of categories.
4. Select the category that this products falls under.
You should return the selected category as output.
Please do this carefully and correctly.
<|eot_id|><|start_header_id|>user<|end_header_id|>
PRODUCT_LISTS: {product_lists}
PRODUCT_CATEGORY: {product_categories}
<|eot_id|><|start_header_id|>assistant<|end_header_id|>rGÚproduct_categoriesr9)rGrI)r r<rr=rr>)rGrIr?r@rAs r4Úproduct_categorizerrJˆsqÝ
„KÐ?ð&-Ð.BÐCð)
ñ
ô
Ðð.(­#ÑÑ0AÔ0AÑØ
×
$°mÐZlÐ%mÐ%mÑ
n€FØ €MrCÚ channel_namecó˜t}d}d|d|dœ}tj||¬¦«}|jdkr| ¦«}d|vrõt |d¦«dkrÜ|dddd }d
}d ||d œ}tj||¬¦«} | jdkr|  ¦«}
d|
vrut |
d¦«dkr\|
dd} | d
d} | d
d}
2024-11-13 00:41:30 +01:00
| dd}| dd}| dd}| |
|||dœSdSd| jSdSd|jS)Nz,https://www.googleapis.com/youtube/v3/searchÚidÚchannel)ÚpartÚtypeÚkey)Úparamsr%ÚitemsrÚ channelIdz.https://www.googleapis.com/youtube/v3/channelszsnippet,statistics)rOrMrRÚsnippetÚtitleÚ descriptionÚ
statisticsÚsubscriberCountÚ viewCountÚ
videoCount)ÚTitleÚ DescriptionÚ Subscribersú Total Viewsú Total VideosúChannel not found.zError: )r r(Úgetr*r#Úlen)rKÚAPI_KEYr/rSr1ÚdataÚ
channel_idÚchannel_info_urlÚchannel_info_paramsÚchannel_info_responseÚchannel_info_dataÚ channel_inforWrXÚsubscriber_countÚ
2024-11-29 14:59:00 +01:00
view_countÚ video_counts r4Úget_youtube_channel_inforp¥Ý€Gà