User interface - statnett/Talk2PowerSystem GitHub Wiki

Initial requirements

Features:

  1. Users can ask questions and get responses from the chat bot. Consecutive questions can be asked meaning the chat bot has memory.
  2. List of sample questions in the front end - Users are provided with sample questions for the chat bot
  3. Support these buttons (explained left to right):
unnamed
  • Re-send a question - sends the last user question to the chat bot again
  • Copy answer to the clipboard
  • Cost - show the number of consumed tokens
  • Explain - show the SPARQL query, and any other tools with their arguments that were used
  • Open the SPARQL query in GraphDB Workbench editor
  • Copy query to clipboard
  1. Sample conversation view
unnamed (1)

Limitations:

  1. No new agents are created from the UI. There is only one existing agent, which can’t be modified or deleted from the UI. The agent instructions and configuration is also not visible in the UI.
  2. While there is memory, there is no full history for the chats, i.e. the chats and all of their messages are not persisted. When a user starts a new chat, upon refresh of the browser - the chat is gone.
  3. Inactive conversations for a configurable time period (by default 1 hour) are deleted.

REST API

POST /rest/chat/conversations

Starts a new conversation or adds message to an existing conversation

Request Headers:

  • X-Request-Id - version 4 UUID, which can be used to correlate HTTP requests between clients, services and service dependencies; optional, if not provided, it will be automatically generated and returned as a response header
  • Content-Type: "application/json"
  • Accept: "application/json"

Response Headers:

  • X-Request-Id - Same as the Request Header "X-Request-Id"; auto generated version 4 UUID, if the request didn't include it
  • Content-Type: "application/json"

Request Body JSON Schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "conversationId": {
      "type": "string"
    },
    "question": {
      "type": "string"
    }
  },
  "required": [
    "question"
  ]
}

Sample Request Bodies:

  • New conversation
{
  "question": "List all transformers within substation OSLO."
}
  • Adding messages to existing conversation
{
 "conversationId": "thread_x8PTAw42sC3Mzl7vr6JP8ZMa",
 "question": "List all transformers within substation OSLO."
}

Response Body JSON Schema:

{
 "$schema": "http://json-schema.org/draft-04/schema#",
 "type": "object",
 "properties": {
   "id": {
     "type": "string"
   },
   "messages": {
     "type": "array",
     "items": [
       {
         "type": "object",
         "properties": {
           "id": {
             "type": "string"
           },
           "message": {
             "type": "string"
           },
           "usage": {
             "type": "object",
             "properties": {
               "completionTokens": {
                 "type": "integer"
               },
               "promptTokens": {
                 "type": "integer"
               },
               "totalTokens": {
                 "type": "integer"
               }
             },
             "required": [
               "completionTokens",
               "promptTokens",
               "totalTokens"
             ]
           }
         },
         "required": [
           "id",
           "message",
           "usage"
         ]
       }
     ]
   },
   "usage": {
     "type": "object",
     "properties": {
       "completionTokens": {
         "type": "integer"
       },
       "promptTokens": {
         "type": "integer"
       },
       "totalTokens": {
         "type": "integer"
       }
     },
     "required": [
       "completionTokens",
       "promptTokens",
       "totalTokens"
     ]
   }
 },
 "required": [
   "id",
   "messages",
   "usage"
 ]
}

Sample Response Body:

{
    "id": "thread_x8PTAw42sC3Mzl7vr6JP8ZMa",
    "messages": [
        {
            "id": "msg_sObdXPBa0RBtvwl2BR6hUVd9",
            "message": "The following transformers are within substation OSLO:\n\n1. OSLO T1\n2. OSLO T2\n\nLet me know if you need more details about these transformers.",
            "usage": {
                "completionTokens": 38,
                "promptTokens": 57322,
                "totalTokens": 57360
            }
        }
    ],
    "usage": {
        "completionTokens": 38,
        "promptTokens": 57322,
        "totalTokens": 57360
    }
}

Response Status Codes:

  • 200 - Successful Response
  • 400 - Conversation not found
  • 422 - Validation Error

POST /rest/chat/conversations/explain/

For a given message in a conversation returns the tools calls made by the AI agent

Request Headers:

  • X-Request-Id - version 4 UUID, which can be used to correlate HTTP requests between clients, services and service dependencies; optional, if not provided, it will be automatically generated and returned as a response header
  • Content-Type: "application/json"
  • Accept: "application/json"

Response Headers:

  • X-Request-Id - Same as the Request Header "X-Request-Id"; auto generated version 4 UUID, if the request didn't include it
  • Content-Type: "application/json"

Request Body JSON Schema

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "conversationId": {
      "type": "string"
    },
    "messageId": {
      "type": "string"
    }
  },
  "required": [
    "conversationId",
    "messageId"
  ]
}

Sample Request Body

{
    "conversationId": "thread_x8PTAw42sC3Mzl7vr6JP8ZMa",
    "messageId": "msg_sObdXPBa0RBtvwl2BR6hUVd9"
}

Response Body JSON Schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "conversationId": {
            "type": "string"
        },
        "messageId": {
            "type": "string"
        },
        "queryMethods": {
            "type": "array",
            "items": [
                {
                    "type": "object",
                    "properties": {
                        "name": {
                            "type": "string"
                        },
                        "args": {
                            "type": "object"
                        },
                        "query": {
                            "type": "string",
                            "description": "Present only if the queryType is present."
                        },
                        "queryType": {
                            "enum": [
                                "sparql"
                            ]
                        },
                        "errorOutput": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "name",
                        "args"
                    ]
                }
            ]
        }
    },
    "required": [
        "conversationId",
        "messageId",
        "queryMethods"
    ]
}

Sample Response Body

{
    "conversationId": "thread_x8PTAw42sC3Mzl7vr6JP8ZMa",
    "messageId": "msg_sObdXPBa0RBtvwl2BR6hUVd9",
    "queryMethods": [
        {
            "name": "autocomplete_search",
            "args": {
                "query": "OSLO",
                "result_class": "cim:Substation"
            },
            "query": "\nPREFIX sesame: <http://www.openrdf.org/schema/sesame#>\nPREFIX rank: <http://www.ontotext.com/owlim/RDFRank#>\nPREFIX auto: <http://www.ontotext.com/plugins/autocomplete#>\nSELECT ?iri ?name ?class ?rank {\n    ?iri auto:query \"OSLO\" ;\n        <https://cim.ucaiug.io/ns#IdentifiedObject.name> | <https://cim.ucaiug.io/ns#IdentifiedObject.aliasName> | <https://cim.ucaiug.io/ns#CoordinateSystem.crsUrn> ?name ;\n        a cim:Substation ;\n        sesame:directType ?class;\n        rank:hasRDFRank5 ?rank.\n}\nORDER BY DESC(?rank)\nLIMIT 10",
            "queryType": "sparql"
        },
        {
            "name": "sparql_query",
            "args": {
                "query": "SELECT ?class WHERE { <urn:uri:1234> a ?class }"
            },
            "errorOutput": "Error: ValueError('The following IRIs are not used in the data stored in GraphDB: <urn:uri:1234>') Please fix your mistakes."
        },
        {
            "name": "sparql_query",
            "args": {
                "query": "\nSELECT ?transformer ?name WHERE {\n  ?transformer a cim:PowerTransformer .\n  ?transformer cim:Equipment.EquipmentContainer <urn:uuid:f176963c-9aeb-11e5-91da-b8763fd99c5f> .\n  OPTIONAL { ?transformer cim:IdentifiedObject.name ?name }\n} ORDER BY ?name"
            },
            "query": "\nPREFIX cim: <https://cim.ucaiug.io/ns#>\nSELECT ?transformer ?name WHERE {\n  ?transformer a cim:PowerTransformer .\n  ?transformer cim:Equipment.EquipmentContainer <urn:uuid:f176963c-9aeb-11e5-91da-b8763fd99c5f> .\n  OPTIONAL { ?transformer cim:IdentifiedObject.name ?name }\n} ORDER BY ?name",
            "queryType": "sparql"
        },
        {
            "name": "retrieve_data_points",
            "args": {
                "external_id": "9bb00faf-0f2f-831a-e040-1e828c94e833_estimated_value",
                "aggregates": [
                    "average",
                    "count"
                ],
                "granularity": "2days"
            }
        }
    ]
}

Response Status Codes:

  • 200 - Successful Response
  • 400 - Conversation or message not found
  • 422 - Validation error

Troubleshooting endpoints

GET /__health

Returns the health status of the application

Request Headers:

  • X-Request-Id - version 4 UUID, which can be used to correlate HTTP requests between clients, services and service dependencies; optional, if not provided, it will be automatically generated and returned as a response header
  • Accept: "application/json"

Response Headers:

  • X-Request-Id - Same as the Request Header "X-Request-Id"; auto generated version 4 UUID, if the request didn't include it
  • Content-Type: "application/json"

Response Body JSON Schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "status": {
            "type": "string"
        },
        "healthChecks": {
            "type": "array",
            "items": [
                {
                    "type": "object",
                    "properties": {
                        "status": {
                            "type": "string"
                        },
                        "severity": {
                            "type": "string"
                        },
                        "id": {
                            "type": "string"
                        },
                        "name": {
                            "type": "string"
                        },
                        "type": {
                            "type": "string"
                        },
                        "impact": {
                            "type": "string"
                        },
                        "troubleshooting": {
                            "type": "string"
                        },
                        "description": {
                            "type": "string"
                        },
                        "message": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "status",
                        "severity",
                        "id",
                        "name",
                        "type",
                        "impact",
                        "troubleshooting",
                        "description",
                        "message"
                    ]
                }
            ]
        }
    },
    "required": [
        "status",
        "healthChecks"
    ]
}

Sample Response Body:

{
    "status": "OK",
    "healthChecks": [
        {
            "status": "OK",
            "severity": "HIGH",
            "id": "http://talk2powersystem.no/talk2powersystem-api/redis-healthcheck",
            "name": "Redis Health Check",
            "type": "redis",
            "impact": "Redis is inaccessible and the chat bot can't function",
            "troubleshooting": "http://localhost:8000/__trouble#redis-health-check-status-is-not-ok",
            "description": "Checks if Redis can be queried.",
            "message": "Redis can be queried."
        },
        {
            "status": "OK",
            "severity": "HIGH",
            "id": "http://talk2powersystem.no/talk2powersystem-api/cognite-healthcheck",
            "name": "Cognite Health Check",
            "type": "cognite",
            "impact": "Chat bot won't be able to query Cognite or tools may not function as expected.",
            "troubleshooting": "http://localhost:8000/__trouble#cognite-health-check-status-is-not-ok",
            "description": "Checks if Cognite can be queried by listing the time series with limit of 1.",
            "message": "Cognite can be queried."
        },
        {
            "status": "OK",
            "severity": "HIGH",
            "id": "http://talk2powersystem.no/talk2powersystem-api/graphdb-healthcheck",
            "name": "GraphDB Health Check",
            "type": "graphdb",
            "impact": "Chat bot won't be able to query GraphDB or tools may not function as expected.",
            "troubleshooting": "http://localhost:8000/__trouble#graphdb-health-check-status-is-not-ok",
            "description": "Checks if GraphDB repository can be queried. Also checks that the autocomplete is enabled, and RDF rank is computed.",
            "message": "GraphDB repository can be queried and it's configured correctly."
        }
    ]
}

Response Status Codes:

  • 200 - Successful Response

GET /__gtg

Returns if the service is good to go

Request Headers:

  • X-Request-Id - version 4 UUID, which can be used to correlate HTTP requests between clients, services and service dependencies; optional, if not provided, it will be automatically generated and returned as a response header
  • Accept: "application/json"

Query Parameters:

  • cache (boolean, defaults to `true`) - whether to return the last cached value or force a new check of the system health and refresh the cache

Response Headers:

  • X-Request-Id - Same as the Request Header "X-Request-Id"; auto generated version 4 UUID, if the request didn't include it
  • Content-Type: "application/json"

Response Status Codes:

  • 200 - The service is good to go
  • 503 - The service is unavailable

Response Body JSON Schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "gtg": {
      "type": "string"
    }
  },
  "required": [
    "gtg"
  ]
}

Sample Response Body:

{
  "gtg": "OK"
}

GET /__about

Describes the application and provides build info about the component

Request Headers:

  • X-Request-Id - version 4 UUID, which can be used to correlate HTTP requests between clients, services and service dependencies; optional, if not provided, it will be automatically generated and returned as a response header
  • Accept: "application/json"

Response Headers:

  • X-Request-Id - Same as the Request Header "X-Request-Id"; auto generated version 4 UUID, if the request didn't include it
  • Content-Type: "application/json"

Sample Response Body

{
  "description": "Talk2PowerSystem Chat Bot Application provides functionality for chatting with the Talk2PowerSystem Chat bot",
  "version": "0.0.0a0",
  "buildDate": "2024-01-09T13:31:49Z",
  "buildBranch": "COOL-BRANCH-NAME",
  "gitSHA": "a730751ac055a4f2dad3dc3e5658bb1bf30ff412",
  "pythonVersion": "3.12.11",
  "systemVersion": "3.12.11 | packaged by conda-forge | (main, Jun  4 2025, 14:45:31) [GCC 13.3.0]",
  "fastApiVersion": "0.115.14",
  "uvicornVersion": "0.35.0"
}

Response Status Codes:

  • 200 - Successful Response

GET /__trouble

Returns an html rendering of the trouble document for the application

Request Headers:

  • X-Request-Id - version 4 UUID, which can be used to correlate HTTP requests between clients, services and service dependencies; optional, if not provided, it will be automatically generated and returned as a response header
  • Accept: "text/html"

Response Headers:

  • X-Request-Id - Same as the Request Header "X-Request-Id"; auto generated version 4 UUID, if the request didn't include it
  • Content-Type: "text/html"

Response Status Codes:

  • 200 - Successful Response

Backend Application

  • The application is implemented in Python and Fast API. It's served with the uvicorn server.
  • A docker image is also provided.
  • The chat bot memory is persisted in Redis.

Web Application

  • The application is implemented using AngularJS. The web pages are served as static content using Nginx web server.
  • The application is released as Docker image and it has Helm chart for easier deployment on Kubernetes environment(s).
  • The source code repository is Talk2PowerSystem_UI.
⚠️ **GitHub.com Fallback** ⚠️