Update agent.py
Browse files
agent.py
CHANGED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
|
4 |
+
GROQ_API_URL = "https://api.groqcloud.com/v1/chat/completions"
|
5 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Secure key from Hugging Face Secrets
|
6 |
+
|
7 |
+
# Helper function to load system prompt from txt files
|
8 |
+
def load_prompt(filename):
|
9 |
+
with open(f'config/system_prompts/{filename}', 'r') as file:
|
10 |
+
return file.read()
|
11 |
+
|
12 |
+
# Function to call Groq API with system prompt and user input
|
13 |
+
def call_groq(system_prompt, user_input):
|
14 |
+
headers = {"Authorization": f"Bearer {GROQ_API_KEY}"}
|
15 |
+
payload = {
|
16 |
+
"model": "mixtral-8x7b-32768",
|
17 |
+
"messages": [
|
18 |
+
{"role": "system", "content": system_prompt},
|
19 |
+
{"role": "user", "content": user_input}
|
20 |
+
]
|
21 |
+
}
|
22 |
+
response = requests.post(GROQ_API_URL, json=payload, headers=headers)
|
23 |
+
return response.json()['choices'][0]['message']['content']
|
24 |
+
|
25 |
+
def ad_copy_agent(product, description, audience, tone):
|
26 |
+
system_prompt = load_prompt("ad_copy_prompt.txt")
|
27 |
+
user_input = f"Product: {product}\nDescription: {description}\nAudience: {audience}\nTone: {tone}"
|
28 |
+
return call_groq(system_prompt, user_input)
|
29 |
+
|
30 |
+
def sentiment_agent(social_data):
|
31 |
+
system_prompt = load_prompt("sentiment_prompt.txt")
|
32 |
+
return call_groq(system_prompt, social_data)
|
33 |
+
|
34 |
+
def timing_agent(platform):
|
35 |
+
system_prompt = load_prompt("timing_prompt.txt")
|
36 |
+
return call_groq(system_prompt, f"Platform: {platform}")
|