Skip to content

Commit

Permalink
feat(agents-api): Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr committed Apr 25, 2024
1 parent c9cc77c commit 08fca77
Show file tree
Hide file tree
Showing 29 changed files with 575 additions and 497 deletions.
2 changes: 1 addition & 1 deletion agents-api/.tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python 3.11.7
python 3.10.13
43 changes: 22 additions & 21 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-04-18T12:56:54+00:00
# timestamp: 2024-04-20T14:32:07+00:00

from __future__ import annotations

Expand Down Expand Up @@ -221,7 +221,7 @@ class Suggestion(BaseModel):

class Role(str, Enum):
"""
ChatML role (system|assistant|user|function_call)
ChatML role (system|assistant|user|function_call|function)
"""

user = "user"
Expand All @@ -234,7 +234,7 @@ class Role(str, Enum):
class ChatMLMessage(BaseModel):
role: Role
"""
ChatML role (system|assistant|user|function_call)
ChatML role (system|assistant|user|function_call|function)
"""
content: str
"""
Expand All @@ -256,20 +256,21 @@ class ChatMLMessage(BaseModel):

class Role1(str, Enum):
"""
ChatML role (system|assistant|user|function_call)
ChatML role (system|assistant|user|function_call|function|auto)
"""

user = "user"
assistant = "assistant"
system = "system"
function_call = "function_call"
function = "function"
auto = "auto"


class InputChatMLMessage(BaseModel):
role: Role1
"""
ChatML role (system|assistant|user|function_call)
ChatML role (system|assistant|user|function_call|function|auto)
"""
content: str
"""
Expand Down Expand Up @@ -783,10 +784,6 @@ class PatchAgentRequest(BaseModel):
"""
About the agent
"""
instructions: List[str] | None = None
"""
List of instructions for the agent
"""
name: str | None = None
"""
Name of the agent
Expand All @@ -803,6 +800,10 @@ class PatchAgentRequest(BaseModel):
"""
Optional metadata
"""
instructions: str | List[str] | None = None
"""
Instructions for the agent
"""


class PatchSessionRequest(BaseModel):
Expand Down Expand Up @@ -844,10 +845,6 @@ class Agent(BaseModel):
"""
About the agent
"""
instructions: List[str] | None = None
"""
List of instructions for the agent
"""
created_at: AwareDatetime | None = None
"""
Agent created at (RFC-3339 format)
Expand All @@ -872,6 +869,10 @@ class Agent(BaseModel):
"""
Optional metadata
"""
instructions: str | List[str] | None = None
"""
Instructions for the agent
"""


class CreateUserRequest(BaseModel):
Expand Down Expand Up @@ -910,10 +911,6 @@ class CreateAgentRequest(BaseModel):
"""
About the agent
"""
instructions: List[str] | None = None
"""
List of instructions for the agent
"""
tools: List[CreateToolRequest] | None = None
"""
A list of tools the model may call. Currently, only `function`s are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.
Expand All @@ -934,6 +931,10 @@ class CreateAgentRequest(BaseModel):
"""
(Optional) metadata
"""
instructions: str | List[str] | None = None
"""
Instructions for the agent
"""


class UpdateAgentRequest(BaseModel):
Expand All @@ -945,10 +946,6 @@ class UpdateAgentRequest(BaseModel):
"""
About the agent
"""
instructions: List[str] | None = None
"""
List of instructions for the agent
"""
name: str
"""
Name of the agent
Expand All @@ -965,6 +962,10 @@ class UpdateAgentRequest(BaseModel):
"""
Optional metadata
"""
instructions: str | List[str] | None = None
"""
Instructions for the agent
"""


class ChatInputData(BaseModel):
Expand Down
6 changes: 5 additions & 1 deletion agents-api/agents_api/routers/agents/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,16 @@ async def update_tool(
async def patch_tool(
agent_id: UUID4, tool_id: UUID4, request: PatchToolRequest
) -> ResourceUpdatedResponse:
parameters = (
request.function.parameters.model_dump() if request.function.parameters else {}
)

embeddings = await embed(
[
function_embed_instruction
+ (request.function.description or "")
+ "\nParameters: "
+ json.dumps(request.function.parameters.model_dump())
+ json.dumps(parameters)
],
join_inputs=True,
)
Expand Down
18 changes: 9 additions & 9 deletions agents-api/agents_api/routers/sessions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from json import JSONDecodeError
from typing import Callable
from uuid import uuid4
from openai.types.chat.chat_completion import ChatCompletion

from dataclasses import dataclass
from openai.types.chat.chat_completion import ChatCompletion
from pydantic import UUID4

from agents_api.clients.embed import embed
from agents_api.env import summarization_tokens_threshold
from agents_api.clients.temporal import run_summarization_task
Expand Down Expand Up @@ -114,7 +116,7 @@ def rm_user_assistant(m):

async def run(
self, new_input, settings: Settings
) -> tuple[ChatCompletion, Entry, Callable]:
) -> tuple[ChatCompletion, Entry, Callable | None]:
# TODO: implement locking at some point
# Get session data
session_data = get_session_data(self.developer_id, self.session_id)
Expand Down Expand Up @@ -229,13 +231,11 @@ async def forward(
# Else add to entries as is
entries.append(
Entry(
**{
"role": row["role"],
"name": row["name"],
"content": row["content"],
"session_id": self.session_id,
"created_at": row["created_at"],
}
role=row["role"],
name=row["name"],
content=row["content"],
session_id=self.session_id,
created_at=row["created_at"],
)
)

Expand Down
Loading

0 comments on commit 08fca77

Please sign in to comment.