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 <chester.curme@gmail.com>
This commit is contained in:
Andrew 2025-01-13 18:11:47 +03:00 committed by GitHub
parent e4ceafa1c8
commit 0e3115330d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -408,7 +408,8 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
message_metadata: Metadata to associate with a new message. message_metadata: Metadata to associate with a new message.
thread_metadata: Metadata to associate with new thread. Only relevant thread_metadata: Metadata to associate with new thread. Only relevant
when a new thread is created. 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. model: Override Assistant model for this run.
tools: Override Assistant tools for this run. tools: Override Assistant tools for this run.
run_metadata: Metadata to associate with new run. run_metadata: Metadata to associate with new run.
@ -507,7 +508,14 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
params = { params = {
k: v k: v
for k, v in input.items() 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( return self.client.beta.threads.runs.create(
input["thread_id"], input["thread_id"],
@ -637,7 +645,14 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
params = { params = {
k: v k: v
for k, v in input.items() 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( return await self.async_client.beta.threads.runs.create(
input["thread_id"], input["thread_id"],