Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,20 +30,43 @@ def call_groq_api(prompt, model="llama3-70b-8192"):
|
|
30 |
else:
|
31 |
return f"[Groq API Error] {response.text}"
|
32 |
|
33 |
-
def call_blackbox_agent(prompt):
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
|
|
|
30 |
else:
|
31 |
return f"[Groq API Error] {response.text}"
|
32 |
|
33 |
+
# def call_blackbox_agent(prompt):
|
34 |
+
# url = "https://api.code.blackbox.ai/v1/chat/completions"
|
35 |
+
# headers = {
|
36 |
+
# "Content-Type": "application/json",
|
37 |
+
# "Authorization": f"Bearer {BLACKBOX_API_KEY}"
|
38 |
+
# }
|
39 |
+
# data = {
|
40 |
+
# "message": prompt
|
41 |
+
# }
|
42 |
+
# response = requests.post(url, headers=headers, json=data)
|
43 |
+
# if response.status_code == 200:
|
44 |
+
# return response.json().get("response", response.json())
|
45 |
+
# else:
|
46 |
+
# return f"[Blackbox API Error] {response.text}"
|
47 |
+
|
48 |
+
def call_blackbox_agent(messages, model="gpt-4o"):
|
49 |
+
"""
|
50 |
+
messages: list of dicts, e.g.
|
51 |
+
[
|
52 |
+
{"role": "system", "content": "You are a helpful coding assistant."},
|
53 |
+
{"role": "user", "content": "Refactor this code: ..."}
|
54 |
+
]
|
55 |
+
"""
|
56 |
+
url = "http://localhost:4000/v1/chat/completions"
|
57 |
+
headers = {
|
58 |
+
"Content-Type": "application/json",
|
59 |
+
"Authorization": f"Bearer {BLACKBOX_API_KEY}"
|
60 |
+
}
|
61 |
+
data = {
|
62 |
+
"model": model,
|
63 |
+
"messages": messages
|
64 |
+
}
|
65 |
+
response = requests.post(url, headers=headers, json=data)
|
66 |
+
if response.status_code == 200:
|
67 |
+
return response.json()["choices"][0]["message"]["content"]
|
68 |
+
else:
|
69 |
+
return call_groq_api(messages[-1]["content"])
|
70 |
|
71 |
|
72 |
|