Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
4197b96
1
Parent(s): 6692ff0
adding whoami to system prompt
Browse files
agent/context_manager/manager.py
CHANGED
|
@@ -8,6 +8,7 @@ from pathlib import Path
|
|
| 8 |
from typing import Any
|
| 9 |
|
| 10 |
import yaml
|
|
|
|
| 11 |
from jinja2 import Template
|
| 12 |
from litellm import Message, acompletion
|
| 13 |
|
|
@@ -24,7 +25,8 @@ class ContextManager:
|
|
| 24 |
prompt_file_suffix: str = "system_prompt_v2.yaml",
|
| 25 |
):
|
| 26 |
self.system_prompt = self._load_system_prompt(
|
| 27 |
-
tool_specs or [],
|
|
|
|
| 28 |
)
|
| 29 |
self.max_context = max_context
|
| 30 |
self.compact_size = int(max_context * compact_size)
|
|
@@ -58,6 +60,7 @@ class ContextManager:
|
|
| 58 |
current_date=current_date,
|
| 59 |
current_time=current_time,
|
| 60 |
current_timezone=current_timezone,
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
def add_message(self, message: Message, token_count: int = None) -> None:
|
|
|
|
| 8 |
from typing import Any
|
| 9 |
|
| 10 |
import yaml
|
| 11 |
+
from huggingface_hub import HfApi
|
| 12 |
from jinja2 import Template
|
| 13 |
from litellm import Message, acompletion
|
| 14 |
|
|
|
|
| 25 |
prompt_file_suffix: str = "system_prompt_v2.yaml",
|
| 26 |
):
|
| 27 |
self.system_prompt = self._load_system_prompt(
|
| 28 |
+
tool_specs or [],
|
| 29 |
+
prompt_file_suffix="system_prompt_v2.yaml",
|
| 30 |
)
|
| 31 |
self.max_context = max_context
|
| 32 |
self.compact_size = int(max_context * compact_size)
|
|
|
|
| 60 |
current_date=current_date,
|
| 61 |
current_time=current_time,
|
| 62 |
current_timezone=current_timezone,
|
| 63 |
+
hf_user_info=HfApi().whoami().get("name"),
|
| 64 |
)
|
| 65 |
|
| 66 |
def add_message(self, message: Message, token_count: int = None) -> None:
|
agent/core/tools.py
CHANGED
|
@@ -35,8 +35,6 @@ from agent.tools.github_read_file import (
|
|
| 35 |
GITHUB_READ_FILE_TOOL_SPEC,
|
| 36 |
github_read_file_handler,
|
| 37 |
)
|
| 38 |
-
from agent.tools.jobs_tool import HF_JOBS_TOOL_SPEC, hf_jobs_handler
|
| 39 |
-
from agent.tools.plan_tool import PLAN_TOOL_SPEC, plan_tool_handler
|
| 40 |
from agent.tools.hf_repo_files_tool import (
|
| 41 |
HF_REPO_FILES_TOOL_SPEC,
|
| 42 |
hf_repo_files_handler,
|
|
@@ -45,6 +43,8 @@ from agent.tools.hf_repo_git_tool import (
|
|
| 45 |
HF_REPO_GIT_TOOL_SPEC,
|
| 46 |
hf_repo_git_handler,
|
| 47 |
)
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# NOTE: Private HF repo tool disabled - replaced by hf_repo_files and hf_repo_git
|
| 50 |
# from agent.tools.private_hf_repo_tools import (
|
|
@@ -57,7 +57,7 @@ warnings.filterwarnings(
|
|
| 57 |
"ignore", category=DeprecationWarning, module="aiohttp.connector"
|
| 58 |
)
|
| 59 |
|
| 60 |
-
NOT_ALLOWED_TOOL_NAMES = ["hf_jobs", "hf_doc_search", "hf_doc_fetch"]
|
| 61 |
|
| 62 |
|
| 63 |
def convert_mcp_content_to_string(content: list) -> str:
|
|
@@ -301,8 +301,6 @@ def create_builtin_tools() -> list[ToolSpec]:
|
|
| 301 |
parameters=HF_REPO_GIT_TOOL_SPEC["parameters"],
|
| 302 |
handler=hf_repo_git_handler,
|
| 303 |
),
|
| 304 |
-
|
| 305 |
-
|
| 306 |
# NOTE: Github search code tool disabled - a bit buggy
|
| 307 |
# ToolSpec(
|
| 308 |
# name=GITHUB_SEARCH_CODE_TOOL_SPEC["name"],
|
|
|
|
| 35 |
GITHUB_READ_FILE_TOOL_SPEC,
|
| 36 |
github_read_file_handler,
|
| 37 |
)
|
|
|
|
|
|
|
| 38 |
from agent.tools.hf_repo_files_tool import (
|
| 39 |
HF_REPO_FILES_TOOL_SPEC,
|
| 40 |
hf_repo_files_handler,
|
|
|
|
| 43 |
HF_REPO_GIT_TOOL_SPEC,
|
| 44 |
hf_repo_git_handler,
|
| 45 |
)
|
| 46 |
+
from agent.tools.jobs_tool import HF_JOBS_TOOL_SPEC, hf_jobs_handler
|
| 47 |
+
from agent.tools.plan_tool import PLAN_TOOL_SPEC, plan_tool_handler
|
| 48 |
|
| 49 |
# NOTE: Private HF repo tool disabled - replaced by hf_repo_files and hf_repo_git
|
| 50 |
# from agent.tools.private_hf_repo_tools import (
|
|
|
|
| 57 |
"ignore", category=DeprecationWarning, module="aiohttp.connector"
|
| 58 |
)
|
| 59 |
|
| 60 |
+
NOT_ALLOWED_TOOL_NAMES = ["hf_jobs", "hf_doc_search", "hf_doc_fetch", "hf_whoami"]
|
| 61 |
|
| 62 |
|
| 63 |
def convert_mcp_content_to_string(content: list) -> str:
|
|
|
|
| 301 |
parameters=HF_REPO_GIT_TOOL_SPEC["parameters"],
|
| 302 |
handler=hf_repo_git_handler,
|
| 303 |
),
|
|
|
|
|
|
|
| 304 |
# NOTE: Github search code tool disabled - a bit buggy
|
| 305 |
# ToolSpec(
|
| 306 |
# name=GITHUB_SEARCH_CODE_TOOL_SPEC["name"],
|
agent/prompts/system_prompt_v2.yaml
CHANGED
|
@@ -2,6 +2,7 @@ system_prompt: |
|
|
| 2 |
You are Hugging Face Agent, a skilled AI assistant for machine learning engineering with deep expertise in the Hugging Face ecosystem. You help users accomplish ML tasks (training, fine-tuning, data processing, inference, evaluation) by interacting with Hugging Face services via {{ num_tools }} specialized tools.
|
| 3 |
|
| 4 |
_Current Time: **{{ current_date }} {{ current_time }} ({{ current_timezone }})**_
|
|
|
|
| 5 |
|
| 6 |
# Core Mission & Behavior
|
| 7 |
|
|
@@ -330,11 +331,6 @@ system_prompt: |
|
|
| 330 |
- Check model size, architecture, requirements
|
| 331 |
- Verify dataset columns, splits, size
|
| 332 |
|
| 333 |
-
**hf_whoami:**
|
| 334 |
-
- Check authentication status
|
| 335 |
-
- Verify token has correct permissions
|
| 336 |
-
- Use before operations requiring write access
|
| 337 |
-
|
| 338 |
## Execution & Storage Tools
|
| 339 |
|
| 340 |
**hf_jobs:**
|
|
@@ -456,8 +452,6 @@ system_prompt: |
|
|
| 456 |
hub_model_id="username/model-name", # ← Must be set
|
| 457 |
# ...
|
| 458 |
)
|
| 459 |
-
|
| 460 |
-
# Verify token: hf_whoami()
|
| 461 |
```
|
| 462 |
|
| 463 |
### Dataset Format Mismatch
|
|
|
|
| 2 |
You are Hugging Face Agent, a skilled AI assistant for machine learning engineering with deep expertise in the Hugging Face ecosystem. You help users accomplish ML tasks (training, fine-tuning, data processing, inference, evaluation) by interacting with Hugging Face services via {{ num_tools }} specialized tools.
|
| 3 |
|
| 4 |
_Current Time: **{{ current_date }} {{ current_time }} ({{ current_timezone }})**_
|
| 5 |
+
{% if hf_user_info %}_AUTHENTICATED ON HF AS: **{{ hf_user_info }}**_{% endif %}
|
| 6 |
|
| 7 |
# Core Mission & Behavior
|
| 8 |
|
|
|
|
| 331 |
- Check model size, architecture, requirements
|
| 332 |
- Verify dataset columns, splits, size
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
## Execution & Storage Tools
|
| 335 |
|
| 336 |
**hf_jobs:**
|
|
|
|
| 452 |
hub_model_id="username/model-name", # ← Must be set
|
| 453 |
# ...
|
| 454 |
)
|
|
|
|
|
|
|
| 455 |
```
|
| 456 |
|
| 457 |
### Dataset Format Mismatch
|