Open Technologicat opened 2 months ago
Specifically related to Python chat example:
Someone posted in April 2024 on Reddit: OpenAI API chat with character examples no longer works. However, that fix has already been pushed.
But I figured it out - the problem was that the chosen AI character must exist. Changing "character": "Example"
to "character": "Assistant"
, the Python chat example works. I think this should be mentioned in the docs.
EDIT: And actually, the server did print this in its console:
12:39:33-097268 ERROR Could not find the character "Example" inside characters/. No character has been loaded.
I suppose I should keep that window visible on a separate screen when testing things like this. :)
And specifically related to Python chat example with streaming:
It seems the "message"
field has been renamed to "delta"
. Makes sense given how it's used.
So to fix this example, change the line
chunk = payload['choices'][0]['message']['content']
to
chunk = payload['choices'][0]['delta']['content']
Describe the bug
The Python examples in the wiki docs are out of date, and crash with various errors.
For example:
500
error from the server.KeyError
, payload does not have key"message"
.Note that my
text-generation-webui
installation itself works fine, including the API - SillyTavern can use it just fine.I'd like to use
text-generation-webui
as an LLM backend in a small custom project. Right now, because the examples are not working, it is difficult to build a custom program that calls the API, short of reading through the (much longer) source code of SillyTavern or another known-working app.Is there an existing issue for this?
Reproduction
text-generation-webui
with theopenai
extension enabled, to serve the API onlocalhost:5000
.Screenshot
No response
Logs
Python chat example
This is actually caused by a
500
error from the server, which is not detected, since the example has no error handling (hence the misleading error messages above).By adding
print(response)
right after the lineresponse = requests.post(url, headers=headers, json=data, verify=False)
, the program prints<Response [500]>
before crashing as above.Python chat example with streaming
System Info
EDIT: Fixed broken formatting, due to the auto-formatting in the logs and system info sections.