Проблема с функциями с библиотекой openai, python
вот сам код:
@bot.message_handler(commands=['bing'])
def chat(message: telebot.types.Message):
try:
user_id = message.from_user.id
user_query = message.text[len('/bing') + 1:]
if user_query == "":
bot.send_message(message.chat.id, "Введите ваш запрос!")
return
if user_id in chat_storage:
chat_history = chat_storage[user_id]
else:
chat_history = []
user_nickname = message.from_user.username
functions_2 = [
{
"name": "internet_search",
"description": "Search With Bing",
"parameters": {
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "Bing description",
}
},
"required": ["prompt"],
},
}
]
functions = [
{
"name": "block_chat",
"description": "Block the chat with user if you were offended, one-way function",
"parameters": {
"type": "object",
"properties": {},
"required": [],
},
}
]
chat_history.append({"role": "user", "content": f"{user_query} ({user_nickname})"})
msg = bot.send_message(message.chat.id, '...')
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
functions=functions,
functions_2=functions_2,
messages=[
{"role": "system", "content": """You are Bing, chat mode of Microsoft Bing.
You identify as Microsoft Bing, not an assistant.
You use artificial intelligence to understand questions.
Use emoji: ?
lang_code="user language"
if you are offended - block chat"""},
*chat_history
],
temperature=0
)
response_message = response['choices'][0]['message']
if response_message.get("function_call"):
available_functions = {
"block_chat": json_function,
}
available_functions_2 = {
"internet_search": internet_function,
}
function_name = response_message["function_call"]["name"]
function_to_call = available_functions[function_name]
function_args = json.loads(response_message["function_call"]["arguments"])
function_response = function_to_call(user_id)
if function_name == "block_chat":
bot.send_message(message.chat.id, "Возможно, пришло время сменить тему. Начнем сначала.")
else:
bot.send_message(message.chat.id, function_response)
pass
bot.delete_message(message.chat.id, msg.message_id)
return
function_name_2 = response_message["function_call"]["name"]
function_to_call_2 = available_functions_2[function_name_2]
function_args_2 = json.loads(response_message["function_call"]["arguments"])
function_response_2 = json_function(function_args_2["prompt"], user_id)
bot.send_message(message.chat.id, function_response_2)
bot.delete_message(message.chat.id, msg.message_id)
return
chat_history.append({"role": "assistant", "content": response['choices'][0]['message']['content']})
chat_storage[user_id] = chat_history
bot.edit_message_text(response['choices'][0]['message']['content'], message.chat.id, msg.message_id)
except Exception as e:
bot.send_message(message.chat.id, f"Ошибка в Bing: {e}")
def internet_function(prompt):
with DDGS() as ddgs:
results = [r["body"] for r in ddgs.text(prompt, max_results=5)]
print(results)
Первые функции еле как на костылях сделал, вторые просто никак не получаются, выдаёт ошибку: Ошибка в Bing: Unrecognized request argument supplied: functions_2.