Metadata-Version: 2.1
Name: sapapj-langchain-proxy
Version: 0.0.2
Summary: Connect langchain to SAP's AI proxy.
Author-email: Skye0402 <albrechg@yahoo.com>
License: MIT License
        
        Copyright (c) [2023] [Gunter Albrecht]
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/skye0402/saplangchain-proxy
Keywords: langchain,sap,proxy
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: oauthlib>=3.2.2
Requires-Dist: requests-oauthlib>=1.3.1
Requires-Dist: tomli; python_version < "3.11"
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: bumpver; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: pip-tools; extra == "dev"
Requires-Dist: pytest; extra == "dev"

# 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:

```python
# 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
```python
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.
