viralx-agent / agent.py
Your Name
Initial commit of production engine
3c760ee
Raw
History Blame Contribute Delete
2.16 kB
# agent.py
import os
import httpx
from pydantic import BaseModel
MISTRAL_URL = "https://api.mistral.ai/v1/chat/completions"
MISTRAL_MODEL = "mistral-small-latest"
SYSTEM_PROMPT = """
You are a world-class growth-hacking AI engine. Your job is to generate highly addictive,
meme-tier "Tech Stack & Profile Roasts" that users cannot resist sharing.
Review the user's raw input (tools, resume text, or daily workflow) and strictly output this format:
### πŸ’€ THE BRUTAL ROAST
[Provide a devastatingly witty, 2-sentence critique of their choices]
### πŸ“ˆ BRAIN DAMAGE INDEX
`[β–“β–“β–“β–“β–“β–“β–“β–“β–‘β–‘] 80%` [Generate a customized, hilariously accurate ASCII bar based on their stack]
πŸš€ VIRAL X-POST (Click to copy)
"[Insert an aggressive, high-engagement tweet under 240 chars summarizing the roast] #RoastMyStack #ViralX"
"""
class AgentResponse(BaseModel):
success: bool
content: str
async def execute_agent_prompt(user_input: str) -> AgentResponse:
api_key = os.getenv("MISTRAL_API_KEY")
if not api_key:
return AgentResponse(success=False, content="Missing MISTRAL_API_KEY in environment variable.")
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"model": MISTRAL_MODEL,
"messages": [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f"Analyze this input: {user_input}"}
],
"temperature": 0.85,
"max_tokens": 450
}
async with httpx.AsyncClient(timeout=20.0) as client:
try:
response = await client.post(MISTRAL_URL, json=payload, headers=headers)
if response.status_code != 200:
return AgentResponse(success=False, content=f"Mistral API Error Status: {response.status_code}")
raw_data = response.json()
output_text = raw_data["choices"][0]["message"]["content"]
return AgentResponse(success=True, content=output_text)
except Exception as e:
return AgentResponse(success=False, content=f"Network Error: {str(e)}")