langchain-ai / opengpts

MIT License
6.3k stars 827 forks source link

It always returns "Thread not found" by API #316

Closed box9527 closed 2 months ago

box9527 commented 2 months ago

Hi, there, Sorry to bother you. I am confuse about conversation with OpenGpts backend via APIs, because I am not lucky with successfully get results from most of them. Even the example code from API.md.

I can make a successful call with following api but that's all:

async def get_assistant(assistant_id: str) -> Optional[Config]:
    try:
        response = requests.get(
                f"{get_settings().opengpts_bk_uri}/assistants/{assistant_id}",
                headers=api_headers,
        )
        if not response.ok:
            return None
        return Config(**response.json())
    except Exception as error:
        print("Failed to fetch assistant:", error)
        return None

import asyncio
resp = asyncio.run(get_assistant_info(assistant_id))
print(resp.config)

If I try to get the list of assistants, it return an empty array:

curl -XGET  http://backend:8000/assistants/

[]

If I try to get the information of a thread, it always turns "Thread not found":

import requests
requests.get(
    'http://127.0.0.1:8100/threads/231dc7f3-33ee-4040-98fe-27f6e2aa8b2b/state', 
    cookies= {"opengpts_user_id": "foo"}
).content

b'{"detail":"Thread not found"}'

curl -XGET  http://backend:8000/threads/23a56cc0-b6a9-41b1-8188-f78de0631713
{"detail":"Thread not found"}

I am pretty sure I have these records in the PostgresSQL storage:

              thread_id               |             assistant_id             |               user_id                |                        name                        |          updated_at
--------------------------------------+--------------------------------------+--------------------------------------+----------------------------------------------------+-------------------------------
 452a2d13-9daa-4c42-9e68-9ecac4be88d1 | cda01f4b-323d-4fb1-8b7f-7f5936b7b06f | bcd9bd62-0868-49da-b568-a9567afae57d |  test-1 | 2024-04-18 07:21:54.101534+00
 988498d0-8d58-4c0a-bd9c-09662cb71ed7 | cda01f4b-323d-4fb1-8b7f-7f5936b7b06f | bcd9bd62-0868-49da-b568-a9567afae57d |  test-2                                       | 2024-04-18 08:23:57.964683+00
 23a56cc0-b6a9-41b1-8188-f78de0631713 | 3c87d178-19da-4dec-9957-2868a05c8d23 | bcd9bd62-0868-49da-b568-a9567afae57d | test-3                                           | 2024-04-18 09:25:36.289734+00
 5fe5655d-c6cd-45e6-9dac-8f7ea175fe0a | b11d8c1e-9cf6-4ed3-bba2-b8f986c08732 | bcd9bd62-0868-49da-b568-a9567afae57d | test-4                                             | 2024-04-18 11:03:07.664755+00

How can I make it smoothly? Any help are welcome, thank you.