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

    options = PromptOptions()
    options.keep_context = True,
    options.num_ctx = 8128
    options.raw = True
    options.temperature = 0.4
    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:

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

Prompt on datasource example:

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.18.tar.gz (18.8 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.18-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiman_client-1.0.18.tar.gz
  • Upload date:
  • Size: 18.8 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.18.tar.gz
Algorithm Hash digest
SHA256 b248d5f4024c7224dbe5c3130aae9695c893681280128855f83f1b0052d6cbe4
MD5 d7fe171cda854a7022d636124c2ca3fa
BLAKE2b-256 8b9b08477163635c2e2ff9b6d5468f2a55dad7b997d65d5edb49af63e2c14028

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiman_client-1.0.18-py3-none-any.whl
  • Upload date:
  • Size: 19.1 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.18-py3-none-any.whl
Algorithm Hash digest
SHA256 8d9bff695600f4d518c28a6bc67533f7f2a012dfb90821491d189b78e8462d2b
MD5 d19b4375aa47c5d489d88de487b1fe01
BLAKE2b-256 5d3f67ceb0bff6c6ae9864a6fb4cd469639b0dc1e59b878239e4aba3fa7e51bb

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