SAP Langchain Proxy to work with AI models at SAP
OpenAI SAP BTP Proxy
The OpenAI SAP BTP Proxy is a Python library that provides a proxy to connect to OpenAI services through SAP Business Technology Platform (BTP) with OAuth2 authentication. It abstracts interactions with various OpenAI models for tasks such as generating completions, working with embeddings, and using chat-based language models.
Features
- Completions: Interact with OpenAI models for text completions.
- Embeddings: Work with text embeddings using OpenAI models.
- Chat Completions: Utilize chat-based language models for conversational applications.
Usage
To use the library, you need to provide the necessary configuration for OAuth2 authentication and OpenAI endpoints. Below is an example of how to set up and use the library:
# Configure OAuth2 and OpenAI endpoints
oauth_config = {
"openai_api_client_id": "YOUR_CLIENT_ID",
"openai_api_client_secret": "YOUR_CLIENT_SECRET",
"openai_api_tokenurl": "OPENAI_TOKEN_URL",
"openai_api_url": "OPENAI_API_URL"
}
It's recommended, though to provide the parameters as environment variables
OPENAI_CLIENTID
OPENAI_CLIENTSECRET
OPENAI_APIURL
OPENAI_TOKENURL
Example code
Use below examples for LLM or Chat models in langchain
from saplangchainproxy.chat import SAPChatOpenAI
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory
chat = SAPChatOpenAI(model='gpt-4', temperature=0.0)
conversation = ConversationChain(
llm=chat,
memory=ConversationBufferMemory()
)
test_string = "Hello I'm an AI."
test_reply = conversation.run(f"Just answer with '{test_string}'. Nothing else.")
print(f"AI response is: {test_reply}")
from saplangchainproxy.llm import SAPAzureOpenAI
llm = SAPAzureOpenAI(temperature=0.0)
test_string = "Hello I'm an AI."
test_reply = llm(f"Just answer with '{test_string}'. Nothing else.")
print(f"AI response is: {test_reply}")
License
This library is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for sapapj-langchain-proxy 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sapapj-langchain-proxy-0.0.2.tar.gz | 19.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sapapj_langchain_proxy-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.6 kB
Release files / sapapj-langchain-proxy-0.0.2.tar.gz
| Download URL | sapapj-langchain-proxy-0.0.2.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
647bef7c6075ddf509d9de15531775227b943d83441f8b86f9c7dd297610bb3f
|
|
BLAKE2b-256 checksum How to use checksums |
a1c7345f777b8cbaa6c17ab6e482c20de2ac252f8c8a564f7bebeb7d0d072030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Release files / sapapj_langchain_proxy-0.0.2-py3-none-any.whl
| Download URL | sapapj_langchain_proxy-0.0.2-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31354901362227d9256224519895023d3552a6dd6959175f4647e0bc98a8ee77
|
|
BLAKE2b-256 checksum How to use checksums |
ab41ab4b72bfa20ee246592a46586e4e5df7a8540463768e24af76989edc5030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|