Skip to content

[BUG]: API endpoint for workspace chats and thread chats are inconsistent and reversed #2990

@mayzyo

Description

@mayzyo

How are you running AnythingLLM?

Docker (remote)

What happened?

When fetching chat history from api/v1/workspace/slug/chats (so the "default" thread) the array is reversed. Additionally, the order of "assistant" and "user" is reversed on top of the whole array being reversed.

Example api/v1/workspace/slug/chats:
The history displayed in the web UI start with me asking "quick test" and assistant replying "How can I assist you?" which is correct.

[
    {
        "attachments": [],
        "chatId": 417,
        "content": "Give me a brief intr",
        "role": "user",
        "sentAt": 1735077496
    },
    {
        "chatId": 417,
        "content": " I am a text-based A",
        "feedbackScore": null,
        "metrics": {
            "completion_tokens": 163,
            "duration": 18.376,
            "outputTps": 8.870265563778842,
            "prompt_tokens": 5,
            "total_tokens": 168
        },
        "role": "assistant",
        "sentAt": 1735077496,
        "sources": [],
        "type": "chat"
    },
    {
        "attachments": [],
        "chatId": 372,
        "content": "How much water shoul",
        "role": "user",
        "sentAt": 1734609844
    },
    {
        "chatId": 372,
        "content": "The general recommen",
        "feedbackScore": null,
        "metrics": {},
        "role": "assistant",
        "sentAt": 1734609844,
        "sources": [],
        "type": "chat"
    },
    {
        "attachments": [],
        "chatId": 362,
        "content": "quick test",
        "role": "user",
        "sentAt": 1734470476
    },
    {
        "chatId": 362,
        "content": " How can I assist yo",
        "feedbackScore": null,
        "metrics": {},
        "role": "assistant",
        "sentAt": 1734470476,
        "sources": [],
        "type": "chat"
    }
]

Example api/v1/workspace/slug/threads/tslug/chats:
I believe this is endpoint is the correct one.

[
    {
        "attachments": [],
        "chatId": 341,
        "content": "Hi there!",
        "role": "user",
        "sentAt": 1733646403
    },
    {
        "chatId": 341,
        "content": " Hello! How can I as",
        "feedbackScore": null,
        "metrics": {},
        "role": "assistant",
        "sentAt": 1733646403,
        "sources": [],
        "type": "chat"
    },
    {
        "attachments": [],
        "chatId": 342,
        "content": "What do you know abo",
        "role": "user",
        "sentAt": 1733649565
    },
    {
        "chatId": 342,
        "content": " \"Gundam SEED\" is an",
        "feedbackScore": null,
        "metrics": {},
        "role": "assistant",
        "sentAt": 1733649565,
        "sources": [],
        "type": "chat"
    },
    {
        "attachments": [],
        "chatId": 346,
        "content": "Compare seed destiny",
        "role": "user",
        "sentAt": 1733702408
    },
    {
        "chatId": 346,
        "content": "When comparing \"Gund",
        "feedbackScore": null,
        "metrics": {},
        "role": "assistant",
        "sentAt": 1733702408,
        "sources": [],
        "type": "chat"
    }
]

Are there known steps to reproduce?

No response

Metadata

Metadata

Assignees

Labels

investigatingCore team or maintainer will or is currently looking into this issuepossible bugBug was reported but is not confirmed or is unable to be replicated.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions