Chatcompletion empty output

Hey guys,
For now I’ve been using text complexion with davincii 3, but want to switch on gpt3.5-turbo and gpt4 for some tests.
My code here return an empty Json, it seems the completion is not working, I would say it come from my prompt.
Here is my code :

class Gpt3:
    def __init__(self):
        self.openai = self.connect()

    def connect(self):
        openai.organization = os.getenv("OPENAI_API_ORGA")
        openai.api_key = os.getenv("OPENAI_API_KEY")
        return openai

    def make_summary(self, content):
        messages=[
      {
         "role":"system",
         "content":"I want you to act as an assitant that makes summary of calls and speachs"
      },
      {
         "role":"user",
         "content":f"Content is : {content}"},
      {
         "role":"user",
         "content":"Can you make a summary?"
      }
   ]
        response = openai.ChatCompletion(
            engine="gpt-3.5-turbo",
            messages=messages,
            temperature=0.3,
        )
        return response```

No error message?

Does it work if you change the prompt?

Welcome to the forum.

1 Like

Thanks. Nop nothing happen, event if I change my prompt. That’s weird.

I think you want to amend the end of the make_summary method as follows:

[...]
        response = self.openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=messages,
            temperature=0.3,
        )
        return response.choices[0]["message"]["content"]

In particular: refer to the class instance of OpenAI you initialized in the __init__ method. Use the openai.ChatCompletion.create() method with the model argument (I think this is the main issue and this change is what will get it working correctly). Get the output with response.choices[0]["message"]["content"],

Edit: this revised code works for me.

import openai
import os

class Gpt3:
    def __init__(self):
        self.openai = self.connect()

    def connect(self):
        #openai.organization = os.getenv("OPENAI_API_ORGA")
        openai.api_key = os.getenv("OPENAI_API_KEY")
        return openai

    def make_summary(self, content):
        messages=[
      {
         "role":"system",
         "content":"I want you to act as an assitant that makes summary of calls and speachs"
      },
      {
         "role":"user",
         "content":f"Content is : {content}"},
      {
         "role":"user",
         "content":"Can you make a summary?"
      }
   ]
        response = self.openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=messages,
            temperature=0.3,
        )
        return response.choices[0]["message"]["content"]
2 Likes

Indeed it’s working for me too, thanks. As I say the json was empty, so the problem may have come from openai organisation part.
Thanks a lot !

1 Like

I suspect it was this part:

response = self.openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=messages,
    temperature=0.3,
)

compared to what you had originally:

response = openai.ChatCompletion(
    engine="gpt-3.5-turbo",
    messages=messages,
    temperature=0.3,
)

(ChatCompletion() vs ChatCompletion.create())

1 Like