Spaces:
Runtime error
Runtime error
Update tools/orchestrator.py
Browse files- tools/orchestrator.py +28 -15
tools/orchestrator.py
CHANGED
@@ -3,6 +3,7 @@ import json
|
|
3 |
import re
|
4 |
import logging
|
5 |
import time
|
|
|
6 |
|
7 |
from model_logic import call_model_stream, MODELS_BY_PROVIDER, get_default_model_display_name_for_provider
|
8 |
from memory_logic import retrieve_memories_semantic, retrieve_rules_semantic
|
@@ -64,22 +65,34 @@ def orchestrate_and_respond(user_input: str, provider_name: str, model_display_n
|
|
64 |
context_str = None
|
65 |
|
66 |
if action_type == "create_huggingface_space":
|
67 |
-
params = ["
|
68 |
if all(p in action_input for p in params):
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
else:
|
84 |
context_str = "Tool Failed: Missing parameters for create_huggingface_space. Required: " + ", ".join(params)
|
85 |
elif action_type == "list_huggingface_space_files":
|
|
|
3 |
import re
|
4 |
import logging
|
5 |
import time
|
6 |
+
from huggingface_hub import whoami
|
7 |
|
8 |
from model_logic import call_model_stream, MODELS_BY_PROVIDER, get_default_model_display_name_for_provider
|
9 |
from memory_logic import retrieve_memories_semantic, retrieve_rules_semantic
|
|
|
65 |
context_str = None
|
66 |
|
67 |
if action_type == "create_huggingface_space":
|
68 |
+
params = ["space_name", "sdk", "description"]
|
69 |
if all(p in action_input for p in params):
|
70 |
+
try:
|
71 |
+
hf_token = os.getenv("HF_TOKEN")
|
72 |
+
if not hf_token: raise ValueError("Hugging Face token (HF_TOKEN) not found.")
|
73 |
+
|
74 |
+
yield "status", "[Tool: Verifying user identity...]"
|
75 |
+
user_info = whoami(token=hf_token)
|
76 |
+
owner = user_info.get("name")
|
77 |
+
if not owner: raise ValueError("Could not determine owner from HF token.")
|
78 |
+
action_input["owner"] = owner
|
79 |
+
|
80 |
+
yield "status", "[Tool: Generating space content...]"
|
81 |
+
space_gen_messages = [
|
82 |
+
{"role": "system", "content": prompts.SPACE_GENERATION_SYSTEM_PROMPT},
|
83 |
+
{"role": "user", "content": prompts.get_space_generation_user_prompt(**action_input)}
|
84 |
+
]
|
85 |
+
markdown_content = "".join(list(call_model_stream(provider_name, model_display_name, space_gen_messages, ui_api_key_override, 0.1, 4096)))
|
86 |
+
yield "status", "[Tool: Creating Space...]"
|
87 |
+
result = create_huggingface_space(
|
88 |
+
owner=owner,
|
89 |
+
space_name=action_input["space_name"],
|
90 |
+
sdk=action_input["sdk"],
|
91 |
+
markdown_content=markdown_content.strip()
|
92 |
+
)
|
93 |
+
context_str = f"Tool Result (Create Space): {result.get('result') or result.get('error', 'Unknown outcome')}"
|
94 |
+
except Exception as e:
|
95 |
+
context_str = f"Tool Failed: An error occurred during space creation process - {e}"
|
96 |
else:
|
97 |
context_str = "Tool Failed: Missing parameters for create_huggingface_space. Required: " + ", ".join(params)
|
98 |
elif action_type == "list_huggingface_space_files":
|