module documentation

Undocumented

Function get_attributes # GET `/api/attributes/<attribute_name>`
Function get_catalog # GET `/api/catalog`
Function get_docs # GET `/api/docs`
Function get_document_by_name # GET `/api/document/<name>`
Function get_notes_for_post # GET `/api/notes/<post_title>`
Function post_attribute # POST `/api/attribute`
Function post_auth_wrapper A decorator to each POST endpoints. Calls the post_auth_check to checks wheter or not the request is authenticated.
Function post_comment # POST `/api/note`
Function post_compile_attribute # POST `/api/compile/attribute`
Function post_compile_catalog # POST `/api/compile/catalog`
Function post_post # POST `/api/document`
Function stream # POST `/api/query`
Function stream_auth_wrapper A decorator to each the 'api/stream' endpoint. Calls the stream_auth_check to checks wheter or not the request is authenticated.
Variable post_auth_check A method variable called before each POST request. It must return a bool that indicates wether or not the request can be made. By default always returns `False` unless `allow_post` is set to `True` in the `qA_Ap...
Variable server A Bottle server instance. It is accessible as `qA_Ap.server`.
Variable stream_auth_check A method variable called before each `api/stream` endpoint request. It must return a bool that indicates wether or not the request can be made. By default always returns `True`. Redefine this variable to implement your stream endpoint authentication...
@server.get('/api/attributes/<attribute_name>')
def get_attributes(attribute_name: str) -> str:

# GET `/api/attributes/<attribute_name>` Returns all existing values for the specified attribute as JSON. ## 200 response: ```json [ "attribute1", "attribute2", ... ] ``` ## Error response: ```json {"error": "<error message>"} ```

@server.get('/api/catalog')
def get_catalog() -> str:

# GET `/api/catalog` Returns the catalog as JSON. The catalog is a list of all documents with their metadata and a short excerpt. ## 200 response: ```json [ { "title": "Document Title", "metadata": { "links": ["link1", "link2"], "attributes": ["attribute1", "attribute2"], }, "excerpt": "This is a short excerpt of the document..." }, ... ] ```

@server.get('/api/docs')
def get_docs() -> str:

# GET `/api/docs`

Returns the api documentation generated with [**pDoc**](https://pdoc.dev/).

@server.get('/api/document/<name>')
def get_document_by_name(name: str) -> str:

# GET `/api/document/<name>` Returns a document by name. Returns an error message if the document is not found or if an error occurs. ## 200 response: ```json { "title": "Document Title", "content": "Full content of the document...", "metadata": { "links": ["link1", "link2"], "attributes": ["attribute1", "attribute2"], } } ``` ## Error response: ```json {"error": "<error message>"} ```

@server.get('/api/notes/<post_title>')
def get_notes_for_post(post_title: str) -> str:

# GET `/api/notes/<post_title>` Returns all notes for a document as JSON. ## 200 response: ```json [ { "note_title": "User1", "content": "Note content...", "metadata": { "rating": 5, } }, ... ] ``` ## Error response: ```json {"error": "<error message>"} ```

@server.post('/api/attribute')
@post_auth_wrapper
def post_attribute() -> str:

# POST `/api/attribute` Registers new attribute values. All the attribute values already existing are ignored. If the attribute type does not exist, it is created with the new values. ## Request body: ```json { "attribute": str, // the attribute name "values": list[str] } ``` ## 200 response: ```json { "success": true, "message": "attribute '<attribute>' registered" } ``` ## Error response: ```json {"error": "<error message>"} ```

def post_auth_wrapper(func):

A decorator to each POST endpoints. Calls the post_auth_check to checks wheter or not the request is authenticated.

@server.post('/api/note')
@post_auth_wrapper
def post_comment() -> str:

# POST `/api/note` Registers a new note. ## Request body: ```json { "post_title": "Document Title", "note_title": "User1", "content": <yaml str> | <str> "medias": <list[str]>, "metadata": <dict[str,str]>" } ``` ## 200 response: ```json { "success": true, "message": "<note_title> commented on the document <post_title>" } ``` ## Error response: ```json {"error": "<error message>"} ```

@server.post('/api/compile/attribute')
@post_auth_wrapper
def post_compile_attribute() -> str:

# POST `/api/compile/attribute` Triggers a rebuild of an attribute values list from the catalog. ## Request body: ```json { "attributes": <list[str]> } ``` ## 200 response: ```json { "success": true, "message": "Catalog compiled successfully" } ``` ## Error response: ```json {"error": "<error message>"} ```

@server.post('/api/compile/catalog')
@post_auth_wrapper
def post_compile_catalog() -> str:

# POST `/api/compile/catalog` Triggers a rebuild of the catalog from all documents. ## 200 response: ```json { "success": true, "message": "Catalog compiled successfully" } ``` ## Error response: ```json {"error": "<error message>"} ```

@server.post('/api/document')
@post_auth_wrapper
def post_post() -> str:

# POST `/api/document` Registers a new document. ## Request body: ```json { "title": <str>, "medias": <list[str]>, "content": <yaml str> | <str> "metadata": <dict[str,str]> } ``` If no `metadata` field is given the document content can be in YAML format with optional metadata prefixed. ## Document content example with metadata: ```yaml medias: - image1.png - image2.png tags: - tag1 - tag2 ### This is the text content of the document. ``` If the `metadata` field is given, the yaml formatted fields are prefixed to the content automatically. ## 200 response: ```json { "success": true, "message": "The document <post_title> is created" } ``` ## Error response: ```json {"error": "<error message>"} ```

@server.post('/api/query')
@stream_auth_wrapper
def stream():

# POST `/api/query` Streams a response from the LLM for a given prompt. The history is a list of entry containing the role and content of messages. Example: ```json [ { "role": "user", "content": "Why is the sky blue?" }, { "role": "assistant", "content": "The sky is blue because of the way the Earth's atmosphere scatters sunlight." }, ... ] ``` ## Request body: ```json { "prompt": <str>, "history": <list[dict[str,str]]> (default None) "metadata": <bool> (default: true) // whether to include retrieved documents metadata in the response } ``` ## Streamed response: ``` <LLM response chunks> ```

def stream_auth_wrapper(func):

A decorator to each the 'api/stream' endpoint. Calls the stream_auth_check to checks wheter or not the request is authenticated.

post_auth_check =

A method variable called before each POST request. It must return a bool that indicates wether or not the request can be made. By default always returns `False` unless `allow_post` is set to `True` in the `qA_Ap.init()` method. Redefine this variable to implement your authentication. ```qA_Ap.server.post_auth_check = your_method```

server =

A Bottle server instance. It is accessible as `qA_Ap.server`.

stream_auth_check =

A method variable called before each `api/stream` endpoint request. It must return a bool that indicates wether or not the request can be made. By default always returns `True`. Redefine this variable to implement your stream endpoint authentication. ```qA_Ap.server.stream_auth_check = your_method```