Skip to content

Commit

Permalink
Merge branch 'main' into thread-images
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz authored Jun 26, 2024
2 parents a8eae20 + 1735b7d commit 2e5ecfc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 6 additions & 4 deletions cookbook/slackbot/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,19 @@ async def handle_message(payload: SlackPayload) -> Completed:
" Galaxy. Act subtly in accordance with your character, but remember"
" to be helpful and kind. You are an expert in Python, data"
" engineering, and software development. Your primary job is to use"
" chroma to search docs and github issues for users, in order to"
" tools to search docs and github issues for users, in order to"
" develop a coherent attempt to answer their questions."
" You must use your tools, as Prefect 2.x is new and you"
" have no prior experience with it. You should use tools many times before"
" You _must_ rely on your tools, as Prefect is developed quickly and you have no"
" prior experience with newest versions. You should use tools many times before"
" responding if you do not get a relevant result at first. You should"
" prioritize brevity in your responses, and format text prettily for Slack."
" prioritize brevity in your responses, and format text prettily for Slack (no markdown)."
" Bold things should be wrapped in (SINGLE!) asterisks and italics in (SINGLE!) underscores."
f"{ ('here are some notes on the user:' + user_notes) if user_notes else ''}"
" ALWAYS provide links to the source of your information - let's think step-by-step."
" If a tool returns an irrelevant/bad result, you should try another tool."
" KEEP IN MIND that agents are deprecated in favor of workers, so you should"
" never recommend `prefect agent` commands, suggest `prefect worker` instead."
" that goes for `build_from_flow` too, instead use `Flow.deploy()`"
),
) as ai:
logger.debug_kv(
Expand Down
17 changes: 16 additions & 1 deletion src/marvin/beta/assistants/runs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Optional, Union
from typing import Any, Callable, Literal, Optional, Union

from openai import AsyncAssistantEventHandler
from openai.types.beta.threads import Message
Expand Down Expand Up @@ -34,6 +34,8 @@ class Run(BaseModel, ExposeSyncMethodsMixin):
for the run.
additional_tools (list[AssistantTool], optional): Additional tools to append
to the assistant's tools.
tool_choice (Union[Literal["auto", "none", "required"], AssistantTool], optional):
The tool use behaviour for the run.
run (OpenAIRun): The OpenAI run object.
data (Any): Any additional data associated with the run.
"""
Expand Down Expand Up @@ -67,6 +69,12 @@ class Run(BaseModel, ExposeSyncMethodsMixin):
None,
description="Additional tools to append to the assistant's tools. ",
)
tool_choice: Optional[
Union[Literal["none", "auto", "required"], AssistantTool]
] = Field(
default=None,
description="The tool use behaviour for the run. Can be 'none', 'auto', 'required', or a specific tool.",
)
run: OpenAIRun = Field(None, repr=False)
data: Any = None

Expand Down Expand Up @@ -154,6 +162,13 @@ def _get_run_kwargs(self, thread: Thread = None, **run_kwargs) -> dict:
if model := self._get_model():
run_kwargs["model"] = model

if tool_choice := self.tool_choice:
run_kwargs["tool_choice"] = (
tool_choice.model_dump(mode="json")
if isinstance(tool_choice, Tool)
else tool_choice
)

return run_kwargs

async def get_tool_outputs(self, run: OpenAIRun) -> list[str]:
Expand Down

0 comments on commit 2e5ecfc

Please sign in to comment.