Hanson commited on
Commit
9436bac
·
1 Parent(s): 2d5c1f0

chore: change default model to openrouter free llama3.1

Browse files
Files changed (1) hide show
  1. app.py +8 -6
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 # 💡 重新引進 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
- # 這裡只存儲 Token,保持乾淨
24
- self.hf_token = os.getenv("HF_TOKEN")
 
 
25
 
26
  def __call__(self, question: str) -> str:
27
  try:
28
- # 💡 真正的 Agent 在這裡臨時建立,且「絕對不要」加 @spaces.GPU 裝飾器
29
  model = LiteLLMModel(
30
- model_id="huggingface/Qwen/Qwen2.5-72B-Instruct",
31
- token=self.hf_token
 
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)