From 0e3115330d6725cf047c2e039fe62e4230714a0b Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 13 Jan 2025 18:11:47 +0300 Subject: [PATCH] Add additional_instructions on openai assistan runs create. (#29164) - **Description**: In the functions `_create_run` and `_acreate_run`, the parameters passed to the creation of `openai.resources.beta.threads.runs` were limited. Source: ``` def _create_run(self, input: dict) -> Any: params = { k: v for k, v in input.items() if k in ("instructions", "model", "tools", "run_metadata") } return self.client.beta.threads.runs.create( input["thread_id"], assistant_id=self.assistant_id, **params, ) ``` - OpenAI Documentation ([createRun](https://platform.openai.com/docs/api-reference/runs/createRun)) - Full list of parameters `openai.resources.beta.threads.runs` ([source code](https://github.com/openai/openai-python/blob/main/src/openai/resources/beta/threads/runs/runs.py#L91)) - **Issue:** Fix #17574 - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ Co-authored-by: ccurme --- .../langchain/agents/openai_assistant/base.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/langchain/langchain/agents/openai_assistant/base.py b/libs/langchain/langchain/agents/openai_assistant/base.py index dc85fb03037..63457b63de2 100644 --- a/libs/langchain/langchain/agents/openai_assistant/base.py +++ b/libs/langchain/langchain/agents/openai_assistant/base.py @@ -408,7 +408,8 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]): message_metadata: Metadata to associate with a new message. thread_metadata: Metadata to associate with new thread. Only relevant when a new thread is created. - instructions: Additional run instructions. + instructions: Overrides the instructions of the assistant. + additional_instructions: Appends additional instructions. model: Override Assistant model for this run. tools: Override Assistant tools for this run. run_metadata: Metadata to associate with new run. @@ -507,7 +508,14 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]): params = { k: v for k, v in input.items() - if k in ("instructions", "model", "tools", "run_metadata") + if k + in ( + "instructions", + "model", + "tools", + "additional_instructions", + "run_metadata", + ) } return self.client.beta.threads.runs.create( input["thread_id"], @@ -637,7 +645,14 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]): params = { k: v for k, v in input.items() - if k in ("instructions", "model", "tools", "run_metadata") + if k + in ( + "instructions", + "model", + "tools", + "additional_instructions", + "run_metadata", + ) } return await self.async_client.beta.threads.runs.create( input["thread_id"],