User chat manager
POST
/api/v1/Chat/prompt
Prompt
GET
/api/v1/Chat/history
Get All
GET
/api/v1/Chat/chat/{chat_id}
Get Chat
Here are the few issues That I notes on chat page.
1. One thing is when I try to load chats already there, it shows failed to load
screenshot. So for old chat first we can use the api call of /api/v1/Chat/history
, basically get all chats which response looks like,
[
{
"id": "1d48e8ea-1d94-4c77-ab94-a5c72803f450",
"title": "Hi, I am Deep, I want to list the databases",
"tool_id": 1,
"created_at": "2025-06-24T09:21:08.528950"
},
{
"id": "1dd6965a-63fc-4e1c-b30c-8b4438948ac3",
"title": "Hi, I am Deep, I want to list the databases",
"tool_id": 1,
"created_at": "2025-06-24T09:25:46.209330"
},
{
"id": "57bbb3bb-c1aa-4125-a439-8c006185b9cb",
"title": "Hi, I am Deep, I want to list the databases",
"tool_id": 1,
"created_at": "2025-06-24T09:29:16.062862"
},
{
"id": "7e35747f-09f8-4007-bb73-41d285bb7c3a",
"title": "I want to list databases",
"tool_id": 1,
"created_at": "2025-06-24T09:49:51.958100"
},
{
"id": "c8dbe921-6a0d-4581-a6f6-cf8051fb2876",
"title": "Hi, I want to list databases",
"tool_id": 1,
"created_at": "2025-06-24T11:24:05.531446"
},
{
"id": "fa1cb6c8-23c3-465c-9e6c-e02eb207737b",
"title": "Hi I want to count the rows of SC_ADDICATION",
"tool_id": 1,
"created_at": "2025-06-24T11:37:01.878357"
},
{
"id": "f5f102bf-b07d-4c3e-87aa-8777f439068c",
"title": "I want to count the rows of SC_ADDICATION table",
"tool_id": 1,
"created_at": "2025-06-24T11:43:10.458664"
},
{
"id": "7dd24070-365f-4b30-811b-af7fb9662bad",
"title": "Hi",
"tool_id": 1,
"created_at": "2025-06-25T08:48:20.275211"
}
]
This works for the showing the list view of chat but now when user goes to any of
chat it should call this api using its chat id:
GET
/api/v1/Chat/chat/{chat_id}
Get Chat
Response
[
{
"id": 7,
"parent_id": null,
"role": "user",
"content": "Hi, I am Deep, I want to list the databases",
"created_at": "2025-06-24T09:26:17.066156"
},
{
"id": 8,
"parent_id": 7,
"role": "assistant",
"content": "I am sorry, I cannot list the databases. But if you tell me what
you would like to do with the databases, I can try to help.",
"created_at": "2025-06-24T09:26:17.373819"
}
]
Here based on above data in sequence of id we can select role as what's is chat
from user or assistant etc and use content field to show the content that entered
or returned the in the chat.
2. Now lets fix now interacting with assistant using this call
POST
/api/v1/Chat/prompt
Prompt
So now there are two cases :
Case : 1 creating a new chat
So will sending this payload :
{
"chat_id": null,
"prompt": "Hi can you check the count of a table SC_ADDICTION",
"cred_id": 2
}
Response :
{
"chat_id": "8047f1e9-9164-4969-920b-db8175694851",
"response": "I can, but I need to know the database and the schema of the table.
Can you provide them?"
}
Here chat id will keep that as null because first time it will create a chat id at
backend, whatever prompt that user has entered in chat we can keep that in field
prompt, and also important thing is cred_id, as we already integrated the
credentials it should check for currently selected credentials, from there it will
get cred id, now here if it does not have any credentials so it should add alert
that no credentials added please add credentials in connected databases.
After receiving the response we. Get the new chat id created throng that will be
maintaining the history as we discussed in above. And whatever response that we get
from response field in response body we have to show that in chat.
Case : 2 what if we are interacting in already created chat. Then we have to
provide the chat id of its chat. In request today along with the cred id selected.
Same here if no credentials are there it should add alert that no credentials added
please add credentials in connected databases
Request body:
{
"chat_id": "8047f1e9-9164-4969-920b-db8175694851",
"prompt": "Database is TEST and schema is PUBLIC",
"cred_id": 2
}
Response :
{
"chat_id": "8047f1e9-9164-4969-920b-db8175694851",
"response": "The table TEST.PUBLIC.SC_ADDICTION contains 705 rows."
}