Skip to main content

Client Library to communicate with AIMan-API

Project description

AIMan API-Client by brandCompete

Package brandCompete AIMan AIMan

Preconditions

Python version: >=3.8.1

Installation

pip install aiman-client

Getting started

Instantiate the api client

IMPORTANT: The host_url needs to be the base address of the api you want to connect to. The format of the host_url should look like this example:

from aiman.client import AimanClient

client = AimanClient(
    host_url="https://aiman-api-test.brandcompete.com",
    user_name="john@doe.com",
    password="top_secret")

Autorefresh JWT-Token

The client takes care of updating the token during the client's runtime if it has expired.

Fetching available AI-Models

This method returns a list of available models of type AIModel.

models = client.get_models()
for model in models:
    print(f"[default tag:{model.default_model_tag_id:4}] {model.name.upper():25} - {model.short_description}")

Prompting a simple query to a specific model

In order to submit a query the model for the prompt must be determined. This is done via the model_tag_id as parameter and can be taken from the AIModel object by default_model_tag_id property. Alternatively, you can also view available models here

response:dict = client.prompt(
    model_tag_id=10,
    query="Enter a question to prompt for")
print(response["responseText"])

Prompting a query and attach one or more files

response:dict = client.prompt(
    model_tag_id=1, 
    query="Enter a question to ask something about the given file content...", 
    attachments=["file/path/file_1.pdf", "file/path/file_2.xlsx"])

Raging with datasources and documents

Datasource

Init a new datasource with minimum requirements: name and summary

datasource_id = client.init_new_datasource(
    name="Test datasource", 
    summary="New datasource for uploading some documents")

Or init a new datasource with a list of tags and categories

datasource_id = client.init_new_datasource(
    name="Test datasource", 
    summary="New datasource for uploading documents", 
    tags=["tagA","tagB", "etc"], 
    categories=["catA","catB","etc"])

Fetch all datasources (associated to your account). Possible status:

  • 2 (ready)
  • 1 (indexing)
  • 0 (pending)
datasources = client.fetch_all_datasources()
for source in datasources:
    print(f"{source.id}")
    print(f"{source.name}")
    print(f"{source.status}")

Documents

Add multiple documents into a datasource (can be url or file)

client.add_documents(
    data_source_id=your_ds_id, 
    sources=["path/to_my_data/test.pdf", "https://www.brandcompete.com"] )

Prompt on datasource context

Prompt in conjunction with a datasource_id. You have to use the model_tag_id to specify the model to prompt. NOTE: The datasource requires status == 2 and should be checked before prompting.

client.prompt_on_datasource(
    datasource_id=datasource_id, 
    model_tag_id=200, 
    query="can you please summarize the content?", 
    prompt_options = None)

Prompt options

You can pass prompt options as a optional parameter to any kind of prompt.

New instance with current properties and their default values.

from aiman.core.classes import PromptOptions

options = PromptOptions()
options.keep_context = True,
options.num_ctx = 8128
options.raw = True
options.temperature = 0.8
options.mirostat = 0
options.mirostat_eta = 0.1
options.mirostat_tau = 5
options.num_gqa = 8
options.num_gpu = 0
options.num_thread = 0
options.repeat_last_n = 64
options.repeat_penalty = 1.1
options.seed = 0

Executing prompt with options:

options = PromptOptions()
options.keep_context = False

response:dict = client.prompt(
    model_tag_id=10,
    query="Enter a question to prompt for"
    prompt_options = options
    )

Prompt on datasource example:

options = PromptOptions()
options.temperature = 0.2

client.prompt_on_datasource(
    datasource_id=datasource_id, 
    model_tag_id=200, 
    query="can you please summarize the content?", 
    prompt_options = options)

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

aiman_client-1.0.21.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

aiman_client-1.0.21-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file aiman_client-1.0.21.tar.gz.

File metadata

  • Download URL: aiman_client-1.0.21.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for aiman_client-1.0.21.tar.gz
Algorithm Hash digest
SHA256 bb70da704a0279c95d4f29280705c9778bef737c1cff88a4bc59547de20d0abd
MD5 f4bfb05e9c55c2d479fcf447c06cb80b
BLAKE2b-256 ea8bbe78e5451d65f2be95363ae1a1dec2143f0480c37177f7d60b5156a68385

See more details on using hashes here.

File details

Details for the file aiman_client-1.0.21-py3-none-any.whl.

File metadata

  • Download URL: aiman_client-1.0.21-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for aiman_client-1.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 a12ae7ed69a0ed8c3598811c8a2587050ace20f05b7ca05f61ac93505c9ffc77
MD5 65153962335239019a164ec2b6e893e3
BLAKE2b-256 c3dd03660775cc69d948937d871d3b1b73f4b59426e324fd65b20a0ca2a8d79f

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