Imnotchis commited on
Commit
812df53
·
verified ·
1 Parent(s): 19e3276

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -5,7 +5,7 @@ from pathlib import Path
5
  import gradio as gr
6
  import pandas as pd
7
  import requests
8
- from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, VisitWebpageTool
9
 
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -50,13 +50,21 @@ class BasicAgent:
50
  search_tool = DuckDuckGoSearchTool()
51
  visit_tool = VisitWebpageTool()
52
 
53
- # Setup LLM sử dụng API miễn phí của Hugging Face (Không tốn tiền)
54
- # Lưu ý: Cần thêm secret HF_TOKEN trong cài đặt Space
55
- self.model = HfApiModel(
56
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
57
- token=os.environ.get("HF_TOKEN")
 
58
  )
59
 
 
 
 
 
 
 
 
60
  # Setup CodeAgent
61
  self.agent = CodeAgent(
62
  tools=[search_tool, visit_tool],
 
5
  import gradio as gr
6
  import pandas as pd
7
  import requests
8
+ from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool, VisitWebpageTool
9
 
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
50
  search_tool = DuckDuckGoSearchTool()
51
  visit_tool = VisitWebpageTool()
52
 
53
+ # Setup LLM sử dụng API miễn phí của Hugging Face thông qua cổng OpenAI-compatible
54
+ # LƯU Ý: Đảm bảo Space của bạn có secret tên là HF_TOKEN
55
+ self.model = OpenAIServerModel(
56
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
57
+ api_base="https://api-inference.huggingface.co/v1/",
58
+ api_key=os.environ.get("HF_TOKEN")
59
  )
60
 
61
+ # --- GỢI Ý THÊM (Tùy chọn): Nếu mạng HF bị chậm, bạn có thể bỏ comment đoạn dưới để dùng Groq Free ---
62
+ # self.model = OpenAIServerModel(
63
+ # model_id="qwen-2.5-coder-32b",
64
+ # api_base="https://api.groq.com/openai/v1",
65
+ # api_key=os.environ.get("GROQ_API_KEY")
66
+ # )
67
+
68
  # Setup CodeAgent
69
  self.agent = CodeAgent(
70
  tools=[search_tool, visit_tool],