Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,8 +20,6 @@ from langchain_community.chat_models import ChatHuggingFace
|
|
| 20 |
# --- Constants ---
|
| 21 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 22 |
|
| 23 |
-
hf_token = os.getenv("HF_TOKEN")
|
| 24 |
-
|
| 25 |
# --- Basic Agent Definition ---
|
| 26 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 27 |
class BasicAgent:
|
|
@@ -35,13 +33,27 @@ class BasicAgent:
|
|
| 35 |
|
| 36 |
class ZephyrPipelineModel:
|
| 37 |
def __init__(self):
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def __call__(self, prompt: str) -> str:
|
| 41 |
-
# Zephyr wants a list of messages
|
| 42 |
messages = [{"role": "user", "content": prompt}]
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
class LangGraphAgent:
|
| 47 |
def __init__(self):
|
|
|
|
| 20 |
# --- Constants ---
|
| 21 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 22 |
|
|
|
|
|
|
|
| 23 |
# --- Basic Agent Definition ---
|
| 24 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 25 |
class BasicAgent:
|
|
|
|
| 33 |
|
| 34 |
class ZephyrPipelineModel:
|
| 35 |
def __init__(self):
|
| 36 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 37 |
+
if not hf_token:
|
| 38 |
+
raise ValueError("HF_TOKEN environment variable not set.")
|
| 39 |
+
|
| 40 |
+
self.client = InferenceClient(
|
| 41 |
+
model="HuggingFaceH4/zephyr-7b-beta",
|
| 42 |
+
token=hf_token,
|
| 43 |
+
)
|
| 44 |
|
| 45 |
def __call__(self, prompt: str) -> str:
|
|
|
|
| 46 |
messages = [{"role": "user", "content": prompt}]
|
| 47 |
+
try:
|
| 48 |
+
completion = self.client.chat.completions.create(
|
| 49 |
+
model="HuggingFaceH4/zephyr-7b-beta",
|
| 50 |
+
messages=messages,
|
| 51 |
+
max_tokens=512,
|
| 52 |
+
temperature=0.7,
|
| 53 |
+
)
|
| 54 |
+
return completion.choices[0].message.content
|
| 55 |
+
except Exception as e:
|
| 56 |
+
return f"❌ Inference failed: {str(e)}"
|
| 57 |
|
| 58 |
class LangGraphAgent:
|
| 59 |
def __init__(self):
|