Spaces:
Sleeping
Sleeping
Ishar Maharjan commited on
Commit ·
d27085c
1
Parent(s): 959eb34
use openai
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +17 -14
- requirements.txt +1 -1
__pycache__/app.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -6,18 +6,19 @@ from typing import Any
|
|
| 6 |
import gradio as gr
|
| 7 |
import pandas as pd
|
| 8 |
import requests
|
| 9 |
-
from smolagents import CodeAgent,
|
| 10 |
from smolagents.default_tools import DuckDuckGoSearchTool, VisitWebpageTool
|
| 11 |
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
-
|
| 14 |
|
| 15 |
|
| 16 |
@dataclass
|
| 17 |
class AgentConfig:
|
| 18 |
api_base_url: str = DEFAULT_API_URL
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
max_steps: int = 8
|
| 22 |
web_timeout_sec: int = 15
|
| 23 |
max_file_chars: int = 12000
|
|
@@ -49,14 +50,15 @@ def submit_answers(api_base_url: str, payload: dict[str, Any]) -> dict[str, Any]
|
|
| 49 |
class GAIASmolAgent:
|
| 50 |
def __init__(self, config: AgentConfig):
|
| 51 |
self.config = config
|
| 52 |
-
|
| 53 |
-
if not
|
| 54 |
-
raise ValueError(f"Missing required secret: {config.
|
| 55 |
-
|
| 56 |
-
self.model =
|
| 57 |
-
model_id=config.
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
max_tokens=1200,
|
| 61 |
)
|
| 62 |
self.http = requests.Session()
|
|
@@ -300,9 +302,10 @@ with gr.Blocks() as demo:
|
|
| 300 |
2. Submit generated answers to leaderboard scoring.
|
| 301 |
|
| 302 |
Required Space secrets:
|
| 303 |
-
- `
|
| 304 |
Optional:
|
| 305 |
-
- `
|
|
|
|
| 306 |
"""
|
| 307 |
)
|
| 308 |
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
import pandas as pd
|
| 8 |
import requests
|
| 9 |
+
from smolagents import CodeAgent, OpenAIServerModel, tool
|
| 10 |
from smolagents.default_tools import DuckDuckGoSearchTool, VisitWebpageTool
|
| 11 |
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
+
DEFAULT_OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-4o-mini")
|
| 14 |
|
| 15 |
|
| 16 |
@dataclass
|
| 17 |
class AgentConfig:
|
| 18 |
api_base_url: str = DEFAULT_API_URL
|
| 19 |
+
openai_model: str = DEFAULT_OPENAI_MODEL
|
| 20 |
+
openai_api_key_env: str = "OPENAI_API_KEY"
|
| 21 |
+
openai_api_base: str = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
|
| 22 |
max_steps: int = 8
|
| 23 |
web_timeout_sec: int = 15
|
| 24 |
max_file_chars: int = 12000
|
|
|
|
| 50 |
class GAIASmolAgent:
|
| 51 |
def __init__(self, config: AgentConfig):
|
| 52 |
self.config = config
|
| 53 |
+
api_key = os.getenv(config.openai_api_key_env)
|
| 54 |
+
if not api_key:
|
| 55 |
+
raise ValueError(f"Missing required secret: {config.openai_api_key_env}")
|
| 56 |
+
|
| 57 |
+
self.model = OpenAIServerModel(
|
| 58 |
+
model_id=config.openai_model,
|
| 59 |
+
api_base=config.openai_api_base,
|
| 60 |
+
api_key=api_key,
|
| 61 |
+
temperature=0.0,
|
| 62 |
max_tokens=1200,
|
| 63 |
)
|
| 64 |
self.http = requests.Session()
|
|
|
|
| 302 |
2. Submit generated answers to leaderboard scoring.
|
| 303 |
|
| 304 |
Required Space secrets:
|
| 305 |
+
- `OPENAI_API_KEY`
|
| 306 |
Optional:
|
| 307 |
+
- `OPENAI_MODEL` (default: `gpt-4o-mini`)
|
| 308 |
+
- `OPENAI_API_BASE` (default: `https://api.openai.com/v1`)
|
| 309 |
"""
|
| 310 |
)
|
| 311 |
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
pandas
|
| 4 |
-
huggingface_hub
|
| 5 |
smolagents[toolkit]
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
pandas
|
|
|
|
| 4 |
smolagents[toolkit]
|
| 5 |
+
openai
|