Skip to main content

IBM Watsonx API wrapper package for calling text generation and embedding requests

Project description

IBM Watsonx API wrapper package for calling text generation and embedding requests

Python


Setup a local environment or install on current:

PyPi package link: WatsonxConnector

pip install WatsonxConnector

Usage / Examples

from WatsonxConnector.connector import WatsonxConnector

example_connector_obj = WatsonxConnector(base_url=cp4d_url,
                                         user_name=user_name,
                                         api_key=api_key,
                                         model_id=model_id,
                                         project_id=project_id
                                         )

for model, model_type in example_connector_obj.get_available_models().items():
    print(f"{model}: {model_type}")

example_connector_obj.set_model_params(temperature=0.7, max_new_tokens=800)
print(example_connector_obj.get_model_params())

print(example_connector_obj.generate_text("Write an example python unittest"))

example_connector_obj.set_model_id(model_id="ibm/slate-125m-english-rtrvr")
for embed in example_connector_obj.generate_embedding(["something", "something else"]):
    print(embed)

Example output from above:

codellama/codellama-34b-instruct-hf: text_generation
ibm/granite-13b-chat-v2: text_generation
ibm/slate-125m-english-rtrvr: embedding
ibm/slate-30m-english-rtrvr: embedding
meta-llama/llama-3-70b-instruct: text_generation
{'decoding_method': 'sample', 'max_new_tokens': 800, 'temperature': 0.7, 'top_k': 20, 'top_p': 0.9, 'repetition_penalty': 1.1}
import unittest
from mymodule import my_function

class MyTest(unittest.TestCase):

    def test_my_function(self):
        result = my_function('hello world')
        self.assertEqual(result, 'Hello World')

if __name__ == '__main__':
    unittest.main()

This is an example of a simple Python unit test using the `unittest` module. 
In this case, we define a new class ...
[-0.024465775, -0.0329509, -0.00046468992, -0.017108368, ...  0.017113319, 0.01991029, -0.010878863, 0.005576967]
[-0.037240397, -0.04046932, -0.03115683, -0.034350585, ... 0.020475477, 0.05027425, 0.006514402, 0.0150749]

Documentation:

List of available class methods:

  • set_system_prompt()
  • set_model_id()
  • set_model_params()
  • set_api_version()
  • set_project_id()
  • get_model_id()
  • get_auth_token()
  • get_model_params()
  • get_available_models()
  • get_params()
  • check_model_type()
  • generate_text()
  • generate_embedding()
  • generate_auth_token()

License

Apache-2.0

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

watsonxconnector-0.0.7.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

WatsonxConnector-0.0.7-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file watsonxconnector-0.0.7.tar.gz.

File metadata

  • Download URL: watsonxconnector-0.0.7.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for watsonxconnector-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d70bd08fc91779d1a3cdf75c101cc8bc6249183b459e8a84f0f5145d26a9a651
MD5 7952e6e93f9b44c3c8fc4ebd0a92807c
BLAKE2b-256 3329a44229ed43711c506168ef6a9d17ba367293dc12960414261abcbb4b3f22

See more details on using hashes here.

File details

Details for the file WatsonxConnector-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for WatsonxConnector-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 629b04ff2f3e3e7fc3dc441f76966fcb33d5cc3a6b8c4c3f10dacbd5ffb242cf
MD5 44e27774fa47aa9c3b28fbb64c0db91b
BLAKE2b-256 2d6dc8014e6685a668c3104ac2a7196b712608b5e7f902b3a29e3444ac6e920d

See more details on using hashes here.

Supported by

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