Skip to main content

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:

  1. Chat: Generate chat completions using our Sawalni multilingual models, supporting Moroccan Darija, English, French, Arabic and many other languages.
  2. Search: Perform internet searches in multiple languages with a single query.
  3. Generate Embeddings: Create embeddings for text in multiple languages using Madmon.
  4. Identify Language: Detect the language of a given text with Gherbal, supporting up to 33 languages.
  5. Translate Text: Translate text between 13 supported languages with Tarjamli.
  6. Transliterate Text: Convert Moroccan Arabic script to Moroccan Latin script with Daktilo.

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-micro, sawalni-mini, sawalni-small
chat = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-small")

# Stream
stream = client.chat.completions.create(messages=[{"role": "user", "content": "Hello, how are you?"}], model="sawalni-small", stream=True)
for chunk in stream:
    print(chunk.choices[0].delta.content)

Search

search = client.search("Hello, how are you?")

Generate Embeddings

embeddings = client.embed("Hello, world!")

Identify Language

language = client.identify("Bonjour le monde")

Translate Text

# You can specify a source language or let the model detect it automatically
translation = client.translate("Hello", source="auto", target="ary_Latn")

Transliterate Text

transliteration = client.transliterate("اهلا بيك", model="daktilo-mini", to="latn", temperature=0.1)

# {"text": "ahlane bik"}

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


Download files

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

Source Distribution

sawalni-0.2.9.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

sawalni-0.2.9-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sawalni-0.2.9.tar.gz.

File metadata

  • Download URL: sawalni-0.2.9.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for sawalni-0.2.9.tar.gz
Algorithm Hash digest
SHA256 8819e78650f9b42a70b87d1b46b4ad638229c4c2072f709b90f53d997dbc386f
MD5 82ad828a800a2d72440595ebfe061d1f
BLAKE2b-256 750685b68f39d6c19f4811d93cabbd737ada584e6d8413285c15e7242a0c8855

See more details on using hashes here.

File details

Details for the file sawalni-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: sawalni-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for sawalni-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 390c3f1415ea5c52067be83d9bfe960dea6d8776ac609291ca4a7eafae584c9f
MD5 b94038edea722d47e85e7e0a55467d3c
BLAKE2b-256 e709c16abf5deb50d8687b73c2d88841525bcca82cf8c1adc70f79a7f1a1fcb1

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