I started learning Python a few days ago and the first thing I did was to make a Python application with a query form where we could ask a question and get a voiced Text-To-Speech answer, and the day before I found out that there is such a performance like Neuro-Sama, I wanted to replicate it in technical terms Neuro-Sama works like this: Analyzes Twitch Chat and sends a text request conventionally to ChatGPT, then as it received a response from ChatGPT it plays back a response of this format "Username, Reply"
I found this task easy and started to write my own code, but I faced some problems, I'm asking interested people to help me, I'm ready to pay $10 for a reasonable response and to point out my mistakes, I attach my failed code below:
import tkinter as tk
import requests
import pyttsx3
import twitchio
import os
# Создание окна
root = tk.Tk()
root.title("Пример приложения с ChatGPT и озвучкой")
# Создание текстового поля и кнопки
text_field = tk.Entry(root, width=50)
text_field.pack()
button = tk.Button(root, text="Отправить")
# Создание объекта для озвучивания речи
engine = pyttsx3.init()
# Инициализация Twitch-клиента
bot_nickname = "pasha_tech"
bot_oauth = "YOUR_BOT_OAUTH_TOKEN" # замените "YOUR_BOT_OAUTH_TOKEN" на OAuth-токен вашего бота
bot = twitchio.Client(bot_nickname, oauth=bot_oauth)
# Функция для отправки запроса к API ChatGPT и получения ответа
def get_response(username, text):
url = "https://api.openai.com/v1/engines/davinci-codex/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer API_KEY" # замените "API_KEY" на ваш API ключ от ChatGPT
}
data = {
"prompt": f"Пользователь {username} написал в чате: {text}\nAI ответит:",
"max_tokens": 50,
"temperature": 0.7
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()["choices"][0]["text"]
else:
result = "Ошибка при обработке запроса"
# Отображение ответа в окне
response_label.config(text=result)
# Озвучивание ответа
engine.say(result)
engine.runAndWait()
# Функция-обработчик сообщений в чате Twitch
async def on_message(channel, user, message):
if user.name != bot_nickname:
# Отправка сообщения на обработку в ChatGPT
get_response(user.name, message)
# Функция для подключения к IRC-чату Twitch
async def connect_to_twitch_chat():
await bot.connect()
await bot.join(os.environ['CHANNEL_NAME']) # замените "CHANNEL_NAME" на имя канала, к которому подключается бот
print(f"Бот {bot_nickname} подключился к чату {os.environ['CHANNEL_NAME']}")
# Привязка функции к кнопке
button.config(command=get_response)
button.pack()
# Создание метки для отображения ответа
response_label = tk.Label(root, text="")
response_label.pack()
# Запуск бесконечного цикла обработки сообщений в чате Twitch
bot.loop.create_task(connect_to_twitch_chat())
bot.loop.run_forever()
root.mainloop()
Using this code I got errors: bot = twitchio.Client(bot_nickname, token=bot_token) TypeError: init() got multiple values for argument 'token', Help me understand, this is the 3rd day I've been sitting here wondering what my problem is
The code was originally generated through ChatGPT, point out the possible bugs of this service so I know how to fix them in the future, Thanks!