Skip to content

Commit

Permalink
fix(agents-api): added anthropic call in chat endpoint + typespec cha…
Browse files Browse the repository at this point in the history
…nged to include imageurl in ChatInput
  • Loading branch information
Vedantsahai18 committed Nov 14, 2024
1 parent 28a4702 commit 68c2320
Show file tree
Hide file tree
Showing 9 changed files with 834 additions and 48 deletions.
69 changes: 66 additions & 3 deletions agents-api/agents_api/autogen/Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,58 @@ class Content(BaseModel):
"""


class ContentItem(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["image"] = "image"
source: Source


class ContentModel(BaseModel):
"""
Anthropic image content part
"""

model_config = ConfigDict(
populate_by_name=True,
)
tool_use_id: str
type: Literal["tool_result"] = "tool_result"
content: list[ContentItem]


class ContentModel1(Content):
pass


class ContentModel2(ContentModel):
"""
Anthropic image content part
"""


class ContentModel3(Content):
pass


class ContentModel4(ContentModel):
"""
Anthropic image content part
"""


class ContentModel5(Content):
pass


class ContentModel6(ContentModel):
"""
Anthropic image content part
"""


class ContentModel7(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
Expand Down Expand Up @@ -193,7 +244,8 @@ class Delta(BaseModel):
"""
tool_call_id: str | None = None
content: Annotated[
str | list[str] | list[Content | ContentModel] | None, Field(...)
str | list[str] | list[ContentModel1 | ContentModel7 | ContentModel2] | None,
Field(...),
] = None
"""
The content parts of the message
Expand Down Expand Up @@ -258,7 +310,8 @@ class Message(BaseModel):
"""
tool_call_id: str | None = None
content: Annotated[
str | list[str] | list[Content | ContentModel] | None, Field(...)
str | list[str] | list[Content | ContentModel7 | ContentModel] | None,
Field(...),
] = None
"""
The content parts of the message
Expand Down Expand Up @@ -305,7 +358,8 @@ class MessageModel(BaseModel):
"""
tool_call_id: str | None = None
content: Annotated[
str | list[str] | list[Content | ContentModel] | None, Field(...)
str | list[str] | list[ContentModel3 | ContentModel7 | ContentModel4] | None,
Field(...),
] = None
"""
The content parts of the message
Expand Down Expand Up @@ -405,6 +459,15 @@ class SingleChatOutput(BaseChatOutput):
message: MessageModel


class Source(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["base64"] = "base64"
media_type: str
data: str


class TokenLogProb(BaseTokenLogProb):
model_config = ConfigDict(
populate_by_name=True,
Expand Down
44 changes: 42 additions & 2 deletions agents-api/agents_api/autogen/Entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseEntry(BaseModel):
"""
name: str | None = None
content: (
list[Content | ContentModel]
list[Content | ContentModel3 | ContentModel]
| Tool
| ChosenFunctionCall
| ChosenComputer20241022
Expand All @@ -37,7 +37,7 @@ class BaseEntry(BaseModel):
| str
| ToolResponse
| list[
list[Content | ContentModel]
list[ContentModel1 | ContentModel3 | ContentModel2]
| Tool
| ChosenFunctionCall
| ChosenComputer20241022
Expand Down Expand Up @@ -95,7 +95,38 @@ class Content(BaseModel):
"""


class ContentItem(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["image"] = "image"
source: Source


class ContentModel(BaseModel):
"""
Anthropic image content part
"""

model_config = ConfigDict(
populate_by_name=True,
)
tool_use_id: str
type: Literal["tool_result"] = "tool_result"
content: list[ContentItem]


class ContentModel1(Content):
pass


class ContentModel2(ContentModel):
"""
Anthropic image content part
"""


class ContentModel3(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
Expand Down Expand Up @@ -168,3 +199,12 @@ class Relation(BaseModel):
head: UUID
relation: str
tail: UUID


class Source(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["base64"] = "base64"
media_type: str
data: str
46 changes: 43 additions & 3 deletions agents-api/agents_api/autogen/Tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class Content(BaseModel):
"""


class ContentItem(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["image"] = "image"
source: Source


class ContentModel(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
Expand All @@ -99,14 +107,33 @@ class ContentModel(BaseModel):
"""


class ContentModel1(Content):
class ContentModel1(BaseModel):
"""
Anthropic image content part
"""

model_config = ConfigDict(
populate_by_name=True,
)
tool_use_id: str
type: Literal["tool_result"] = "tool_result"
content: list[ContentItem]


class ContentModel2(Content):
pass


class ContentModel2(ContentModel):
class ContentModel3(ContentModel):
pass


class ContentModel4(ContentModel1):
"""
Anthropic image content part
"""


class CreateTaskRequest(BaseModel):
"""
Payload for creating a task
Expand Down Expand Up @@ -655,7 +682,8 @@ class PromptItem(BaseModel):
"""
tool_call_id: str | None = None
content: Annotated[
list[str] | list[Content | ContentModel] | str | None, Field(...)
list[str] | list[Content | ContentModel | ContentModel1] | str | None,
Field(...),
]
"""
The content parts of the message
Expand Down Expand Up @@ -861,6 +889,18 @@ class SleepStep(BaseModel):
"""


class Source(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["base64"] = "base64"
media_type: str
data: str
"""
A valid jinja template.
"""


class SwitchStep(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
Expand Down
Loading

0 comments on commit 68c2320

Please sign in to comment.