Skip to main content

Opper Python client

Project description

Opper Python SDK

Install

pip install opperai

Using the fn decorator

from opperai import fn

@fn()
def translate(text: str, target_language: str) -> str:
    """Translate text to a target language."""


print(translate("Hello","fr"))

>>> "Bonjour"

The fn decorator automatically creates an Opper function ready to be called like any other function in your code. They're no different than any other function!

Calling functions manually

To call a function you created at https://platform.opper.ai you can use the following code:

from opperai import Client
from opperai.types import ChatPayload, Message

# Use AsyncClient for async operations
client = Client(api_key="your-api-key") 
response = client.functions.chat("your-function-path", 
 ChatPayload(messages=[Message(role="user", content="hello")])
)

print(response)

This more traditional API is better targeted for chat use cases.

Configuration

Environment variable

The OPPER_API_KEY environment variable is read by the SDK if no api_key is provided to the Client object.

When using the fn decorator the SDK client is automatically initialized with the OPPER_API_KEY environment variable.

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

opperai-0.0.9.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

opperai-0.0.9-py2.py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 2 Python 3

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