Skip to main content

Simple client to interact with regolo.ai

Project description

Regolo.ai Python Client

A simple Python client for interacting for Regolo.ai's LLM-based API.

Installation

Ensure you have the regolo module installed. If not, install it using:

  pip install regolo

Basic Usage

1. Import the regolo module

import regolo

2. Set Up Default API Key and Model

To avoid manually passing the API key and model in every request, you can set them globally:

regolo.default_key = "<EXAMPLE_KEY>"
regolo.default_model = "Llama-3.3-70B-Instruct"

This ensures that all RegoloClient instances and static functions will use the specified API key and model.

Still, you can create run methods by inserting model and key directly.

3. Perform a basic request

Completion:

print(regolo.static_completions(prompt="Tell me something about Rome."))

Chat_completion

print(regolo.static_chat_completions(messages=[{"role": "user", "content": "Tell me something about rome"}]))

Chatting through regolo chat CLI

1. What is the regolo chat cli?

To simplify basic interactions with our LLMs, we offer you the possibility to perform request without writing code. To do that, you only need to install python and, if you want, create a venv with the commands:

pip install virtualenv # install virtualenv in python
cd <the directory that'll contain your venv> # choose the starting directory for your venv
python -m venv env # create the venv in the env subdirectory 

To use your venv, you'll go to the env subdirectory and use the source command activate it:

source bin/activate

At this point, you can run a simple chat with:

regolo chat

The CLI will guide you through inserting your API key and desired model.

It is worth mentioning our "chat" command has support for some flags (you can use more of them at the same time).

  • "--no-hide", used to see your API key while typing
regolo chat --no-hide
  • "--disable-newlines", to use if you prefer your AI to output spaces instead of new lines, which could make the response text too large for your environment.
regolo chat --disable-newlines

Loading envs

if you want to interact with this client through environment variables, you can follow this reference:

Default values

  • "API_KEY"

You can use this environment variable to insert the default_key. You can load it after importing regolo using regolo.key_load_from_env_if_exists(). Using it is equivalent to updating regolo.default_key when you import regolo.

  • "LLM"

You can use this environment variable to insert the default_model. You can load it after importing regolo using regolo.default_model_load_from_env_if_exists(). This is equivalent to updating regolo.default_model when you import regolo.

  • "IMAGE_MODEL"

You can use this environment variable to insert the default_image_model. You can load it after importing regolo using regolo.default_image_load_from_env_if_exists(). This is equivalent to updating regolo.default_image_model when you import regolo.

  • "EMBEDDER_MODEL"

You can use this environment variable to insert the default_embedder_model. You can load it after importing regolo using regolo.default_embedder_load_from_env_if_exists(). This is equivalent to updating regolo.default_embedder_model when you import regolo.

[!TIP] All "default" environment variables can be updated together through regolo.try_loading_from_env().

It does nothing but run all the load_from_env methods al once.

Endpoints

  • "REGOLO_URL"

You can use this env variable to set the default base_url used by regolo client and its static methods.

  • "COMPLETIONS_URL_PATH"

You can use this env variable to set the base_url used by regolo client and its static methods.

  • "CHAT_COMPLETIONS_URL_PATH"

You can use this env variable to set the chat completions endpoint used by regolo client and its static methods.

  • "IMAGE_GENERATION_URL_PATH"

You can use this env variable to set the image generation endpoint used by regolo client and its static methods.

  • "EMBEDDINGS_URL_PATH"

You can use this env variable to set the embedding generation endpoint used by regolo client and its static methods.

[!TIP] The "endpoints" environment variables can be changed during execution. Since the client works directly with them.

However, you are likely not to want to change them, since they are tied to how we handle our endpoints.


Other usages

Handling streams

With full output:

import regolo
regolo.default_key = "<EXAMPLE_KEY>"
regolo.default_model = "Llama-3.3-70B-Instruct"

# Completions

client = regolo.RegoloClient()
response = client.completions("Tell me about Rome in a concise manner", full_output=True, stream=True)

while True:
    try:
        print(next(response))
    except StopIteration:
        break

# Chat completions

client = regolo.RegoloClient()
response = client.run_chat(user_prompt="Tell me about Rome in a concise manner", full_output=True, stream=True)


while True:
    try:
        print(next(response))
    except StopIteration:
        break

Without full output:

import regolo
regolo.default_key = "<EXAMPLE_KEY>"
regolo.default_model = "Llama-3.3-70B-Instruct"

# Completions

client = regolo.RegoloClient()
response = client.completions("Tell me about Rome in a concise manner", full_output=False, stream=True)

while True:
    try:
        print(next(response), end='', flush=True)
    except StopIteration:
        break

# Chat completions

client = regolo.RegoloClient()
response = client.run_chat(user_prompt="Tell me about Rome in a concise manner", full_output=False, stream=True)

while True:
    try:
        res = next(response)
        if res[0]:
            print(res[0] + ":")
        print(res[1], end="", flush=True)
    except StopIteration:
        break

Handling chat through add_prompt_to_chat()

import regolo

regolo.default_key = "<EXAMPLE_KEY>"
regolo.default_model = "Llama-3.3-70B-Instruct"

client = regolo.RegoloClient()

# Make a request

client.add_prompt_to_chat(role="user", prompt="Tell me about rome!")

print(client.run_chat())

# Continue the conversation

client.add_prompt_to_chat(role="user", prompt="Tell me something more about it!")

print(client.run_chat())

# You can print the whole conversation if needed

print(client.instance.get_conversation())

It is to consider that using the user_prompt parameter in run_chat() is equivalent to adding a prompt with role=user through add_prompt_to_chat().

Handling image models

Without client:

from io import BytesIO

import regolo
from PIL import Image

regolo.default_image_model = "FLUX.1-dev"
regolo.default_key = "<EXAMPLE_KEY>"

img_bytes = regolo.static_image_create(prompt="a cat")[0]

image = Image.open(BytesIO(img_bytes))

image.show()

With client

from io import BytesIO

import regolo
from PIL import Image
client = regolo.RegoloClient(image_model="FLUX.1-dev", api_key="<EXAMPLE_KEY>")

img_bytes = client.create_image(prompt="A cat in Rome")[0]

image = Image.open(BytesIO(img_bytes))

image.show()

Handling embedder models

Without client:

import regolo

regolo.default_key = "<EXAMPLE_KEY>"
regolo.default_embedder_model = "gte-Qwen2"


embeddings = regolo.static_embeddings(input_text=["test", "test1"])

print(embeddings)

With client:

import regolo

client = regolo.RegoloClient(api_key="<EXAMPLE_KEY>", embedder_model="gte-Qwen2")

embeddings = client.embeddings(input_text=["test", "test1"])

print(embeddings)

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

regolo-1.2.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

regolo-1.2.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file regolo-1.2.0.tar.gz.

File metadata

  • Download URL: regolo-1.2.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for regolo-1.2.0.tar.gz
Algorithm Hash digest
SHA256 dc8178bc8c7b573dfe2675bf48a14a29327cb6a9f6962c212bfbe883b6b902cc
MD5 005e75d7e45b3c5900d32131f1fb7baf
BLAKE2b-256 00021f46b3b788b69ce00fbf82bb535dff55824e01738f9c921ab2d74d5e8295

See more details on using hashes here.

File details

Details for the file regolo-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: regolo-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for regolo-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f818d26007b504b5c987b6def09bf5c8ab481be479bf3ee8322b2ebd3a5c2c71
MD5 8eb9396500882a9181c0825cc541adef
BLAKE2b-256 f2895062a547ea96c8f2c4383218276d190a99e6cb3b6fd35d7c0b7d27405760

See more details on using hashes here.

Supported by

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