Skip to main content

Mirage API Python wrapper.

Project description

python-mirage-api

Build and Release PyPI Downloads

The Mirage API Python wrapper. Access AI inference services.

Copyright 2023 Crisp IM SAS. See LICENSE for copying information.

Usage

Install the library:

pip install mirage-api

Then, import it:

from mirage_api import Mirage

Construct a new authenticated Mirage client with your user_id and secret_key tokens.

client = Mirage("ui_xxxxxx", "sk_xxxxxx")

Then, consume the client eg. to transcribe a audio file containing speech to text:

data = client.task.transcribe_speech({
  "locale": {
    "to": "en"
  },

  "media": {
    "type": "audio/webm",
    "url": "https://files.mirage-ai.com/dash/terminal/samples/transcribe-speech/hey-there.weba"
  }
})

Authentication

To authenticate against the API, get your tokens (user_id and secret_key).

Then, pass those tokens once when you instanciate the Mirage client as following:

# Make sure to replace 'user_id' and 'secret_key' with your tokens
client = Mirage("user_id", "secret_key")

Resource Methods

This library implements all methods the Mirage API provides. See the API docs for a reference of available methods, as well as how returned data is formatted.

Task API

➡️ Transcribe Speech

client.task.transcribe_speech({
  "locale": {
    "to": "en"
  },

  "media": {
    "type": "audio/webm",
    "url": "https://files.mirage-ai.com/dash/terminal/samples/transcribe-speech/hey-there.weba"
  }
});
  • Response:
{
  "reason": "processed",

  "data": {
    "locale": "en",

    "parts": [
      {
        "start": 5.0,
        "end": 9.0,
        "text": " I'm just speaking some seconds to see if the translation is correct"
      }
    ]
  }
}

➡️ Answer Prompt

  • Method: client.task.answer_prompt(data)

  • Reference: Answer Prompt

  • Request:

client.task.answer_prompt({
  "prompt": "Generate an article about Alpacas"
});
  • Response:
{
  "reason": "processed",

  "data": {
    "answer": "The alpaca (Lama pacos) is a species of South American camelid mammal. It is similar to, and often confused with, the llama. However, alpacas are often noticeably smaller than llamas. The two animals are closely related and can successfully crossbreed. Both species are believed to have been domesticated from their wild relatives, the vicuña and guanaco. There are two breeds of alpaca: the Suri alpaca and the Huacaya alpaca."
  }
}

➡️ Answer Question

  • Method: client.task.answer_question(data)

  • Reference: Answer Question

  • Request:

client.task.answer_question({
  "question": "Should I pay more for that?",

  "answer": {
    "start": "Sure,"
  },

  "context": {
    "primary_id": "cf4ccdb5-df44-4668-a9e7-3ab31bebf89b",

    "conversation": {
      "messages": [
        {
          "from": "customer",
          "text": "Hey there!"
        },

        {
          "from": "agent",
          "text": "Hi. How can I help?"
        },

        {
          "from": "customer",
          "text": "I want to add more sub-domains to my website."
        }
      ]
    }
  }
});
  • Response:
{
  "reason": "processed",

  "data": {
    "answer": "You can add the Crisp chatbox to your website by following this guide: https://help.crisp.chat/en/article/how-to-add-crisp-chatbox-to-your-website-dkrg1d/ :)",
    "sources": []
  }
}

➡️ Summarize Paragraphs

client.task.summarize_paragraphs({
  "paragraphs": [
    {
      "text": "GPT-4 is getting worse over time, not better."
    },

    {
      "text": "Many people have reported noticing a significant degradation in the quality of the model responses, but so far, it was all anecdotal."
    }
  ]
});
  • Response:
{
  "reason": "processed",

  "data": {
    "summary": "GPT-4 is getting worse over time, not better. We have a new version of GPT-4 that is not improving, but it is regressing."
  }
}

➡️ Summarize Conversation

client.task.summarize_conversation({
  "transcript": [
    {
      "name": "Valerian",
      "text": "Hello! I have a question about the Crisp chatbot, I am trying to setup a week-end auto-responder, how can I do that?"
    },

    {
      "name": "Baptiste",
      "text": "Hi. Baptiste here. I can provide you an example bot scenario that does just that if you'd like?"
    }
  ]
});
  • Response:
{
  "reason": "processed",

  "data": {
    "summary": "Valerian wants to set up a week-end auto-responder on Crisp chatbot. Baptiste can give him an example."
  }
}

➡️ Categorize Conversations

client.task.categorize_conversations({
  "conversations": [
    {
      "transcript": [
        {
          "from": "customer",
          "text": "Hello! I have a question about the Crisp chatbot, I am trying to setup a week-end auto-responder, how can I do that?"
        },

        {
          "from": "agent",
          "text": "Hi. Baptiste here. I can provide you an example bot scenario that does just that if you'd like?"
        }
      ]
    }
  ]
});
  • Response:
{
  "reason": "processed",

  "data": {
    "categories": [
      "Chatbot Configuration Issue"
    ]
  }
}

➡️ Rank Question

  • Method: client.task.rank_question(data)

  • Reference: Rank Question

  • Request:

client.task.rank_question({
  "question": "Hi! I am having issues setting up DNS records for my Crisp helpdesk. Can you help?",

  "context": {
    "source": "helpdesk",
    "primary_id": "cf4ccdb5-df44-4668-a9e7-3ab31bebf89b"
  }
});
  • Response:
{
  "reason": "processed",

  "data": {
    "results": [
      {
        "id": "15fd3f24-56c8-435e-af8e-c47d4cd6115c",
        "score": 9,
        "grouped_text": "Setup your Helpdesk domain name\ntutorials for most providers",

        "items": [
          {
            "source": "helpdesk",
            "primary_id": "51a32e4c-1cb5-47c9-bcc0-3e06f0dce90a",
            "secondary_id": "15fd3f24-56c8-435e-af8e-c47d4cd6115c",
            "text": "Setup your Helpdesk domain name\ntutorials for most providers",
            "timestamp": 1682002198552,

            "metadata": {
              "title": "Setup your Helpdesk domain name"
            }
          }
        ]
      }
    ]
  }
}

➡️ Translate Text

  • Method: client.task.translate_text(data)

  • Reference: Translate Text

  • Request:

client.task.translate_text({
  "locale": {
    "from": "fr",
    "to": "en"
  },

  "type": "html",
  "text": "Bonjour, comment puis-je vous aider <span translate=\"no\">Mr Saliou</span> ?"
});
  • Response:
{
  "reason": "processed",

  "data": {
    "translation": "Hi, how can I help you Mr Saliou?"
  }
}

➡️ Fraud Spamicity

  • Method: client.task.fraud_spamicity(data)

  • Reference: Fraud Spamicity

  • Request:

client.task.fraud_spamicity({
  "name": "Crisp",
  "domain": "crisp.chat",
  "email_domain": "mail.crisp.chat"
});
  • Response:
{
  "reason": "processed",

  "data": {
    "fraud": false,
    "score": 0.13
  }
}

➡️ Spam Conversation

client.task.spam_conversation({
  "sender": {
    "name": "John Doe",
    "email": "john@example.com"
  },

  "transcript": [
    {
      "from": "customer",
      "origin": "chat",
      "text": "Hello, I would like to discuss your services"
    }
  ]
});
  • Response:
{
  "reason": "processed",

  "data": {
    "class": "spam",
    "confidence": 0.93,
    "logprob": -0.10,

    "scores": {
      "gibberish": 0.0,
      "marketing": 0.45,
      "regular": 0.0,
      "spam": 0.93
    }
  }
}

➡️ Spam Document

  • Method: client.task.spam_document(data)

  • Reference: Spam Document

  • Request:

client.task.spam_document({
  "name": "Spammy Domain",
  "domain": "spammy-domain.crisp.help",
  "title": "Spammy title",
  "content": "Spammy content"
});
  • Response:
{
  "reason": "processed",

  "data": {
    "class": "spam",
    "confidence": 0.82,
    "logprob": -0.10,

    "scores": {
      "gibberish": 0.0,
      "marketing": 0.0,
      "regular": 0.0,
      "spam": 0.82
    }
  }
}

Data API

➡️ Context Ingest

client.data.context_ingest({
  "items": [
    {
      "operation": "index",
      "primary_id": "pri_cf44dd72-4ba9-4754-8fb3-83c4261243c4",
      "secondary_id": "sec_6693a4a2-e33f-4cce-ba90-b7b5b0922c46",
      "tertiary_id": "ter_de2bd6e7-74e1-440d-9a23-01964cd4b7da",

      "text": "Text to index here...",
      "source": "chat",
      "timestamp": 1682002198552,

      "metadata": {
        "custom_key": "custom_value",
        "another_key": "another_value"
      }
    }
  ]
});
  • Response:
{
  "reason": "processed",

  "data": {
    "imported": true
  }
}

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

mirage_api-1.7.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

mirage_api-1.7.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file mirage_api-1.7.0.tar.gz.

File metadata

  • Download URL: mirage_api-1.7.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mirage_api-1.7.0.tar.gz
Algorithm Hash digest
SHA256 1c3df30282e4e19772a681ad6b8db98a7c4e43637c605706d19977f12fb3fab6
MD5 cabe7e4d60ad9056e56975403b981cb4
BLAKE2b-256 f7245bde89dc6193295c015a221c59839f763dc4d4076360295fefa1b09bf510

See more details on using hashes here.

File details

Details for the file mirage_api-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: mirage_api-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mirage_api-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbdba5281edebce4e190268c518f856c056a11c24810b718b8c74b7459a72227
MD5 e48144a9f6b28bd5ccd9f1ba18905fa5
BLAKE2b-256 8eefff6a8a6ccbf5ca4e1c05a061c84a05427ac5e77205bca8a1db2289d9fde2

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