Skip to content

Askrobot-io/quepasa-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quepasa

API for RAG retrieval, managing documents, files, and related operations including Telegram integration.

This Python package is automatically generated by the OpenAPI Generator project:

  • API version: 0.0.1
  • Package version: 1.0.0
  • Generator version: 7.8.0
  • Build package: org.openapitools.codegen.languages.PythonClientCodegen

Requirements.

Python 3.7+

Installation & Usage

pip install

If the python package is hosted on a repository, you can install directly using:

pip install quepasa

(you may need to run pip with root permission: sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git)

Then import the package:

import quepasa

Getting Started

Please follow the installation procedure and then run the following:

import os
import time
from pprint import pprint

import quepasa
from quepasa.rest import ApiException

# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure Bearer authorization (Opaque): bearerAuth
configuration = quepasa.Configuration(
    access_token = os.environ["BEARER_TOKEN"]
)


# Enter a context with an instance of the API client
with quepasa.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    client = quepasa.DefaultApi(api_client)

    domain = "default" # The name of a group of documents. Defaults to "default".
    doc_id = "llm"

    documents = [
        {
            # Required fields
            'id': doc_id, # string
            'url': "https://en.wikipedia.org/wiki/Large_language_model",

            'title': "Large language model",
            'language': "en", # two-char language code in lowercase
            'text': """
A large language model (LLM) is a computational model capable of language generation or other natural language processing tasks. As language models, LLMs acquire these abilities by learning statistical relationships from vast amounts of text during a self-supervised and semi-supervised training process.

The largest and most capable LLMs, as of August 2024, are artificial neural networks built with a decoder-only transformer-based architecture, which enables efficient processing and generation of large-scale text data. Modern models can be fine-tuned for specific tasks or can be guided by prompt engineering.
These models acquire predictive power regarding syntax, semantics, and ontologies inherent in human language corpora, but they also inherit inaccuracies and biases present in the data they are trained on.

Some notable LLMs are OpenAI's GPT series of models (e.g., GPT-3.5, GPT-4 and GPT-4o; used in ChatGPT and Microsoft Copilot), Google's Gemini (the latter of which is currently used in the chatbot of the same name), Meta's LLaMA family of models, IBM's Granite models initially released with Watsonx, Anthropic's Claude models, and Mistral AI's models.
            """.strip(),
            # 'html': "", # or send text
            # 'markdown': "", # or send markdown

            # Optional fields:
            # - 'keywords': document keywords, string, by default empty
            # - 'created_at': "2024-05-20T07:26:06Z", # document creation datetime, by default datetime of first creation of this document via API
            # - 'updated_at': "2024-05-20T07:26:06Z", # document last update datetime, by default datetime of last update of this document via API
        },
    ]

    # OR


    documents = [
        {
            # Required fields
            'id': doc_id, # string
            'url': "https://en.wikipedia.org/wiki/Large_language_model",

            'title': "Large language model",
            'pages': [
                {
                    'language': "en", # two-char language code in lowercase
                    'text': """
A large language model (LLM) is a computational model capable of language generation or other natural language processing tasks. As language models, LLMs acquire these abilities by learning statistical relationships from vast amounts of text during a self-supervised and semi-supervised training process.
                    """.strip(),
                },
                {
                    'language': "en", # two-char language code in lowercase
                    'text': """
The largest and most capable LLMs, as of August 2024, are artificial neural networks built with a decoder-only transformer-based architecture, which enables efficient processing and generation of large-scale text data. Modern models can be fine-tuned for specific tasks or can be guided by prompt engineering.
These models acquire predictive power regarding syntax, semantics, and ontologies inherent in human language corpora, but they also inherit inaccuracies and biases present in the data they are trained on.
                    """.strip(),
                },
                {
                    'language': "en", # two-char language code in lowercase
                    'text': """
Some notable LLMs are OpenAI's GPT series of models (e.g., GPT-3.5, GPT-4 and GPT-4o; used in ChatGPT and Microsoft Copilot), Google's Gemini (the latter of which is currently used in the chatbot of the same name), Meta's LLaMA family of models, IBM's Granite models initially released with Watsonx, Anthropic's Claude models, and Mistral AI's models.
                    """.strip(),
                },
            ],

            # Optional fields:
            # - 'keywords': document keywords, string, by default empty
            # - 'created_at': "2024-05-20T07:26:06Z", # document creation datetime, by default datetime of first creation of this document via API
            # - 'updated_at': "2024-05-20T07:26:06Z", # document last update datetime, by default datetime of last update of this document via API
        },
    ]

    # Upsert document
    print("The response of client.upsert_documents:")
    response = client.upsert_documents(domain, documents)
    pprint(response)

    batch_id = response.data.batch_id


    # Wait until indexation is finished
    while batch_id != None:
        print("The response of client.get_batch_status:")
        response = client.get_batch_status(batch_id)
        pprint(response)

        time.sleep(10)
        if response.status == 'Batch state: done':
            break


    print("The response of client.retrieve_answer:")
    response = client.retrieve_answer({
        'question': "What is LLM?",
    })
    pprint(response)
    print(response.data.markdown)

Upload file

import os
import time
from pprint import pprint

import quepasa
from quepasa.rest import ApiException


# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure Bearer authorization (Opaque): bearerAuth
configuration = quepasa.Configuration(
    access_token = os.environ["BEARER_TOKEN"]
)


# Enter a context with an instance of the API client
with quepasa.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    client = quepasa.DefaultApi(api_client)

    domain = "default" # The name of a group of documents. Defaults to "default".
    filename = "TimeTravel101ForBeginners.pdf"

    # Upload file
    print("The response of client.upsert_files:")
    response = client.upsert_files(domain, filename)
    pprint(response)

    batch_id = response.data.batch_id


    # Wait until indexation is finished
    while batch_id != None:
        print("The response of client.get_batch_status:")
        response = client.get_batch_status(batch_id)
        pprint(response)

        time.sleep(10)
        if response.status == 'Batch state: done':
            break


    print("The response of client.retrieve_answer:")
    response = client.retrieve_answer({
        'question': "Can I un-eat yesterday burrito?",
    })
    pprint(response)
    print(response.data.markdown)

Documentation for API Endpoints

All URIs are relative to https://api.quepasa.ai/api/v1

Class Method HTTP request Description
DefaultApi upsert_files POST /upload/data/files/{domain} Upsert files
DefaultApi upsert_documents POST /upload/data/documents/{domain} Upsert documents
DefaultApi replace_documents PUT /upload/data/documents/{domain} Replace documents
DefaultApi get_batch_status GET /upload/data/batches/{id} Get batch status
DefaultApi get_document GET /upload/data/documents/{domain}/{id} Get document details
DefaultApi list_all_documents GET /upload/data/documents List all documents
DefaultApi list_documents GET /upload/data/documents/{domain} List documents
DefaultApi remove_document DELETE /upload/data/documents/{domain}/{id} Remove document
DefaultApi remove_domain DELETE /upload/data/documents/{domain} Remove domain
DefaultApi retrieve_answer POST /retrieve/answer Retrieve answers
DefaultApi retrieve_chunks POST /retrieve/chunks Retrieve search results
DefaultApi setup_telegram PATCH /upload/data/telegram Setup Telegram integration

Documentation For Models

Documentation For Authorization

Authentication schemes defined for the API:

bearerAuth

  • Type: Bearer authentication (Opaque)

Development

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import quepasa

Tests

Execute pytest to run the tests.

Author

QuePasa.ai

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published