-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for OCI OpenAI Responses API with Langchain/Langgraph #61
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
Add support for OCI OpenAI Responses API with Langchain/Langgraph #61
Conversation
|
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
libs/oci/langchain_oci/chat_models/oci_generative_ai_responses_api.py
Outdated
Show resolved
Hide resolved
libs/oci/langchain_oci/chat_models/oci_generative_ai_responses_api.py
Outdated
Show resolved
Hide resolved
libs/oci/langchain_oci/chat_models/oci_generative_ai_responses_api.py
Outdated
Show resolved
Hide resolved
| import requests | ||
| from langchain_openai import ChatOpenAI | ||
| from oci.config import DEFAULT_LOCATION, DEFAULT_PROFILE | ||
| from openai import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openai not required in dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the way current packages are managed, we give error messages when specific required packages are not installed. For eg: oracle-ads, langchain-openai. So we have followed the same. When langchain-openai is not installed an error message is thrown. langchain-openai brings in the openai as a transitive dependency. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is going to fail because you are importing at the top level. Could you check what ads is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
|
@YouNeedCryDear |
Sounds like a good idea. But this might be a huge change to the code base and I don't think the Reponses API team is able to do. |
|
The change looks good to me. One more question regarding the file naming and structure. Is the ChatOCIOpenAI specifically for responses API or it can also be used for chat-completion? I wonder if we should rename the file to something more generic or directly move the class under oci_generative_ai.py. @furqan-shaikh-dev |
the openai API supports both. the langchain-openai tries to detects if the model selected used reasoning, and if so will automatically select the Response API, however it is also a flag you can set. in the example here: https://github.com/oracle-samples/oci-openai?tab=readme-ov-file#using-with-langchain-openai you can see how that works with langchai-openai |
That's why I think instead of having it under oci_generative_ai_responses_api.py, which the name is specific for responses api, we probably need to rename the file or just directly move the ChatOCIOpenAI class under oci_generative_ai.py |
libs/oci/langchain_oci/chat_models/oci_generative_ai_responses_api.py
Outdated
Show resolved
Hide resolved
libs/oci/examples/chat_models/langchain_oci_openai_responses_api_example.py
Outdated
Show resolved
Hide resolved
libs/oci/langchain_oci/chat_models/oci_generative_ai_responses_api.py
Outdated
Show resolved
Hide resolved
libs/oci/langchain_oci/chat_models/oci_generative_ai_responses_api.py
Outdated
Show resolved
Hide resolved
| API_KEY = "<NOTUSED>" | ||
| COMPARTMENT_ID_HEADER = "opc-compartment-id" | ||
| CONVERSATION_STORE_ID_HEADER = "opc-conversation-store-id" | ||
| OUTPUT_VERSION = "responses/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this? i find it strange to say responses/v1
in OpenAI, the path are like v1/responses and v1/chat/completions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is defined by langchain itself, for supporting openai responses API. Please see: https://github.com/langchain-ai/langchain/blob/525d5c0169225f4a56d732be0dad8ad5c78b7265/libs/partners/openai/langchain_openai/chat_models/base.py#L788
| conversation_store_id=conversation_store_id | ||
| ), | ||
| base_url=_resolve_base_url(region=region, service_endpoint=service_endpoint, base_url=base_url), | ||
| use_responses_api=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can customers use ChatOCIOpenAI with our compatible ChatCompletions API?
| super().__init__( | ||
| model=model, | ||
| api_key=SecretStr(API_KEY), | ||
| http_client=get_sync_httpx_client( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's our plan for Async client? Does LangChain has that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont see it supported yet. We will keep a tab and add whenever its available
Summary
Adds support for OpenAI Responses API by introducing a new class
OCIChatOpenAI. This allows users to invoke OCI Generative AI to leverage OpenAI Responses API.Changes
oci_generative_ai_responses_api.pywhich implementsOCIChatOpenAIclass and OCI Auth.examplesfolder to provide sample usagesREADME.mdTesting
Breaking Changes
None - this is a new feature that is fully backward compatible.