wt002 commited on
Commit
1e4945c
·
verified ·
1 Parent(s): d224c1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -20
app.py CHANGED
@@ -24,29 +24,18 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
24
  load_dotenv()
25
 
26
 
27
- import os
28
- import io
29
- import contextlib
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 = "mistralai/Mistral-7B-Instruct-v0.3"
38
- token = os.getenv("HF_TOKEN")
39
 
40
- if token is None:
41
- raise EnvironmentError("HF_TOKEN is not set in environment variables.")
42
-
43
- try:
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