Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,20 +22,27 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 22 |
class SmartAgent:
|
| 23 |
def __init__(self):
|
| 24 |
self.generator = pipeline(
|
| 25 |
-
"
|
| 26 |
-
model="
|
| 27 |
-
max_new_tokens=
|
| 28 |
temperature=0.3,
|
| 29 |
-
do_sample=True,
|
| 30 |
device_map="auto"
|
| 31 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
self.system_prompt = (
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
| 37 |
-
"If
|
| 38 |
-
"digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules."
|
| 39 |
)
|
| 40 |
|
| 41 |
def extract_final_answer(self, text: str) -> str:
|
|
@@ -45,7 +52,8 @@ class SmartAgent:
|
|
| 45 |
return text.strip()
|
| 46 |
|
| 47 |
def __call__(self, question: str) -> str:
|
| 48 |
-
prompt = f"{self.system_prompt}\nQuestion: {question}\n"
|
|
|
|
| 49 |
output = self.generator(prompt, return_full_text=False)[0]['generated_text']
|
| 50 |
answer = self.extract_final_answer(output)
|
| 51 |
print(f"[DEBUG] Question: {question}")
|
|
|
|
| 22 |
class SmartAgent:
|
| 23 |
def __init__(self):
|
| 24 |
self.generator = pipeline(
|
| 25 |
+
"text2text-generation",
|
| 26 |
+
model="google/flan-t5-base",
|
| 27 |
+
max_new_tokens=128,
|
| 28 |
temperature=0.3,
|
|
|
|
| 29 |
device_map="auto"
|
| 30 |
)
|
| 31 |
+
|
| 32 |
+
# self.system_prompt = (
|
| 33 |
+
# "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer "
|
| 34 |
+
# "with the following template: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR "
|
| 35 |
+
# "as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, "
|
| 36 |
+
# "don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
|
| 37 |
+
# "If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the "
|
| 38 |
+
# "digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules."
|
| 39 |
+
# )
|
| 40 |
self.system_prompt = (
|
| 41 |
+
"Answer the question briefly and precisely. Your answer should be as few words as possible. "
|
| 42 |
+
"If you are asked for a string, don't use articles, neither abbreviations unless specified otherwise. "
|
| 43 |
+
"If the answer is a number, write only the number. "
|
| 44 |
+
"Don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
|
| 45 |
+
"If it is a list, use a comma-separated list with no explanations. "
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
def extract_final_answer(self, text: str) -> str:
|
|
|
|
| 52 |
return text.strip()
|
| 53 |
|
| 54 |
def __call__(self, question: str) -> str:
|
| 55 |
+
# prompt = f"{self.system_prompt}\nQuestion: {question}\n"
|
| 56 |
+
prompt = f"{self.system_prompt} Question: {question_text}"
|
| 57 |
output = self.generator(prompt, return_full_text=False)[0]['generated_text']
|
| 58 |
answer = self.extract_final_answer(output)
|
| 59 |
print(f"[DEBUG] Question: {question}")
|