Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,7 +69,7 @@ class HuggingFaceSpaceSearcherTool(Tool):
|
|
| 69 |
"top_k": {
|
| 70 |
"type": "integer",
|
| 71 |
"description": "The number of top results to return (default is 3).",
|
| 72 |
-
"
|
| 73 |
}
|
| 74 |
}
|
| 75 |
output_type = "string" # Optional: define output type
|
|
@@ -82,8 +82,8 @@ class HuggingFaceSpaceSearcherTool(Tool):
|
|
| 82 |
Provides repo_id, description, likes, and last modified date for each space found.
|
| 83 |
"""
|
| 84 |
try:
|
| 85 |
-
# top_k will be provided by the Tool base class mechanism
|
| 86 |
-
#
|
| 87 |
actual_top_k = top_k if top_k is not None else 3 # Ensure top_k has a value
|
| 88 |
print(f"Searching spaces with query: {query}, top_k: {actual_top_k}")
|
| 89 |
spaces_found = list(list_spaces(search=query, full=True, limit=actual_top_k, sort="likes", direction=-1))
|
|
@@ -164,7 +164,7 @@ AGENT_INSTRUCTIONS = """You are a highly capable AI assistant. Your primary goal
|
|
| 164 |
Follow these steps:
|
| 165 |
1. **Understand the Request:** Carefully analyze the user's prompt (which will follow these instructions). Identify the core task and any specific requirements or inputs.
|
| 166 |
2. **Check Predefined Tools:** Review your list of available tools. If a predefined tool can directly address the request, use it.
|
| 167 |
-
* For the 'huggingface_space_searcher' tool, you MUST provide its arguments as a dictionary. For example: `huggingface_space_searcher(arguments={"query": "your search term", "top_k": 3})`. The `query` is mandatory. `top_k` is optional
|
| 168 |
3. **Search for Spaces (If Needed):** If no predefined tool is suitable, use the `huggingface_space_searcher` tool as described above.
|
| 169 |
4. **Select and Instantiate a Space Tool:** From the search results, choose the most promising Space. Attempt to create a tool from it using `Tool.from_space(repo_id='SELECTED_SPACE_ID', name='a_unique_tool_name')`. You might need to give it a unique name. If `Tool.from_space` fails, the Space might not be compatible, or you could try another one from the search results.
|
| 170 |
5. **Execute the Tool:** Call the tool (either predefined or dynamically created) with the necessary arguments.
|
|
@@ -284,4 +284,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 284 |
)
|
| 285 |
|
| 286 |
if __name__ == "__main__":
|
| 287 |
-
app.launch(debug=True)
|
|
|
|
| 69 |
"top_k": {
|
| 70 |
"type": "integer",
|
| 71 |
"description": "The number of top results to return (default is 3).",
|
| 72 |
+
"nullable": True # Changed from "optional" to "nullable"
|
| 73 |
}
|
| 74 |
}
|
| 75 |
output_type = "string" # Optional: define output type
|
|
|
|
| 82 |
Provides repo_id, description, likes, and last modified date for each space found.
|
| 83 |
"""
|
| 84 |
try:
|
| 85 |
+
# top_k will be provided by the Tool base class mechanism.
|
| 86 |
+
# If "nullable": True and it's not provided by the agent, it might be None.
|
| 87 |
actual_top_k = top_k if top_k is not None else 3 # Ensure top_k has a value
|
| 88 |
print(f"Searching spaces with query: {query}, top_k: {actual_top_k}")
|
| 89 |
spaces_found = list(list_spaces(search=query, full=True, limit=actual_top_k, sort="likes", direction=-1))
|
|
|
|
| 164 |
Follow these steps:
|
| 165 |
1. **Understand the Request:** Carefully analyze the user's prompt (which will follow these instructions). Identify the core task and any specific requirements or inputs.
|
| 166 |
2. **Check Predefined Tools:** Review your list of available tools. If a predefined tool can directly address the request, use it.
|
| 167 |
+
* For the 'huggingface_space_searcher' tool, you MUST provide its arguments as a dictionary. For example: `huggingface_space_searcher(arguments={"query": "your search term", "top_k": 3})`. The `query` is mandatory. `top_k` is optional (defaults to 3 if not provided in the dictionary or if the key is absent).
|
| 168 |
3. **Search for Spaces (If Needed):** If no predefined tool is suitable, use the `huggingface_space_searcher` tool as described above.
|
| 169 |
4. **Select and Instantiate a Space Tool:** From the search results, choose the most promising Space. Attempt to create a tool from it using `Tool.from_space(repo_id='SELECTED_SPACE_ID', name='a_unique_tool_name')`. You might need to give it a unique name. If `Tool.from_space` fails, the Space might not be compatible, or you could try another one from the search results.
|
| 170 |
5. **Execute the Tool:** Call the tool (either predefined or dynamically created) with the necessary arguments.
|
|
|
|
| 284 |
)
|
| 285 |
|
| 286 |
if __name__ == "__main__":
|
| 287 |
+
app.launch(debug=True)
|