openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Support `openai api --json completions.create ...`

Open backus opened this issue 1 year ago • 4 comments

Describe the feature or improvement you're requesting

I have this tool I made which I'm using day to day now: https://github.com/backus/ai.sh

It is super useful and I actually like that it is written in pure bash because it is very portable and it is also a testament to just how easy it is to add some AI magic to your application. That said, one thing I'd like to add to the tool is the ability to see why the completion finished generating (did it hit a stop token or did it hit the token limit?).

I could do this to switching to a pure cURL, but I'd love if I could just tell the client to give me JSON instead of just the .choices[0].text. Would be really easy then to use jq to manipulate the response inside of scripts.

Additional context

No response

backus avatar Mar 17 '23 13:03 backus

The whole JSON can be accessed through completion variable

Arthavruksha avatar Mar 17 '23 17:03 Arthavruksha

@Arthavruksha I'm talking about the CLI. For example:

$ openai api completions.create -p 'Say hello' -m 'text-ada-001'
Say hello

Hello!%

backus avatar Mar 18 '23 18:03 backus

On it!

bnkc avatar Jan 12 '24 18:01 bnkc

@backus does this PR do what you were hoping for? https://github.com/openai/openai-python/pull/1068

rattrayalex avatar Feb 08 '24 23:02 rattrayalex