Skip to content

Commit

Permalink
feat: simplify structure
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Sep 27, 2024
1 parent 6d1ed7d commit 2c086cf
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, List, Optional
from payments_py.data_models import AgentExecutionStatus
from payments_py.protocol.nvm_backend import BackendApiOptions, NVMBackendApi
from payments_py.nvm_backend import BackendApiOptions, NVMBackendApi
import asyncio


Expand Down
120 changes: 62 additions & 58 deletions payments_py/data_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydantic import BaseModel, ConfigDict, Field
from enum import Enum
from typing import Dict, List, Optional, Union
from typing import Dict, List, Optional, Union, Any
from datetime import datetime

class SubscriptionType(str, Enum):
CREDITS = 'credits'
Expand Down Expand Up @@ -95,8 +96,6 @@ class ServiceTokenResultDto(BaseModel):
}
})



class AgentExecutionStatus(Enum):
Pending = "Pending"
In_Progress = "In_Progress"
Expand All @@ -105,58 +104,63 @@ class AgentExecutionStatus(Enum):
Failed = "Failed"
# Add other status options here

# class Artifact(BaseModel):
# artifactId: str
# url: str

# class BaseStepDto(BaseModel):
# task_id: str = Field(..., description="Id of the task")

# input_query: Optional[str] = Field(None, example="What's the weather in NY now?", description="Input for the task")

# input_params: Optional[List[Dict[str, str]]] = Field(None, example=[{'assistantId': '1234'}], description="List of additional key-value parameters required for the step")

# input_artifacts: Optional[List[Artifact]] = Field(None, example=[{'artifactId': 'art-aabb', 'url': 'https://nevermined.io/file.txt'}], description="Artifacts for the step")

# name: Optional[str] = Field(None, example="summarizer", description="Name of the step")

# order: Optional[int] = Field(None, example=1, description="Order of the execution of the step")

# cost: Optional[int] = Field(None, example=5, description="Cost in credits of executing the step")

# predecessor: Optional[str] = Field(None, example=AgentStepEntity.generateId(), description="Previous step id. If not given, the system will associate to the latest step (by order).")

# is_last: Optional[bool] = Field(None, example=True, description="Is the last step of the task?")

# class NewStepDto(BaseStepDto):
# step_id: Optional[str] = Field(None, description="Id of the step. If not given or invalid, the system will auto-generate it", example=AgentStepEntity.generateId())

# step_status: Optional[AgentExecutionStatus] = Field(None, description="Status of the step", example=AgentExecutionStatus.Not_Ready)

# input_query: str = Field(..., example="What's the weather in NY now?", description="Input for the task")

# class UpdateStepDto(BaseStepDto):
# step_id: str = Field(..., description="Id of the step. If not given or invalid, the system will auto-generate it", example=AgentStepEntity.generateId())

# step_status: AgentExecutionStatus = Field(..., description="New status of the step", example=AgentExecutionStatus.Completed)

# output: Optional[str] = Field(None, example="success", description="Output of the step")

# output_additional: Optional[List[Dict[str, str]]] = Field(None, example=[{'message': 'success'}], description="List of additional key-value output values generated by the step")

# output_artifacts: Optional[List[Artifact]] = Field(None, example=[{'artifactId': 'art-aabb', 'url': 'https://nevermined.io/file.txt'}], description="Artifacts generated by the execution of the step")

# class CreateStepsDto(BaseModel):
# steps: Optional[List[NewStepDto]] = Field(None, example=[{
# 'task_id': 'task-1234',
# 'input_query': 'What is the weather in NY now?',
# 'name': 'summarizer',
# 'order': 2,
# 'is_last': True
# }], description="List of new Steps to create")

# class CreateTaskDto(BaseModel):
# query: str = Field(..., example="What's the weather in NY now?", description='Input for the task')
# name: Optional[str] = Field(None, example="summarizer", description='Name of the task')
# additional_params: Optional[List[Dict[str, str]]] = Field(None, example=[{"assistantId": "1234"}], description='List of additional key-value parameters required for the task')
# artifacts: Optional[List[Artifact]] = Field(None, example=[{"artifactId": "art-aabb", "url": "https://nevermined.io/file.txt"}], description='Artifacts for the task')
# Artifact data class
class Artifact:
"""
Represents an artifact with a unique identifier and a URL reference.
"""
artifact_id: str
url: str

# ExecutionInput data class
class ExecutionInput:
"""
Represents the input for a task, such as a query and additional parameters or artifacts.
"""
query: str
additional_params: Optional[List[Dict[str, str]]] = None
artifacts: Optional[List[Artifact]] = None

# ExecutionOutput data class
class ExecutionOutput:
"""
Represents the output of a task or step execution.
"""
output: Any
additional_output: Optional[List[Dict[str, Any]]] = None
artifacts: Optional[List[str]] = None

# ExecutionOptions data class
class ExecutionOptions:
"""
Represents options for executing a task or step, such as input, status, and output.
"""
input: ExecutionInput
status: AgentExecutionStatus
output: Optional[ExecutionOutput] = None
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
retries: Optional[int] = None

# Step data class
class Step(ExecutionOptions):
"""
Represents a step in the execution of a task.
"""
step_id: str
task_id: str
is_last: Optional[bool] = False
name: Optional[str] = None

# Task data class
class Task(ExecutionOptions):
"""
Represents a task that an agent should execute, composed of multiple steps.
"""
task_id: str
steps: List[Step]
name: Optional[str] = None

# Constants for step names
FIRST_STEP_NAME = 'init'
LAST_STEP_NAME = 'init'
File renamed without changes.
4 changes: 2 additions & 2 deletions payments_py/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from payments_py.data_models import BalanceResultDto, BurnResultDto, CreateAssetResultDto, DownloadFileResultDto, MintResultDto, OrderSubscriptionResultDto, ServiceTokenResultDto
from payments_py.environments import Environment
from payments_py.protocol.nvm_backend import BackendApiOptions, NVMBackendApi
from payments_py.protocol.query_api import AIQueryApi
from payments_py.nvm_backend import BackendApiOptions, NVMBackendApi
from payments_py.ai_query_api import AIQueryApi
from payments_py.utils import snake_to_camel


Expand Down
Binary file not shown.
Binary file not shown.
74 changes: 0 additions & 74 deletions payments_py/protocol/types.py

This file was deleted.

0 comments on commit 2c086cf

Please sign in to comment.