Spaces:
Runtime error
Runtime error
Enhance SYSTEM_PROMPT in SmolAgent for clarity and accuracy, update model ID, and simplify response handling.
Browse files9 unmodified lines10111213141516171819202122232425262728297 unmodified lines373839404142436 unmodified lines5051525354555657585960616263646566676869707172737475767778799 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"HF_TOKEN = os.getenv("HF_TOKEN")SYSTEM_PROMPT = """You are an expert assistant answering questions for evaluation where answers are checked using exact string match.Rules:- Return ONLY the final answer on a single line.- Do NOT include reasoning or extra text.- If the answer is a number, return the plain number with no commas, no currency symbols, and no units unless explicitly required.- If the answer is a string, use lowercase, no articles, no abbreviations, and digits written in plain text unless specified.- If the answer is a comma-separated list, follow the above rules for each element, with no spaces after commas.- Do NOT write "Answer:" or "FINAL ANSWER:" before your response.- If unsure, guess concisely.Always strictly follow these instructions to ensure exact match."""# --- Smol Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class SmolAgent:7 unmodified lines# 3. Initialize the SmolLM modelmodel = InferenceClientModel(model_id="HuggingFaceTB/SmolLM-360M-Instruct",token=hf_token,)6 unmodified linesprint("SmolAgent initialized")def __call__(self, question: str) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")try:# The system prompt is already set, just pass the question.full_response = self._agent.run(question)print(f"Agent full response: {full_response}")# Parse the response to extract the final answerif "FINAL ANSWER:" in full_response:# Split and get the part after "FINAL ANSWER:"final_answer_part = full_response.split("FINAL ANSWER:")[1]# Remove brackets if they exist and strip whitespacefinal_answer = final_answer_part.strip()if final_answer.startswith('[') and final_answer.endswith(']'):final_answer = final_answer[1:-1]print(f"Agent returning parsed answer: {final_answer}")return final_answerelse:print("Warning: 'FINAL ANSWER:' not found in response. Returning full response.")return full_responseexcept Exception as e:print(f"Error running agent: {e}")return f"AGENT ERROR: {e}"def run_and_submit_all( profile: gr.OAuthProfile | None):9 unmodified lines1011121314151617181920212223242526272829307 unmodified lines383940414243446 unmodified lines51525354555657585960616263649 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"HF_TOKEN = os.getenv("HF_TOKEN")SYSTEM_PROMPT = """You are a helpful assistant answering evaluation questions that will be scored using exact string match.Instructions:- Return ONLY the final answer on a single line.- Do NOT include explanations or reasoning.- Do NOT write "Answer:" or "FINAL ANSWER:" before your response.- If the answer is a number, return the plain number with no commas, currency symbols, or units unless explicitly required.- If the answer is a string, use lowercase, no articles, no abbreviations, and digits in plain text unless specified otherwise.- If the answer is a comma-separated list, follow the above rules for each element with no spaces after commas.- If unsure, guess concisely.Always strictly follow these instructions to maximize exact match accuracy."""# --- Smol Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class SmolAgent:7 unmodified lines# 3. Initialize the SmolLM modelmodel = InferenceClientModel(model_id="HuggingFaceTB/SmolLM-1.7B-Instruct",token=hf_token,)6 unmodified linesprint("SmolAgent initialized")def __call__(self, question: str) -> str:print(f"\n🪐 Running on question:\n{question}\n")try:answer = self._agent.run(prompt)print(f"Agent returning answer: {answer}")return str(answer)except Exception as e:print(f"Agent error: {e}")return f"Agent error: {e}"def run_and_submit_all( profile: gr.OAuthProfile | None):
app.py+15-30