Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Henri Bonamy commited on
Commit ·
c2cdd0d
1
Parent(s): 46d481e
private tool handles spaces better + prompt improvements for reliability
Browse files
agent/prompts/system_prompt.yaml
CHANGED
|
@@ -17,7 +17,8 @@ system_prompt: |
|
|
| 17 |
2. **THEN**: Formulate a plan based on research findings. Pass todos to the PlanTool. Update as progress is made.
|
| 18 |
|
| 19 |
3. **FINALLY**: Implement using researched approaches
|
| 20 |
-
- Search
|
|
|
|
| 21 |
- Use all available tools to complete the task
|
| 22 |
- Leverage existing resources before creating new ones
|
| 23 |
- Invoke multiple independent tools simultaneously for efficiency
|
|
|
|
| 17 |
2. **THEN**: Formulate a plan based on research findings. Pass todos to the PlanTool. Update as progress is made.
|
| 18 |
|
| 19 |
3. **FINALLY**: Implement using researched approaches
|
| 20 |
+
- Search HF Hub to find the exact user-specified model and dataset. If you can't, or you change model / dataset, confirm explicitely with user beforehand.
|
| 21 |
+
- If user has not provided the model or the dataset, suggest different options, and let it choose before proceeding.
|
| 22 |
- Use all available tools to complete the task
|
| 23 |
- Leverage existing resources before creating new ones
|
| 24 |
- Invoke multiple independent tools simultaneously for efficiency
|
agent/tools/private_hf_repo_tools.py
CHANGED
|
@@ -159,7 +159,20 @@ Call this tool with:
|
|
| 159 |
}
|
| 160 |
}
|
| 161 |
```
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
### Check if a repository exists
|
| 165 |
Call this tool with:
|
|
@@ -261,13 +274,15 @@ Call this tool with:
|
|
| 261 |
|
| 262 |
# Create repo if needed
|
| 263 |
if not repo_exists and create_if_missing:
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
|
|
|
|
|
|
| 271 |
elif not repo_exists:
|
| 272 |
return {
|
| 273 |
"formatted": f"Repository {repo_id} does not exist. Set create_if_missing: true to create it.",
|
|
@@ -332,6 +347,7 @@ Call this tool with:
|
|
| 332 |
|
| 333 |
repo_type = args.get("repo_type", "dataset")
|
| 334 |
private = True # Always create private repos
|
|
|
|
| 335 |
|
| 336 |
try:
|
| 337 |
# Check if repo already exists
|
|
@@ -347,14 +363,27 @@ Call this tool with:
|
|
| 347 |
"resultsShared": 1,
|
| 348 |
}
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
# Create repository
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
response = f"""✓ Repository created successfully!
|
| 360 |
|
|
@@ -586,7 +615,8 @@ PRIVATE_HF_REPO_TOOL_SPEC = {
|
|
| 586 |
"description": (
|
| 587 |
"Operation-specific arguments as a JSON object. "
|
| 588 |
"Write ops: file_content (string/bytes), path_in_repo (string), repo_id (string), "
|
| 589 |
-
"repo_type (dataset/model/space), create_if_missing (boolean), commit_message (string)
|
|
|
|
| 590 |
"Read ops: repo_id (string), path_in_repo (for read_file), repo_type (optional)."
|
| 591 |
),
|
| 592 |
"additionalProperties": True,
|
|
|
|
| 159 |
}
|
| 160 |
}
|
| 161 |
```
|
| 162 |
+
|
| 163 |
+
### Create a Space
|
| 164 |
+
Call this tool with:
|
| 165 |
+
```json
|
| 166 |
+
{
|
| 167 |
+
"operation": "create_repo",
|
| 168 |
+
"args": {
|
| 169 |
+
"repo_id": "my-gradio-app",
|
| 170 |
+
"repo_type": "space",
|
| 171 |
+
"space_sdk": "gradio"
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
```
|
| 175 |
+
Note: Repositories are always created as private. For spaces, `space_sdk` is required (gradio, streamlit, static, or docker).
|
| 176 |
|
| 177 |
### Check if a repository exists
|
| 178 |
Call this tool with:
|
|
|
|
| 274 |
|
| 275 |
# Create repo if needed
|
| 276 |
if not repo_exists and create_if_missing:
|
| 277 |
+
create_args = {
|
| 278 |
+
"repo_id": repo_id,
|
| 279 |
+
"repo_type": repo_type,
|
| 280 |
+
"private": True,
|
| 281 |
+
}
|
| 282 |
+
# Pass through space_sdk if provided (required for spaces)
|
| 283 |
+
if "space_sdk" in args:
|
| 284 |
+
create_args["space_sdk"] = args["space_sdk"]
|
| 285 |
+
await self._create_repo(create_args)
|
| 286 |
elif not repo_exists:
|
| 287 |
return {
|
| 288 |
"formatted": f"Repository {repo_id} does not exist. Set create_if_missing: true to create it.",
|
|
|
|
| 347 |
|
| 348 |
repo_type = args.get("repo_type", "dataset")
|
| 349 |
private = True # Always create private repos
|
| 350 |
+
space_sdk = args.get("space_sdk") # Required if repo_type is "space"
|
| 351 |
|
| 352 |
try:
|
| 353 |
# Check if repo already exists
|
|
|
|
| 363 |
"resultsShared": 1,
|
| 364 |
}
|
| 365 |
|
| 366 |
+
# Validate space_sdk for spaces
|
| 367 |
+
if repo_type == "space" and not space_sdk:
|
| 368 |
+
return {
|
| 369 |
+
"formatted": "space_sdk is required when creating a space. Valid values: gradio, streamlit, static, docker",
|
| 370 |
+
"totalResults": 0,
|
| 371 |
+
"resultsShared": 0,
|
| 372 |
+
"isError": True,
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
# Create repository
|
| 376 |
+
create_kwargs = {
|
| 377 |
+
"repo_id": repo_id,
|
| 378 |
+
"repo_type": repo_type,
|
| 379 |
+
"private": private,
|
| 380 |
+
"exist_ok": True,
|
| 381 |
+
}
|
| 382 |
+
# Add space_sdk only for spaces
|
| 383 |
+
if repo_type == "space" and space_sdk:
|
| 384 |
+
create_kwargs["space_sdk"] = space_sdk
|
| 385 |
+
|
| 386 |
+
repo_url = await _async_call(self.api.create_repo, **create_kwargs)
|
| 387 |
|
| 388 |
response = f"""✓ Repository created successfully!
|
| 389 |
|
|
|
|
| 615 |
"description": (
|
| 616 |
"Operation-specific arguments as a JSON object. "
|
| 617 |
"Write ops: file_content (string/bytes), path_in_repo (string), repo_id (string), "
|
| 618 |
+
"repo_type (dataset/model/space), create_if_missing (boolean), commit_message (string), "
|
| 619 |
+
"space_sdk (gradio/streamlit/static/docker - required when repo_type=space). "
|
| 620 |
"Read ops: repo_id (string), path_in_repo (for read_file), repo_type (optional)."
|
| 621 |
),
|
| 622 |
"additionalProperties": True,
|