строка 25 в
response =chat_with_gpt(human_input)
строка 17 вchat_with_gptreturncomplete.choices[0].message.content.strip()
TypeError: объект «NoneType» не подлежит подписке
I не могу понять, где я ошибаюсь. Любая помощь будет принята с благодарностью. Спасибо.
Полный код приведен ниже:
Код: Выделить всё
import openai
openai.api_type = "open_ai"
openai.base_url = "http://127.0.0.1:1234"
openai.api_key = "NULL"
def chat_with_gpt(prompt):
completion = openai.chat.completions.create(
messages = [
{"role": "user",
"content": prompt}
],
model="llama3"
)
return completion.choices[0].message.content.strip()
while True:
human_input = input("Human: ")
if human_input.lower() in ["quit", "exit", "bye"]:
break
response = chat_with_gpt(human_input)
print("Chatbot: ", response)
if __name__ == "__main__":
while True:
human_input = input("Human: ")
if human_input.lower() in ["quit", "exit", "bye"]:
break
response = chat_with_gpt(human_input)
print("Chatbot: ", response)
Подробнее здесь: https://stackoverflow.com/questions/792 ... o-solve-it