Official Python SDK for the Sawalni API
Project description
Sawalni Python SDK
This is the official Python SDK for the Sawalni API, providing easy access to language-related services such as embedding generation, language identification, and translation. Sawalni API is developed by Omneity Labs, and provides unique multilingual models and NLP capabilities, including pioneering Moroccan Darija support.
Installation
Install the package using pip:
pip install sawalni
Quick Start
To use the Sawalni SDK, you'll need an API key. You can set it as an environment variable or pass it directly to the client:
from sawalni import Sawalni
client = Sawalni(api_key='your_api_key_here')
# or specify the key via SAWALNI_API_KEY in the environment
Features
The SDK supports both synchronous and asynchronous operations for the following services:
- Chat (OpenAI compatible)
- Generate Embeddings (languages depend on the model)
- Identify Language (35 languages supported)
- Translate Text (13 languages supported)
The Sawalni SDK includes an OpenAI compatible client, which can be accessed via the chat
and embeddings
properties, or direct use via the OpenAI client as detailed below.
Chat
# Available models: sawalni-zero, sawalni-micro, sawalni-mini
chat = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-zero")
# Stream
stream = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-zero", stream=True)
for chunk in stream:
print(chunk.choices[0].delta.content)
Generate Embeddings
embeddings = client.embed("Hello, world!")
Identify Language
language = client.identify("Bonjour le monde")
Translate Text
translation = client.translate("Hello", source="eng_Latn", target="ary_Latn")
Asynchronous Usage
For asynchronous operations, use the SawalniAsync client:
from sawalni import SawalniAsync
async_client = SawalniAsync(api_key='your_api_key_here')
embeddings = await async_client.embed("Hello, world!")
OpenAI compatible client
The SDK also includes an OpenAI compatible client, which can be accessed via the chat
and embeddings
properties:
chat = client.chat
embeddings = client.embeddings
You can also use the OpenAI client directly with the base URL set to https://api.sawalni.com/v1
and the API key set to your Sawalni API key.
import openai
client = openai.OpenAI(base_url="https://api.sawalni.com/v1", api_key="your_api_key_here")
Only the chat
and embeddings
properties are supported with this approach.
Documentation
For detailed information about available models, parameters, languages and and response formats, please refer to the complete API documentation at https://api.sawalni.com.
Support
If you encounter any issues or have questions, please contact api@sawalni.com.
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
Built Distribution
File details
Details for the file sawalni-0.1.8.tar.gz
.
File metadata
- Download URL: sawalni-0.1.8.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be73c3a3f3c5e0e1935366b03cf88c7a7f52e1e5807ec722b0de7f1334569ed6 |
|
MD5 | 706edd457fdb464f091626774d7ed9dc |
|
BLAKE2b-256 | df3a00715c0b0c9c3cae77752f07cf4a03f00659f2cf6dc3361bf81da18f54fb |
File details
Details for the file sawalni-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: sawalni-0.1.8-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97cc53b46cb9ee940c938398af483488ed903a294cb2bb1cde027c31925dbe3 |
|
MD5 | 5b4b8c804e67e4bc6896c885c2697d23 |
|
BLAKE2b-256 | 7efd9961ef610745ca1f21c3ec99761e571c0e2cd9907ea590362d5d0f6e1680 |