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.
Retrieval
client.indexes.retrieve(index_id=42, "Who is the president of the USA?", 3)
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
Release history Release notifications | RSS feed
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.1.4.tar.gz
(11.6 kB
view hashes)
Built Distribution
Close
Hashes for opperai-0.1.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d8d6b19fa4ecdb2f5f4d69cd58a26d5d7986019a23326be5cae91705f2497e3 |
|
MD5 | 9b9867d6c14480d6fea4a956e31d559a |
|
BLAKE2b-256 | b48b1e381a63444e2acc53951194acd949f7dc64880bab0450b585214081d8d6 |