Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Error Creating New Thread with userId in Workspace API #2272

Closed
MrSimonC opened this issue Sep 12, 2024 · 4 comments · Fixed by #2276
Closed

[BUG]: Error Creating New Thread with userId in Workspace API #2272

MrSimonC opened this issue Sep 12, 2024 · 4 comments · Fixed by #2276
Labels
possible bug Bug was reported but is not confirmed or is unable to be replicated.

Comments

@MrSimonC
Copy link
Contributor

How are you running AnythingLLM?

Docker (local)

What happened?

(Sorry - no pull request from me this time - it's too in depth 😄 )
When attempting to create a new thread in a workspace using the API and providing a userId, an error occurs. This issue can be reproduced using the provided code or directly in the Swagger UI.

Environment:

  • Running AnythingLLM in Docker
  • Version: 1.2.2 (also tested in 1.2.1)
  • Tested on Windows WSL2 Docker and Ubuntu in GitHub Codespaces

Are there known steps to reproduce?

  1. Run AnythingLLM in Docker:

    export STORAGE_LOCATION=$HOME/anythingllm && \
    mkdir -p $STORAGE_LOCATION && \
    touch "$STORAGE_LOCATION/.env" && \
    docker run -d -p 3001:3001 \
    --cap-add SYS_ADMIN \
    -v ${STORAGE_LOCATION}:/app/server/storage \
    -v ${STORAGE_LOCATION}/.env:/app/server/.env \
    -e STORAGE_DIR="/app/server/storage" \
    --restart always \
    mintplexlabs/anythingllm:1.2.2
  2. Fill in a new AI provider.

  3. Generate a new API key (e.g., <MY_API_KEY>).

HTTP REST Example:

POST http://localhost:3001/api/v1/workspace/my-workspace-slug/thread/new
Authorization: Bearer <MY_API_KEY>
Content-Type: application/json

{
  "userId": 1
}

CURL Example:

curl -X 'POST' \
  'http://127.0.0.1:3001/api/v1/workspace/my-workspace-slug/thread/new' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <MY_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
  "userId": 1
}'

Result:
The API responds with:

HTTP/1.1 200 OK
X-Powered-By: Express
Vary: Origin
Content-Type: application/json; charset=utf-8
Content-Length: 148
ETag: W/"94-Y14XDftRy07iOWO+P2NlTX+rhlw"
Date: Thu, 12 Sep 2024 16:06:54 GMT
Connection: keep-alive
keep-alive: timeout=5

{
  "thread": null,
  "message": "\nInvalid `prisma.workspace_threads.create()` invocation:\n\n\nForeign key constraint failed on the field: `foreign key`"
}

Expected Behavior:
The thread should be created successfully when a valid userId is provided.

@MrSimonC MrSimonC added the possible bug Bug was reported but is not confirmed or is unable to be replicated. label Sep 12, 2024
@ImaginePilot
Copy link

same here, I just don't have a clue why only creating new threads have this problem

@timothycarambat
Copy link
Member

Are you in multi-user mode?

@timothycarambat
Copy link
Member

timothycarambat commented Sep 12, 2024

This seems to be the issue.

I am not sure if this is the intention, but this endpoint is more for "UI automation" or management of the threads also visible in the UI. We recently introduced the sessionId key on workspace/(chat or stream-chat) endpoint that you can now use some external identifier per request and keep chat history per call without making threads or polluting the UI with threads/chats for any specific user.

sessionId: "identifier-to-partition-chats-by-external-id"

@MrSimonC
Copy link
Contributor Author

Thanks @timothycarambat it was a bit of both - but ultimately the sessionId (which I've tested - and works great) will be the winner for my + other's use cases. Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Bug was reported but is not confirmed or is unable to be replicated.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants