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```
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"]