Skip to content

Commit

Permalink
Merge pull request #957 from andehr/assistant-response-format
Browse files Browse the repository at this point in the history
Allow passing of `response_format` to Assistant constructor
  • Loading branch information
zzstoatzz authored Jul 28, 2024
2 parents 1af8e9c + b2c2a2b commit 7af639f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/marvin/beta/assistants/assistants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union

from openai import AsyncAssistantEventHandler
from prompt_toolkit import PromptSession
Expand All @@ -13,7 +13,7 @@
import marvin.utilities.tools
from marvin.beta.assistants.handlers import PrintHandler
from marvin.tools.assistants import AssistantTool
from marvin.types import Tool
from marvin.types import AssistantResponseFormat, Tool
from marvin.utilities.asyncio import (
ExposeSyncMethodsMixin,
expose_sync_method,
Expand Down Expand Up @@ -64,6 +64,7 @@ class Assistant(BaseModel, ExposeSyncMethodsMixin):
tools: list[Union[AssistantTool, Callable]] = []
tool_resources: dict[str, Any] = {}
metadata: dict[str, str] = {}
response_format: Optional[Union[Literal["auto"], AssistantResponseFormat]] = "auto"
# context level tracks nested assistant contexts
_context_level: int = PrivateAttr(0)

Expand Down Expand Up @@ -173,6 +174,7 @@ async def create_async(self, _auto_delete: bool = False):
"metadata",
"tool_resources",
"metadata",
"response_format",
}
),
tools=[tool.model_dump() for tool in self.get_tools()],
Expand Down
12 changes: 12 additions & 0 deletions src/marvin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ class FunctionCall(MarvinType):
name: str


class AssistantResponseFormat(MarvinType):
type: Literal["json_object", "text"]


class JsonObjectAssistantResponseFormat(AssistantResponseFormat):
type: Literal["json_object"] = "json_object"


class TextAssistantResponseFormat(AssistantResponseFormat):
type: Literal["text"] = "text"


class ImageUrl(MarvinType):
url: str = Field(
description="URL of the image to be sent or a base64 encoded image."
Expand Down

0 comments on commit 7af639f

Please sign in to comment.