mirjam-m commited on
Commit
e7531c4
·
1 Parent(s): b192ffa
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -1,13 +1,17 @@
1
  import inspect
2
  import os
3
 
 
 
4
  import gradio as gr
5
  import pandas as pd
6
  import requests
 
 
 
7
 
8
- from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
9
 
10
- hf_token = os.getenv("HF_TOKEN")
11
 
12
 
13
  # (Keep Constants as is)
@@ -19,20 +23,24 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
20
  class BasicAgent:
21
  def __init__(self):
22
- self.llm = HuggingFaceInferenceAPI(
23
- model_name="deepseek-ai/DeepSeek-R1",
24
- temperature=0.7,
25
- max_tokens=100,
26
- token=hf_token,
27
- provider="nebius",
28
- )
29
 
30
  def __call__(self, question: str) -> str:
31
  print(f"Agent received question (first 50 chars): {question[:50]}...")
32
- response = self.llm.complete("Hello, how are you?")
33
-
34
- print(f"Agent returning answer: {response}")
35
- return response.text
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  def run_and_submit_all(profile: gr.OAuthProfile | None):
@@ -91,7 +99,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
91
  results_log = []
92
  answers_payload = []
93
  print(f"Running agent on {len(questions_data)} questions...")
94
- for item in questions_data:
95
  task_id = item.get("task_id")
96
  question_text = item.get("question")
97
  if not task_id or question_text is None:
 
1
  import inspect
2
  import os
3
 
4
+ from typing import Any, Dict, List, Optional, TypedDict
5
+
6
  import gradio as gr
7
  import pandas as pd
8
  import requests
9
+ from langchain_core.messages import HumanMessage
10
+ from langchain_openai import ChatOpenAI
11
+ from langgraph.graph import END, START, StateGraph
12
 
 
13
 
14
+ hf_token = os.getenv("OPENAI_API_KEY")
15
 
16
 
17
  # (Keep Constants as is)
 
23
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
24
  class BasicAgent:
25
  def __init__(self):
26
+ self.model = ChatOpenAI(model="gpt-4o", temperature=0)
 
 
 
 
 
 
27
 
28
  def __call__(self, question: str) -> str:
29
  print(f"Agent received question (first 50 chars): {question[:50]}...")
30
+ prompt = f"""
31
+ You are a general AI assistant. I will ask you a question.
32
+ Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
33
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
34
+ If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
35
+ If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
36
+ If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
37
+ Question: {question}
38
+ """
39
+ messages = [HumanMessage(content=prompt)]
40
+ response = self.model.invoke(messages)
41
+
42
+ print(f"Agent returning answer: {response.text()}")
43
+ return response.text()
44
 
45
 
46
  def run_and_submit_all(profile: gr.OAuthProfile | None):
 
99
  results_log = []
100
  answers_payload = []
101
  print(f"Running agent on {len(questions_data)} questions...")
102
+ for item in questions_data[:1]:
103
  task_id = item.get("task_id")
104
  question_text = item.get("question")
105
  if not task_id or question_text is None: