Spaces:
Sleeping
Sleeping
Hanson commited on
Commit ·
9436bac
1
Parent(s): 2d5c1f0
chore: change default model to openrouter free llama3.1
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
|
| 14 |
import os
|
| 15 |
-
import spaces
|
| 16 |
|
| 17 |
@spaces.GPU
|
| 18 |
def fake_gpu_function():
|
|
@@ -20,15 +20,17 @@ def fake_gpu_function():
|
|
| 20 |
|
| 21 |
class BasicAgent:
|
| 22 |
def __init__(self):
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
try:
|
| 28 |
-
# 💡 真正的 Agent 在這裡臨時建立,且「絕對不要」加 @spaces.GPU 裝飾器
|
| 29 |
model = LiteLLMModel(
|
| 30 |
-
model_id=
|
| 31 |
-
|
|
|
|
| 32 |
)
|
| 33 |
search_tool = DuckDuckGoSearchTool()
|
| 34 |
agent = CodeAgent(tools=[search_tool], model=model)
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
|
| 14 |
import os
|
| 15 |
+
import spaces
|
| 16 |
|
| 17 |
@spaces.GPU
|
| 18 |
def fake_gpu_function():
|
|
|
|
| 20 |
|
| 21 |
class BasicAgent:
|
| 22 |
def __init__(self):
|
| 23 |
+
self.openrouter_key = os.getenv("OPENROUTER_API_KEY")
|
| 24 |
+
|
| 25 |
+
# 💡 將預設模型改為 OpenRouter 提供的免費 Llama 3.1 模型
|
| 26 |
+
self.model_id = os.getenv("HF_MODEL_ID", "openrouter/meta-llama/llama-3.1-8b-instruct:free")
|
| 27 |
|
| 28 |
def __call__(self, question: str) -> str:
|
| 29 |
try:
|
|
|
|
| 30 |
model = LiteLLMModel(
|
| 31 |
+
model_id=self.model_id,
|
| 32 |
+
api_key=self.openrouter_key,
|
| 33 |
+
api_base="https://openrouter.ai/api/v1"
|
| 34 |
)
|
| 35 |
search_tool = DuckDuckGoSearchTool()
|
| 36 |
agent = CodeAgent(tools=[search_tool], model=model)
|