Chat API - answerrocket/answerrocket-python-client GitHub Wiki

Overview

The Chat module can create and interact with chat threads on the Max app. Chat threads are tied to a particular user and copilot. It is important to note that the actions you perform on chat threads using the API will also be reflected in the UI when you open the application (e.g. if you create a new thread with the API, that new thread will also show up under your user for whichever copilot you specified in the Max web app)

Methods

get_threads(copilot_id, start_date (optional), end_date (optional))

get_entries(thread_id, offset_index (optional), limit (optional))

ask_question(copilot_id, question, thread_id (optional), skip_report_cache (optional), dry_run_type (optional), model_overrides (optional), indicated_skills (optional), history (optional))

evaluate_entry(entry_id, evals) Runs and fetches the evaluation suite for a given entry. Takes as input an entry id and a list of strings containing the names of which evaluations to run.

Returns a EvaluateChatQuestionResponse object with schema:

  • success: a Boolean representing whether the evaluation was successfully updated in MongoDB

  • eval_results: a list of EvaluateChatQuestionResult objects, each with schema:

    • eval_type: a String containing the name of the evaluation ran
    • pass: a Boolean representing whether the given entry passed or failed the evaluation
    • explanation: a String explanation of why the given entry passed or failed the evaluation
    • correct_function: a String denoting the "expected" skill/function that should have been chosen in the given entry... as determined by the LLM running the evaluation

completion(model_type: ModelType = 'COMPLETION', stream_callback: Optional[Callable] = None, **kwargs) -- wrapper for the OpenAI chat completion API

get_chat_entry(entry_id: str) -> MaxChatEntry accepts as input a chat entry ID and returns a MaxChatEntry object

get_chat_thread(thread_id: str) -> MaxChatThread accepts as input a thread ID and returns a MaxChatThread object

create_new_thread(copilot_id: str) -> MaxChatThread accepts as input a copilot ID, creates a thread under the given copilot, and returns the MaxChatThread object representing the created thread.

queue_chat_question(question: str, thread_id: str, skip_cache: bool = False, model_overrides: dict = None, indicated_skills: list[str] = None, history: list[dict] = None) -> MaxChatEntry This queues up a question for processing. Unlike ask_question, this will not wait for the processing to complete. It will immediately return a shell entry with an id you can use to query for the results.

cancel_chat_question(entry_id: str) -> MaxChatEntry This deletes the entry from its thread and attempts to abandon the question's processing if it is still ongoing.

get_user(user_id: str) -> MaxChatUser This fetches a user by their ID. Admin or User Management permissions required.

get_all_chat_entries(offset: int, limit: int, filters=dict) -> list[MaxChatEntry] Fetches all entries in the system for the specified range and filters. offset: an integer >= 0 that specifies the start index of the search (default = 0) limit: an integer >= 1 that specifies the number of entries to pull at once (default = 100) filters: a dictionary representing the filters to apply to the search.

        Example Filter after a date:

        {
            "askedDate": {
              "dateFrom": "2024-10-25 00:00:00",
              "dateTo": None,
              "filterType": "date",
              "type": "askedAfter"
            }
        }

        Other available fields:

        {
            "askedDate": {
              "dateFrom": "2024-10-25 00:00:00",
              "dateTo": "2025-10-26 00:00:00",
              "filterType": "date",
              "type": "askedBetween"
            },
            "questionType": {
              "values": [
                "Test Runs",
                "User Written"
              ],
              "filterType": "set"
            },
            "username": {
              "values": ["someusername"],
              "filterType": "set"
            },
            "lastName": {
              "values": ["somelastname"],
              "filterType": "set"
            },
            "firstName": {
              "values": ["somefirstname"],
              "filterType": "set"
            },
            "copilot": {
              "values": [
                "My Copilot"
              ],
              "filterType": "set"
            },
            "copilotSkillName": {
              "values": [
                "Dimension Breakout",
                "globals test",
                "Document Explorer",
                "Trend Analysis"
              ],
              "filterType": "set"
            },
            "type": {
              "values": [
                "Positive"
              ],
              "filterType": "set"
            },
            "feedbackReviewed": {
              "values": [
                "Seen"
              ],
              "filterType": "set"
            },
            "adminFeedback": {
              "values": [
                "Negative"
              ],
              "filterType": "set"
            },
            "status": {
              "values": [
                "error",
                "completed",
                "canceled",
                "processing"
              ],
              "filterType": "set"
            }
          }

Examples


# Init AnswerRocket Client
arc = AnswerRocketClient(url='https://your-answerrocket-instance.com', token='<your_api_token>')

# get all the threads for the specified copilot
arc.chat.get_threads('<your_copilot_uuid>')

# get all the entries for the first thread in the list
entries = arc.chat.get_entries(threads[0].get('_id'))

# ask a question (create a new thread)
response_a = arc.chat.ask_question('<your_copilot_uuid>', 'What is the total sales for 2022?')

# ask a followup question using the thread created from the first question
response_b = arc.chat.ask_question('<your_copilot_uuid>', 'Now for 2021?', response_a.get('threadId'))

Dry Runs and Cache Skipping


# If you want to skip the cache (and thus get a fresh answer), use the skip_report_cache field
fresh_answer = arc.chat.ask_question('<your_copilot_uuid>', 'Sales for 2021?', response_a.get('threadId'), skip_report_cache=True)

# You can have the system determine the right skills to run, but skip actually running them using SKIP_SKILL_EXEC
dry_run = arc.chat.ask_question('<your_copilot_uuid>', 'Sales for 2021?', response_a.get('threadId'), dry_run_type='SKIP_SKILL_EXEC')

# Alternatively, you can have the system run skills but skip the final natural language generation using SKIP_SKILL_NLG
no_nlg = arc.chat.ask_question('<your_copilot_uuid>', 'Sales for 2021?', response_a.get('threadId'), dry_run_type='SKIP_SKILL_NLG')