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

GPT4All API: Add Streaming to the Completions endpoint #1129

Merged

Conversation

TheDropZone
Copy link
Contributor

@TheDropZone TheDropZone commented Jul 3, 2023

Describe your changes

Adding the ability to do streaming requests to the "/completions" endpoint of the API. Added in a test to showcase using the openai python client to stream the response from the api.

This addresses the NotImplementedError in the completions route of the api
https://github.com/nomic-ai/gpt4all/blob/main/gpt4all-api/gpt4all_api/app/api_v1/routes/completions.py#L54

Issue ticket number and link

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • I have added thorough documentation for my code.
  • I have tagged PR with relevant project labels. I acknowledge that a PR without labels may be dismissed.
  • If this PR addresses a bug, I have provided both a screenshot/video of the original bug and the working solution.

Demo

    model = "gpt4all-j-v1.3-groovy"
    prompt = "Who is Michael Jordan?"
    for resp in openai.Completion.create(
            model=model,
            prompt=prompt,
            max_tokens=50,
            temperature=0.28,
            top_p=0.95,
            n=1,
            echo=True,
            stream=True):
        print(resp.choices[0].text)

The above results in the model output being streamed to your console, directly from the API

Notes

There is a great issue thread over on the openai-node library page, discussing a lot of this streaming work.
openai/openai-node#18

…he completions endpoint. Implemented an openai python client test for the new streaming functionality.
@AndriyMulyar
Copy link
Contributor

AndriyMulyar commented Jul 3, 2023

Great contribution. Looks good from first glance. I will review on Wednesday after the holiday!

@AndriyMulyar
Copy link
Contributor

AndriyMulyar commented Jul 6, 2023

Unit tests pass on my local build. Merging.

@AndriyMulyar AndriyMulyar merged commit fb576fb into nomic-ai:main Jul 6, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants