Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,29 +24,18 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
24 |
load_dotenv()
|
25 |
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
31 |
-
|
32 |
-
class MistralToolCallingAgentTool:
|
33 |
-
name = "mistral_tool_agent"
|
34 |
-
description = "Uses Mistral-7B-Instruct to answer questions using code or reasoning"
|
35 |
|
36 |
def __init__(self):
|
37 |
-
self.model_id = "
|
38 |
-
token = os.getenv("HF_TOKEN")
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id, token=token)
|
45 |
-
self.model = AutoModelForCausalLM.from_pretrained(
|
46 |
-
self.model_id, device_map="auto", torch_dtype="auto", token=token
|
47 |
-
)
|
48 |
-
except Exception as e:
|
49 |
-
raise RuntimeError(f"Error loading Mistral model: {e}")
|
50 |
|
51 |
self.pipeline = pipeline(
|
52 |
"text-generation",
|
@@ -69,6 +58,7 @@ class MistralToolCallingAgentTool:
|
|
69 |
prompt = f"""You are a helpful assistant. Use code to solve questions that involve calculations.
|
70 |
If code is needed, return a block like <tool>code</tool>. End your answer with <final>answer</final>.
|
71 |
|
|
|
72 |
Question: {question}
|
73 |
Answer:"""
|
74 |
|
|
|
24 |
load_dotenv()
|
25 |
|
26 |
|
27 |
+
class ZephyrToolCallingAgentTool:
|
28 |
+
name = "zephyr_tool_agent"
|
29 |
+
description = "Uses Zephyr-7B to answer questions using code or reasoning"
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def __init__(self):
|
32 |
+
self.model_id = "HuggingFaceH4/zephyr-7b-beta"
|
33 |
+
token = os.getenv("HF_TOKEN") # Optional unless private
|
34 |
|
35 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id, token=token)
|
36 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
37 |
+
self.model_id, device_map="auto", torch_dtype="auto", token=token
|
38 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
self.pipeline = pipeline(
|
41 |
"text-generation",
|
|
|
58 |
prompt = f"""You are a helpful assistant. Use code to solve questions that involve calculations.
|
59 |
If code is needed, return a block like <tool>code</tool>. End your answer with <final>answer</final>.
|
60 |
|
61 |
+
|
62 |
Question: {question}
|
63 |
Answer:"""
|
64 |
|