Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAIAssistantRunnable raise exception when pass client #15948

Closed
3 of 15 tasks
hasansustcse13 opened this issue Jan 12, 2024 · 2 comments
Closed
3 of 15 tasks

OpenAIAssistantRunnable raise exception when pass client #15948

hasansustcse13 opened this issue Jan 12, 2024 · 2 comments
Labels
Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@hasansustcse13
Copy link
Contributor

hasansustcse13 commented Jan 12, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.

Example Code

I want to create an OpenAI assistant using an existing ID, but I'm encountering an error.

  1. assistant = OpenAIAssistantRunnable(assistant_id='assistant_id', as_agent=True)
    openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
  2. assistant = OpenAIAssistantRunnable(assistant_id='assistant_id', as_agent=True, client=openai.OpenAI(api_key=self.model.openai_api_key))
    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()

In both cases, an error is encountered. The only successful scenario is when the openai_api_key is set in the environment, but my requirement is for the user to provide it. Has anyone else faced a similar issue? Any assistance would be appreciated.

Description

OpenAIAssistantRunnable raise exception when pass client. There should be a way to pass the key from outside

System Info

langchain==0.1.0

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async
Copy link

dosubot bot commented Jan 12, 2024

🤖

I appreciate your interest in contributing to LangChain! It's great to see your enthusiasm for finding a solution to the issue with passing the client key from outside. Your efforts to address this problem are valuable to the community.

If you have a proposed solution or fix in mind, I encourage you to go ahead and create a pull request. Your contribution will help improve LangChain for all users. Thank you for your willingness to contribute!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Jan 12, 2024
baskaryan pushed a commit that referenced this issue Jan 24, 2024
…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:** #15948
  - **Dependencies:** N/A
@kristapratico
Copy link
Contributor

This was addressed in #16486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants