Skip to main content

A user-friendly GenAI wrapper that leverages SAP's AI Core to seamlessly translate requests into LLM calls.

Project description

Simple GenAI wrapper

A simple GenAI wrapper that leverages SAP's AI Core to seamlessly translate requests into LLM calls.

How to install?

Tip: It's always best to create an environment and install the package there.

Install the wrapper library, execute the below command:

pip install genai_wrapper

How to use?

Prepare you connection:

Create a config file config.json with content as shown below:

{
    "ai_core": {
        "secret": {
            "clientid": "<Enter value from the generated secret key>",
            "clientsecret": "<Enter value from the generated secret key>",
            "url": "<Enter value from the generated secret key>",
            "identityzone": "",
            "identityzoneid": "",
            "appname": "",
            "serviceurls": {
                "AI_API_URL": "<Enter value from the generated secret key>"
            }
        },
        "resource_group": "<Enter your ai-core resource group where you have deployed the models>"
    },
    "gen_ai": {
        "<Give a name to identify the model>": {
            "deploymentid": "<Enter the deployment Id>",
            "model_name": "<Enter the model name as per SAP's llm model name definition>",
            "parameters": {
                "max_tokens": 100,
                "temperature": 0.1,
                "frequency_penalty": 0.0,
                "presence_penalty": 0.0
            }
        },
        "model_gpt-4o": {
            "deploymentid": "d123456789012345",
            "model_name": "gpt-4o",
            "parameters": {
                "max_tokens": 500,
                "temperature": 1.0,
                "frequency_penalty": 0.0,
                "presence_penalty": 0.0
            }
        },
        "text-embedding": {
            "deploymentid": "d123456789054321"
        }
    },
    "hana_vec_store": {
        "host": "<Enter your HANA machine host>",
        "port": 443,
        "userid": "<Enter your user id>",
        "password": "<Enter your password>",
        "ssl_cert_validation": false
    }
}

Tip: To avoid errors, copy the JSON secret-key content generated for AI Core from your SAP BTP sub-account and paste it into ai_core > secret. Ensure no details within the key are modified.

Perform a simple chat:

from genai_wrapper.wrapper  import GenAIWrapper, ChatObject

# Make sure to pass the path of your config file if the config.json is not in the same directory.
gen_ai = GenAIWrapper(
    config_file="config.json"
)

chat = ChatObject()
chat.add_message("Who are you?")

gen_ai.chat("model_gpt-4o", chat)

print(chat.get_answer())

Perform a simple embedding call:

from genai_wrapper.wrapper  import GenAIWrapper

# Make sure to pass the path of your config file if the config.json is not in the same directory.
gen_ai = GenAIWrapper(
    config_file="config.json"
)

embed = gen_ai.embedding("text-embedding", "Hello World!")

print( embed )

Perform similarity search in HANA Db:

from genai_wrapper.wrapper  import GenAIWrapper, HANAVectorObject

# Make sure to pass the path of your config file if the config.json is not in the same directory.
gen_ai = GenAIWrapper(
    config_file="config.json"
)

hana_vec_object = HANAVectorObject(
    table="TABLE_PRODUCT_MASTER",
    columns="*",
    vector_col="VECTOR_PRODUCT_DESC",
    k=3
)
result = gen_ai.embedding_vec_store( "text-embedding", hana_vec_object, vec_text="notebook" )

print(result)

gen_ai.close()

Check out the examples folder for more code.

Found an issue/ Have a suggestion?

IMP: This package is for educational use and is not meant to replace other libraries.

If something is not working as expected or you have ideas for improvements, please feel free to open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genai_wrapper-0.0.9.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genai_wrapper-0.0.9-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file genai_wrapper-0.0.9.tar.gz.

File metadata

  • Download URL: genai_wrapper-0.0.9.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.15

File hashes

Hashes for genai_wrapper-0.0.9.tar.gz
Algorithm Hash digest
SHA256 16d4537e2e9b0a27355708a5d5fb4b60a20a3427a07ff39bc3350a065be17c10
MD5 187b4508cba17613adb2916696e2c018
BLAKE2b-256 e8b051522ce1929776e141a36b913e6ed04b3ff5476d5cec01b0f600d7d87188

See more details on using hashes here.

File details

Details for the file genai_wrapper-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: genai_wrapper-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.15

File hashes

Hashes for genai_wrapper-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 85cc3b42ac2db7a05fdb89759c4c36ceb5cedb96b4bfe6a4d180ba013f139b50
MD5 d1b35139b95c84fcb37634e5b85f285c
BLAKE2b-256 8d7bea206685ebaa573a1cf0545b22c9e8f9785bbfd9d1905c7e94e653030eff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page