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

docs: Improve documentation around createCompletion vs createChatCompletion #23

Open
raygao opened this issue Aug 3, 2023 · 16 comments
Labels
documentation Improvements or additions to documentation

Comments

@raygao
Copy link

raygao commented Aug 3, 2023

Error: invalid_request_error: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
This is the feedback from ChatGPT 3.5 nowadays. out-of-date

@lino-levan
Copy link
Collaborator

Can you share some code to reproduce this issue?

@raygao
Copy link
Author

raygao commented Aug 3, 2023

Never mind. I got it working. You can close the ticket now.

The following does work.
const chatCompletion = await openAI.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Who won the world series in 2020?" },
{
"role": "assistant",
"content": "The Los Angeles Dodgers won the World Series in 2020.",
},
{ "role": "user", "content": "Where was it played?" },
],
});

console.log(chatCompletion.choices);

@lino-levan
Copy link
Collaborator

We should make it clearer in the docs. Thank you for raising this issue!

@lino-levan lino-levan changed the title URL end points are out of date. docs: Improve documentation around createCompletion vs createChatCompletion Aug 3, 2023
@load1n9
Copy link
Owner

load1n9 commented Aug 4, 2023

We should make it clearer in the docs. Thank you for raising this issue!

we might aswell make a full doc site with pyro

@lino-levan
Copy link
Collaborator

Not a bad idea.

@raygao
Copy link
Author

raygao commented Aug 5, 2023

Another queestion, I have a web front end calling a REST function that uses the openAI.createChatCompletion();
But, it is not blocking. as a result, I get an error - TypeError: Failed to fetch in the browser and never manage to get any content back. It is using the Fresh framework. I am calling using fetch from the frontend to the REST API, which contains the openAI function.
At the same time, the same call to the same REST API from Postman works fine and without a hitch.
somehow the createChatCompletion() just jumps over, despite the await or then chaining on async function.
thanks

@lino-levan
Copy link
Collaborator

You you provide a github repo with a reproduction of the issue? It only has to include an API route.

@raygao
Copy link
Author

raygao commented Aug 5, 2023

Yes. I have a repo. https://github.com/raygao/uxig
In the /api/genStory/index.tsx, I call the genStory(body), which calls the openai.CreateChatCompletion( ...)
And, this is where I am having difficulties.

image

image

@raygao
Copy link
Author

raygao commented Aug 5, 2023

Also, the frontend.
image
image

@lino-levan
Copy link
Collaborator

In the code you provide, you return a string from /api/genStory/index.tsx. You can't do that, you must return a response. That's what the red squiggly line is under POST. You should change your handler to include

return new Response(results);

instead of

return results;

@lino-levan lino-levan added the documentation Improvements or additions to documentation label Aug 5, 2023
@raygao
Copy link
Author

raygao commented Aug 6, 2023

Thanks a lot for the help.
That hint solved the red squiggly line under the POST method.
However, the browser still has a Validation issue. see screenshots.
As soon as it calls the createChatCompletion, the fetch method fails. I am not understanding this.
image
image

@lino-levan
Copy link
Collaborator

Okay I think I found the bug. You fetch the api route using

const result = await fetch(url, theScenario);

when you should be doing

const result = await fetch(url, { body: theScenario });

@raygao
Copy link
Author

raygao commented Aug 6, 2023

Amazing how fast, you guys respond! Much appreciate for the help.
Actually, the solution is even simpler. I googled just now, after struggling it for 1 full day.
When I add the event.preventDefault(); to my onclick() method, the issue magically disappear.
https://stackoverflow.com/questions/64619140/my-fetch-requests-are-being-canceled-and-i-dont-know-why
image

@lino-levan
Copy link
Collaborator

Nice, good to here that the bug is fixed!

@raygao
Copy link
Author

raygao commented Aug 7, 2023

Please find the result running app at: https://comfortable-hawk-99.deno.dev/
Thanks a lot for your support. Appreciate it.

@raygao raygao closed this as completed Aug 7, 2023
@lino-levan
Copy link
Collaborator

Reopening so that we can improve docs, happy to hear you were able to deploy your app!

@lino-levan lino-levan reopened this Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants