text-generation-webui icon indicating copy to clipboard operation
text-generation-webui copied to clipboard

[openai] add edits & image endpoints & fix prompt return in non --chat modes

Open matatonic opened this issue 2 years ago • 7 comments

This was pretty simple and works well for translations, spelling, "professional emails", code reformatting, etc.

matatonic avatar May 03 '23 07:05 matatonic

Some examples of how it works (using Alpaca-30B-4bit):

>>> import openai
>>> print(openai.Edit.create(model='x', instruction='Reformat the following python code to be standard', input="deb fibinacci(n):\na, b, c = 0,1, 1\nyield a\nwhile c < n:\na, b, c = a+b, a, c + 1\nyeild a")['choices'][0]['text'])
def fibonacci(n):
    a, b, c = 0, 1, 1
    while c <= n:
        yield a
        a, b, c = a + b, a, c + 1
>>> openai.Edit.create(model='x', instruction='Translate the text to French.', input="The best things in life are free.")['choices'][0]['text']
'Les meilleures choses de la vie sont gratuites.'
>>> openai.Edit.create(model='x', instruction='Make the text sound professional and polite.', input="Jim you rock, that pitch was the bomb! You da man!")['choices'][0]['text']
'Thank you for your hard work on the presentation, Jim. Your efforts were greatly appreciated by everyone in attendance.'

It even fixed the "c <= n" from "c < n" and the 2 typos in the Fibonacci code.

matatonic avatar May 03 '23 21:05 matatonic

I have never used the openai api, does it have an edits endpoint that uses the alpaca format?

oobabooga avatar May 04 '23 14:05 oobabooga

@oobabooga The edits interface is very much like the Alpaca format for instruction/input/response, yes, it's a very natural fit but it's not exactly the same. The API docs for "edits" are here: https://platform.openai.com/docs/api-reference/edits

matatonic avatar May 04 '23 16:05 matatonic

This includes a fix for running in modes other than --chat (the bug with the prompt being returned as well). It's a fairly important fix and should resolve many issued for people who were getting the prompt back in the reply.

matatonic avatar May 04 '23 17:05 matatonic

@drndos FYI, I think I've fixed the issue with the prompt being returned (happens in modes that are not --chat). This PR should do it and should work regardless of server mode.

matatonic avatar May 05 '23 00:05 matatonic

@oobabooga I have a basic images endpoint completed as well and with that I think I'm going to stop for a while until people ask for more. The image generation is better done via Stable Diffusion directly anyways, and I don't know if the other API endpoints are used much (maybe audio?). Anyways, should I merge the image code with this PR or create a second one?

matatonic avatar May 05 '23 21:05 matatonic

Thanks for fixing the prompt return. This was driving me crazy lol I couldn't figure out why it always returned the prompt.

CyberTimon avatar May 06 '23 16:05 CyberTimon

I don't think it's appropriate to hard code the Alpaca format. This format is popular now but another better instruction-following model might be released next week making it obsolete

oobabooga avatar May 09 '23 02:05 oobabooga

totally agree, I literally just finished this: https://github.com/oobabooga/text-generation-webui/pull/1935

matatonic avatar May 09 '23 05:05 matatonic