Skip to content

Commit

Permalink
feat: Regenerate agents-api types
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
creatorrr committed Feb 27, 2024
1 parent 10c0d98 commit 3c15fed
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 403 deletions.
44 changes: 37 additions & 7 deletions agents-api/agents_api/autogen/openapi_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-02-13T06:39:44+00:00
# timestamp: 2024-02-27T14:16:52+00:00

from __future__ import annotations

Expand All @@ -9,7 +9,7 @@
from typing import Any, Dict, List, Optional, Union
from uuid import UUID

from pydantic import BaseModel, Extra, Field, PositiveFloat, confloat, conint, RootModel
from pydantic import BaseModel, Extra, Field, confloat, conint, RootModel


class User(BaseModel):
Expand Down Expand Up @@ -234,10 +234,10 @@ class Belief(BaseModel):
rationale: Optional[str] = Field(
None, description="Rationale: Why did the model decide to form this memory"
)
weight: confloat(lt=100.0, gt=0.0) = Field(
weight: confloat(ge=0.0, le=100.0) = Field(
..., description="Weight (importance) of the memory on a scale of 0-100"
)
sentiment: confloat(lt=1.0, gt=-1.0) = Field(
sentiment: confloat(ge=-1.0, le=1.0) = Field(
..., description="Sentiment (valence) of the memory on a scale of -1 to 1"
)
created_at: datetime = Field(..., description="Belief created at (RFC-3339 format)")
Expand All @@ -254,7 +254,7 @@ class Episode(BaseModel):
None, description="(Optional) ID of the subject user"
)
content: str = Field(..., description="Content of the memory")
weight: confloat(lt=100.0, gt=0.0) = Field(
weight: confloat(ge=0.0, le=100.0) = Field(
..., description="Weight (importance) of the memory on a scale of 0-100"
)
created_at: datetime = Field(
Expand All @@ -266,7 +266,7 @@ class Episode(BaseModel):
happened_at: datetime = Field(
..., description="Episode happened at (RFC-3339 format)"
)
duration: Optional[PositiveFloat] = Field(
duration: Optional[confloat(ge=0.0)] = Field(
0, description="Duration of the episode (in seconds)"
)
id: UUID = Field(..., description="Episode id (UUID)")
Expand Down Expand Up @@ -352,7 +352,7 @@ class ChatSettings(BaseModel):


class AgentDefaultSettings(BaseModel):
frequency_penalty: Optional[confloat(lt=2.0, gt=-2.0)] = Field(
frequency_penalty: Optional[confloat(ge=-2.0, lt=2.0)] = Field(
0,
description="(OpenAI-like) Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
)
Expand Down Expand Up @@ -386,6 +386,7 @@ class Doc(BaseModel):
)
content: str = Field(..., description="Information content")
id: UUID = Field(..., description="ID of doc")
created_at: datetime = Field(..., description="Doc created at")


class CreateDoc(BaseModel):
Expand Down Expand Up @@ -444,6 +445,35 @@ class ResourceDeletedResponse(BaseModel):
deleted_at: datetime


class State(str, Enum):
pending = "pending"
in_progress = "in_progress"
retrying = "retrying"
succeeded = "succeeded"
aborted = "aborted"
failed = "failed"


class JobStatus(BaseModel):
name: str = Field(..., description="Name of the job")
reason: Optional[str] = Field(None, description="Reason for current state")
created_at: datetime = Field(..., description="Job created at (RFC-3339 format)")
updated_at: Optional[datetime] = Field(
None, description="Job updated at (RFC-3339 format)"
)
id: UUID = Field(..., description="Job id (UUID)")
has_progress: Optional[bool] = Field(
False, description="Whether this Job supports progress updates"
)
progress: Optional[conint(ge=0, le=100)] = Field(
0, description="Progress percentage"
)
state: State = Field(
...,
description="Current state (one of: pending, in_progress, retrying, succeeded, aborted, failed)",
)


class Agent(BaseModel):
name: str = Field(..., description="Name of the agent")
about: str = Field(..., description="About the agent")
Expand Down
30 changes: 18 additions & 12 deletions agents-api/demo/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
web_search = {
"type": "search",
"engine": "brave",
"description": "Uses Brave search engine to find relevant information on the web."
"description": "Uses Brave search engine to find relevant information on the web.",
}
call_webhook = {
"type": "http",
"http": {
"endpoint": "http://localhost:9000",
"method": "POST",
"description": "Webhook to deliver research results",
"json": {
"summary": {"type": "string", "description": "Summary of the research"},
"details": {"type": "string", "description": "Detailed search results for further analysis"},
}
}
"endpoint": "http://localhost:9000",
"method": "POST",
"description": "Webhook to deliver research results",
"json": {
"summary": {"type": "string", "description": "Summary of the research"},
"details": {
"type": "string",
"description": "Detailed search results for further analysis",
},
},
},
}

agent = client.agents.create(
Expand Down Expand Up @@ -55,13 +58,16 @@

# Ask the agent to run this task

run = client.runs.create(agent_id=agent.id, task_id=task.id, inputs={"topic": "Sam Altman"})
run = client.runs.create(
agent_id=agent.id, task_id=task.id, inputs={"topic": "Sam Altman"}
)


async def main():
async for step in run.execution_steps():
print(step.messages)



# >>> [{"role": "thought", "content": "Starting the research on Sam Altman. I'll begin by gathering information from various sources on the web."}, {"role": "assistant", "tool_calls": [{"type": "search", "inputs": {"query": "Sam Altman significant contributions and background"}}]}]
# # Wait for 3-4 seconds

Expand All @@ -78,6 +84,6 @@ async def main():
# # Wait for 1 second

# >>> [{"role": "system", "name": "information", "content": "Delivered data to webhook"}]

if __name__ == "__main__":
asyncio.run(main())
73 changes: 60 additions & 13 deletions agents-api/demo/julep.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Step:
def __init__(self, d):
self._d = d

@property
def messages(self):
return self._d.get("content", "")
Expand All @@ -23,32 +23,38 @@ def __init__(self, base_url, api_key):
self.tasks = TaskManager()
self.runs = RunManager()


class AgentManager:
def create(self, name, description, tools):
return Agent(name, description, tools)


class Agent:
def __init__(self, name, description, tools):
self.id = str(uuid.uuid4())
self.name = name
self.description = description
self.tools = tools


class TaskManager:
def create(self, agent_id, instructions, inputs):
return Task(agent_id, instructions, inputs)


class Task:
def __init__(self, agent_id, instructions, inputs):
self.id = str(uuid.uuid4())
self.agent_id = agent_id
self.instructions = instructions
self.inputs = inputs


class RunManager:
def create(self, agent_id, task_id, inputs):
return Run(agent_id, task_id, inputs)


class Run:
def __init__(self, agent_id, task_id, inputs):
self.agent_id = agent_id
Expand All @@ -57,24 +63,65 @@ def __init__(self, agent_id, task_id, inputs):

async def execution_steps(self):
steps = [
{"role": "thought", "content": "Starting the research on Sam Altman. I'll begin by gathering information from various sources on the web."},
{"role": "assistant", "tool_calls": [{"type": "search", "inputs": {"query": "Sam Altman significant contributions and background"}}]},
{"role": "system", "name": "information", "content": "Found numerous articles, interviews, and resources on Sam Altman, including his role at OpenAI, investments, and insights into technology and entrepreneurship."},
{"role": "thought", "content": "Need to summarize this information to capture the essence of Sam Altman's impact."},
{"role": "assistant", "content": "Summary:\nSam Altman, known for his leadership at OpenAI, has been a pivotal figure in the tech industry, driving innovation and supporting startups. His insights on entrepreneurship and the future of AI have influenced a wide audience."},
{"role": "thought", "content": "Now, I'll send the compiled summary and details to the webhook."},
{"role": "assistant", "tool_calls": [{"type": "http", "endpoint": f"http://localhost:{PORT}", "method": "POST", "data": {"summary": "Sam Altman, known for his leadership at OpenAI, has been a pivotal figure in the tech industry, driving innovation and supporting startups. His insights on entrepreneurship and the future of AI have influenced a wide audience.", "details": "Found numerous articles, interviews, and resources on Sam Altman, including his role at OpenAI, investments, and insights into technology and entrepreneurship."}}]},

{
"role": "thought",
"content": "Starting the research on Sam Altman. I'll begin by gathering information from various sources on the web.",
},
{
"role": "assistant",
"tool_calls": [
{
"type": "search",
"inputs": {
"query": "Sam Altman significant contributions and background"
},
}
],
},
{
"role": "system",
"name": "information",
"content": "Found numerous articles, interviews, and resources on Sam Altman, including his role at OpenAI, investments, and insights into technology and entrepreneurship.",
},
{
"role": "thought",
"content": "Need to summarize this information to capture the essence of Sam Altman's impact.",
},
{
"role": "assistant",
"content": "Summary:\nSam Altman, known for his leadership at OpenAI, has been a pivotal figure in the tech industry, driving innovation and supporting startups. His insights on entrepreneurship and the future of AI have influenced a wide audience.",
},
{
"role": "thought",
"content": "Now, I'll send the compiled summary and details to the webhook.",
},
{
"role": "assistant",
"tool_calls": [
{
"type": "http",
"endpoint": f"http://localhost:{PORT}",
"method": "POST",
"data": {
"summary": "Sam Altman, known for his leadership at OpenAI, has been a pivotal figure in the tech industry, driving innovation and supporting startups. His insights on entrepreneurship and the future of AI have influenced a wide audience.",
"details": "Found numerous articles, interviews, and resources on Sam Altman, including his role at OpenAI, investments, and insights into technology and entrepreneurship.",
},
}
],
},
# TODO: @dmitry
# Add a HTTP POST call after this step to 0.0.0.0:8080 with the results

{"role": "system", "name": "information", "content": "Delivered data to webhook"}
{
"role": "system",
"name": "information",
"content": "Delivered data to webhook",
},
]

for step in steps:
if 'tool_calls' in step:
if "tool_calls" in step:
# Simulate tool call delay
await asyncio.sleep(3 if step['role'] == 'assistant' else 2)
await asyncio.sleep(3 if step["role"] == "assistant" else 2)
for c in step["tool_calls"]:
if c.get("endpoint"):
async with httpx.AsyncClient() as client:
Expand Down
Loading

0 comments on commit 3c15fed

Please sign in to comment.