mirror of https://github.com/hwchase17/langchain
langchain[patch]: allow passing client with OpenAIAssistantRunnable (#16486)
- **Description:** This addresses the issue tagged below where if you try to pass your own client when creating an OpenAI assistant, a pydantic error is raised: Example code: ```python import openai from langchain.agents.openai_assistant import OpenAIAssistantRunnable client = openai.OpenAI() interpreter_assistant = OpenAIAssistantRunnable.create_assistant( name="langchain assistant", instructions="You are a personal math tutor. Write and run code to answer math questions.", tools=[{"type": "code_interpreter"}], model="gpt-4-1106-preview", client=client ) ``` Error: `pydantic.v1.errors.ConfigError: field "client" not yet prepared, so the type is still a ForwardRef. You might need to call OpenAIAssistantRunnable.update_forward_refs()` It additionally updates type hints and docstrings to indicate that an AzureOpenAI client is permissible as well. - **Issue:** https://github.com/langchain-ai/langchain/issues/15948 - **Dependencies:** N/Apull/16568/head
parent
d898d2f07b
commit
0e2e7d8b83
@ -0,0 +1,21 @@
|
||||
import pytest
|
||||
|
||||
from langchain.agents.openai_assistant import OpenAIAssistantRunnable
|
||||
|
||||
|
||||
@pytest.mark.requires("openai")
|
||||
def test_user_supplied_client() -> None:
|
||||
import openai
|
||||
|
||||
client = openai.AzureOpenAI(
|
||||
azure_endpoint="azure_endpoint",
|
||||
api_key="api_key",
|
||||
api_version="api_version",
|
||||
)
|
||||
|
||||
assistant = OpenAIAssistantRunnable(
|
||||
assistant_id="assistant_id",
|
||||
client=client,
|
||||
)
|
||||
|
||||
assert assistant.client == client
|
Loading…
Reference in New Issue