Hi, The chatbot chapter code in the course needs updating for API 1.0.0. to avoid the error that the chat completions API is no longer supported, I believe. I tried that by applying the same code as in the Introductions chapter. Also installed the panel module which is required. But trying to run the code, I am getting following error, not sure what it means. Is there an updated code for the chatbot chapter posted anywhere?
TypeError: ‘ChatCompletionMessage’ object is not subscriptable
I have read some other chatbot related posts here. By now, the versions for bokeh are far beyond the 2.4 that somebody mentioned. 3.1.2 is my version, if that matters. There are dependencies which prevent me from going back to version 2.4.
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = client.chat.completions.create(model=model,
messages=messages,
temperature=0)
return response.choices[0].message.content
def get_completion_from_messages(messages,
model="gpt-3.5-turbo",
temperature=0,
max_tokens=500):
response = openai.chat.completions.create(
model=model,
messages=messages,
temperature=temperature, # this is the degree of randomness of the model's output
max_tokens=max_tokens, # the maximum number of tokens the model can ouptut
)
return response.choices[0].message.content