Spaces:
Sleeping
Sleeping
HfApiModel is back for test
Browse files
agent.py
CHANGED
@@ -5,7 +5,7 @@ from smolagents import (
|
|
5 |
VisitWebpageTool,
|
6 |
PythonInterpreterTool,
|
7 |
InferenceClientModel,
|
8 |
-
|
9 |
tool
|
10 |
)
|
11 |
from typing import List, Dict, Any, Optional
|
@@ -31,23 +31,22 @@ class QAgent:
|
|
31 |
self.system_prompt = system_prompt
|
32 |
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
# el
|
49 |
|
50 |
-
|
51 |
if api_key is None:
|
52 |
api_key = os.getenv("Q_NEB_TOK")
|
53 |
if not api_key:
|
|
|
5 |
VisitWebpageTool,
|
6 |
PythonInterpreterTool,
|
7 |
InferenceClientModel,
|
8 |
+
HfApiModel, # import bug from smolagents after adding duckduckgo-search in requirements
|
9 |
tool
|
10 |
)
|
11 |
from typing import List, Dict, Any, Optional
|
|
|
31 |
self.system_prompt = system_prompt
|
32 |
|
33 |
|
34 |
+
if model_type == "HfApiModel":
|
35 |
+
if api_key is None:
|
36 |
+
api_key = os.getenv("SP_HF_TOK")
|
37 |
+
if not api_key:
|
38 |
+
raise ValueError("No API Key found for HuggingFace. Please set SP_HF_TOK or pass api_key.")
|
39 |
+
|
40 |
+
if self.verbose:
|
41 |
+
print(f"Using Hugging Face token: {api_key[:5]}... (HfApiModel mode)")
|
42 |
+
|
43 |
+
self.model = HfApiModel(
|
44 |
+
model_id=model_id or "Qwen/Qwen2.5-Coder-32B-Instruct", # précédemment : or "meta-llama/Llama-3-70B-Instruct",
|
45 |
+
token=api_key
|
46 |
+
# temperature=temperature
|
47 |
+
)
|
|
|
48 |
|
49 |
+
elif model_type == "InferenceClientModel":
|
50 |
if api_key is None:
|
51 |
api_key = os.getenv("Q_NEB_TOK")
|
52 |
if not api_key:
|