fix: replace Completion with ChatCompletion to use gpt-3.5-turbo model (#2066)

According to https://platform.openai.com/docs/guides/gpt/chat-completions-vs-completions , GPT-3.5 Turbo & GPT-4 is not working on **Legacy** Completions API
This commit is contained in:
MengYX 2023-09-05 15:41:31 +08:00 committed by GitHub
parent 900a4fcb0e
commit 928ae775f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,9 +41,9 @@ class GPTIntegrationEndpoint(BaseAPIView):
final_text = task + "\n" + prompt final_text = task + "\n" + prompt
openai.api_key = settings.OPENAI_API_KEY openai.api_key = settings.OPENAI_API_KEY
response = openai.Completion.create( response = openai.ChatCompletion.create(
model=settings.GPT_ENGINE, model=settings.GPT_ENGINE,
prompt=final_text, messages=[{"role": "user", "content": final_text}],
temperature=0.7, temperature=0.7,
max_tokens=1024, max_tokens=1024,
) )
@ -51,7 +51,7 @@ class GPTIntegrationEndpoint(BaseAPIView):
workspace = Workspace.objects.get(slug=slug) workspace = Workspace.objects.get(slug=slug)
project = Project.objects.get(pk=project_id) project = Project.objects.get(pk=project_id)
text = response.choices[0].text.strip() text = response.choices[0].message.content.strip()
text_html = text.replace("\n", "<br/>") text_html = text.replace("\n", "<br/>")
return Response( return Response(
{ {