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 Async Doesn't Work #29270

Closed
5 tasks done
GhimBoon opened this issue Jan 17, 2025 · 2 comments
Closed
5 tasks done

OpenAIAssistantRunnable Async Doesn't Work #29270

GhimBoon opened this issue Jan 17, 2025 · 2 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@GhimBoon
Copy link

GhimBoon commented Jan 17, 2025

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.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

The following code:

import asyncio
from openai import AsyncAzureOpenAI
from langchain.agents.openai_assistant import OpenAIAssistantRunnable
from utils.read_config import GPT4_API_DEPLOYMENT, GPT4_API_BASE, API_TOKEN
load_dotenv(find_dotenv(), override=True)

async_client = AsyncAzureOpenAI(
    azure_endpoint=GPT4_API_BASE,
    api_key=API_TOKEN,
    api_version="2024-05-01-preview"

)
async def call_code_interpreter():
    agent = await OpenAIAssistantRunnable.acreate_assistant(
        name="chatgpt",
        instructions="You are a very careful thinker. Think step by step before answering queries.",
        model=GPT4_API_DEPLOYMENT,
        tools=[{"type": "code_interpreter"}],
        async_client=async_client
    )
    return agent

async def main():
    agent = await call_code_interpreter()
    output = await agent.ainvoke({"content": """
    Plot a simple line graph with the following data:
    x = [1, 2, 3, 4, 5]
    y = [2, 3, 5, 7, 11]
    """})
    print(output)

if __name__ == "__main__":
    asyncio.run(main())

Error Message and Stack Trace (if applicable)

File ~/miniforge3/envs/python3.12/lib/python3.12/site-packages/openai/_client.py:110, in OpenAI.__init__(self, api_key, organization, project, base_url, websocket_base_url, timeout, max_retries, default_headers, default_query, http_client, _strict_response_validation)
    108     api_key = os.environ.get("OPENAI_API_KEY")
    109 if api_key is None:
--> 110     raise OpenAIError(
    111         "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"
    112     )
    113 self.api_key = api_key
    115 if organization is None:

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

Description

The API Key is already added in the Async Client as well as env.

The exact same code, but for non-async works without issues.

System Info

System Information

OS: Linux
OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Python Version: 3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:43:22) [GCC 12.3.0]

Package Information

langchain_core: 0.3.29
langchain: 0.3.14
langchain_community: 0.3.14
langsmith: 0.2.10
langchain_openai: 0.3.0
langchain_postgres: 0.0.12
langchain_sdk: 0.1.5
langchain_text_splitters: 0.3.5
langchain_unstructured: 0.1.6
langgraph_sdk: 0.1.51

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch: 1.33
langchain_core>=0.3.0: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
onnxruntime: 1.19.2
openai: 1.59.7
orjson: 3.10.14
packaging: 23.2
pgvector: 0.2.5
psycopg: 3.2.3
psycopg-pool: 3.2.4
pydantic: 2.9.2
pydantic-settings: 2.7.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.37
sqlalchemy: 2.0.37
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2
unstructured-client: 0.27.0
unstructured[all-docs]: Installed. No version info available.
zstandard: Installed. No version info available.

@langcarl langcarl bot added the investigate Flagged for investigation. label Jan 17, 2025
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jan 17, 2025
@keenborder786
Copy link
Contributor

@GhimBoon I ran the exact same code you provided and it works, please make sure you are loading the correct environment variables.

@GhimBoon
Copy link
Author

Closing issue to troubleshoot further. Thank you for the confirmation.

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

No branches or pull requests

2 participants