Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -3,16 +3,27 @@ import gradio as gr
|
|
| 3 |
from zhipuai import ZhipuAI
|
| 4 |
|
| 5 |
# === GLM setup ===
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# === Helper: call GLM ===
|
| 9 |
def glm_call(prompt: str) -> str:
|
|
|
|
|
|
|
| 10 |
try:
|
|
|
|
| 11 |
resp = zhipu_client.chat.completions.create(
|
| 12 |
model="glm-4-0520",
|
| 13 |
messages=[{"role": "user", "content": prompt}]
|
| 14 |
)
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
return f"[GLM Error] {e}"
|
| 18 |
|
|
@@ -29,11 +40,11 @@ def langgraph_agent(prompt: str) -> str:
|
|
| 29 |
|
| 30 |
# CrewAI Agent (stub for now)
|
| 31 |
def crewai_agent(prompt: str) -> str:
|
| 32 |
-
return "[CrewAI Agent]
|
| 33 |
|
| 34 |
# OpenDevin Agent (stub for now)
|
| 35 |
def opendevin_agent(prompt: str) -> str:
|
| 36 |
-
return "[OpenDevin Agent]
|
| 37 |
|
| 38 |
|
| 39 |
# === Gradio Handlers ===
|
|
@@ -101,3 +112,4 @@ if __name__ == "__main__":
|
|
| 101 |
|
| 102 |
|
| 103 |
|
|
|
|
|
|
| 3 |
from zhipuai import ZhipuAI
|
| 4 |
|
| 5 |
# === GLM setup ===
|
| 6 |
+
api_key = os.getenv("ZHIPUAI_API_KEY")
|
| 7 |
+
if not api_key:
|
| 8 |
+
print("β [Startup Error] Missing ZHIPUAI_API_KEY in environment variables.")
|
| 9 |
+
else:
|
| 10 |
+
print("β
[Startup] ZHIPUAI_API_KEY loaded successfully.")
|
| 11 |
+
|
| 12 |
+
zhipu_client = ZhipuAI(api_key=api_key) if api_key else None
|
| 13 |
|
| 14 |
# === Helper: call GLM ===
|
| 15 |
def glm_call(prompt: str) -> str:
|
| 16 |
+
if not zhipu_client:
|
| 17 |
+
return "[GLM Error] API key not found. Please set ZHIPUAI_API_KEY."
|
| 18 |
try:
|
| 19 |
+
print(f"π‘ Sending prompt to GLM: {prompt}")
|
| 20 |
resp = zhipu_client.chat.completions.create(
|
| 21 |
model="glm-4-0520",
|
| 22 |
messages=[{"role": "user", "content": prompt}]
|
| 23 |
)
|
| 24 |
+
reply = resp.choices[0].message["content"]
|
| 25 |
+
print(f"π€ GLM replied: {reply}")
|
| 26 |
+
return reply
|
| 27 |
except Exception as e:
|
| 28 |
return f"[GLM Error] {e}"
|
| 29 |
|
|
|
|
| 40 |
|
| 41 |
# CrewAI Agent (stub for now)
|
| 42 |
def crewai_agent(prompt: str) -> str:
|
| 43 |
+
return "[CrewAI Agent] β not connected to GLM (stubbed for now)"
|
| 44 |
|
| 45 |
# OpenDevin Agent (stub for now)
|
| 46 |
def opendevin_agent(prompt: str) -> str:
|
| 47 |
+
return "[OpenDevin Agent] β not connected to GLM (stubbed for now)"
|
| 48 |
|
| 49 |
|
| 50 |
# === Gradio Handlers ===
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
+
|