Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decorator for the new sdk #129

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions naptha_sdk/client/naptha.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ async def create_agent(self, name):
"module_url": "None",
"module_type": "agent",
"module_version": "v0.1",
"execution_type": "agent"
"execution_type": "package",
"module_entrypoint": "run.py",
"parameters": "",
}
logger.info(f"Registering Agent {agent_config}")
agent = await self.hub.create_or_update_agent(agent_config)
agent = await self.hub.create_or_update_module("agent", agent_config)
if agent:
logger.info(f"Agent {name} created successfully")
else:
Expand All @@ -74,10 +76,12 @@ async def publish_modules(self, decorator = False, register = None, subdeploymen

if not decorator:
module_path = Path.cwd()
deployment_path = module_path / module_path.name / 'configs/deployment.json'
with open(deployment_path, 'r') as f:
deployment_path = module_path / module_path.name / "configs" / "deployment.json"
with open(deployment_path, "r", encoding="utf-8") as f:
deployment = json.load(f)
module = deployment[0]['module']
module = deployment[0]["module"]
if "module_type" not in module:
module["module_type"] = "agent"
modules = [module]
if subdeployments:
deployment = await setup_module_deployment(module['module_type'], deployment_path)
Expand All @@ -88,19 +92,22 @@ async def publish_modules(self, decorator = False, register = None, subdeploymen
modules.append(submodule.module)
else:
path = Path.cwd() / AGENT_DIR
modules = [item.name for item in path.iterdir() if item.is_dir()]
for module in modules:
git_add_commit(module)
module = {
"name": module,
"description": module,
"parameters": "None",
dir_items = [item.name for item in path.iterdir() if item.is_dir()]
modules = []
for mod_item in dir_items:
git_add_commit(mod_item)
mod_data = {
"name": mod_item,
"description": mod_item,
"parameters": "",
"module_type": "agent",
"module_url": "None",
"module_version": "v0.1",
"module_entrypoint": "run.py",
"execution_type": "package"
}
modules.append(mod_data)

for module in modules:
if "module_url" in module and module['module_url'] != "None":
module_url = module['module_url']
Expand All @@ -112,26 +119,27 @@ async def publish_modules(self, decorator = False, register = None, subdeploymen
logger.info(f"Using provided URL for {module['module_type']} {module['name']}: {module_url}")
# Otherwise, publish to IPFS
else:
_, response = await publish_ipfs_package(module['name'], decorator)
module_url = f'ipfs://{response["ipfs_hash"]}'
logger.info(f"Storing {module['module_type']} {module['name']} on IPFS")
logger.info(f"IPFS Hash: {response['ipfs_hash']}. You can download it from http://provider.akash.pro:30584/ipfs/{response['ipfs_hash']}")
_, response = await publish_ipfs_package(module["name"], decorator)
module_url = f"ipfs://{response['ipfs_hash']}"
logger.info(f"Storing {module['name']} on IPFS")
logger.info(f"Module URL: {module_url}")
logger.info(f"IPFS Hash: {response['ipfs_hash']}. You can download it from http://ipfs-gateway.naptha.work/ipfs/{response['ipfs_hash']}")

if register:
# Register module with hub
async with self.hub:
_, _, user_id = await self.hub.signin(self.hub_username, os.getenv("HUB_PASSWORD"))
module_config = {
"id": f"{module['module_type']}:{module['name']}",
"name": module['name'],
"description": module['description'],
"parameters": module['parameters'],
"name": module["name"],
"description": module.get("description", "No description provided"),
"parameters": module.get("parameters", ""),
"author": self.hub.user_id,
"module_url": module_url,
"module_type": module['module_type'],
"module_version": module['module_version'],
"module_entrypoint": module['module_entrypoint'],
"execution_type": module['execution_type'],
"module_type": module["module_type"],
"module_version": module.get("module_version", "v0.1"),
"module_entrypoint": module.get("module_entrypoint", "run.py"),
"execution_type": module.get("execution_type", "package"),
}
logger.info(f"Registering {module['module_type']} {module['name']} on Naptha Hub {module_config}")
module = await self.hub.create_or_update_module(module['module_type'], module_config)
Expand Down
14 changes: 10 additions & 4 deletions naptha_sdk/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ async def load_node_metadata(deployment, node_url, is_subdeployment):
if not is_subdeployment or deployment["node"]["ip"] == "localhost":
deployment["node"] = url_to_node(node_url)
else:
deployment["node"] = await list_nodes(deployment["node"]["ip"])
deployment["node"] = NodeConfig(**deployment["node"])
node_list = await list_nodes(deployment["node"]["ip"])
if not node_list:
raise Exception("No nodes found.")
deployment["node"] = NodeConfig(**node_list[0])
print(f"Node metadata loaded {deployment['node']}")
return deployment

Expand Down Expand Up @@ -51,10 +53,14 @@ async def load_module_config_data(module_type, deployment, load_persona_data=Fal

if "llm_config" in deployment["config"] and deployment["config"]["llm_config"] is not None:
config_name = deployment["config"]["llm_config"]["config_name"]
config_path = f"{Path.cwd().name}/configs/llm_configs.json"
# CORRECTED PATH: Changed from deployment.json to config.json
config_path = f"{Path.cwd().name}/configs/config.json"
llm_configs = load_llm_configs(config_path)
llm_config = next(config for config in llm_configs if config.config_name == config_name)
llm_config = next((config for config in llm_configs if config.config_name == config_name), None)
if llm_config is None:
raise ValueError(f"No LLM config found with name {config_name}")
deployment["config"]["llm_config"] = llm_config

if load_persona_data:
persona_data = await load_persona(deployment["config"]["persona_module"])
deployment["config"]["system_prompt"]["persona"] = persona_data
Expand Down
Loading