gpt4 book ai didi

python - 我想为 twitch 创建我的 Neuro-sama 模拟,但是

转载 作者:行者123 更新时间:2023-12-02 05:47:22 24 4
gpt4 key购买 nike

几天前我开始学习 Python,我做的第一件事是制作一个带有查询表单的 Python 应用程序,我们可以在其中提出问题并获得有声的文本到语音的答案,而前一天我发现发现有神经大人这样的表演,我想用技术术语来复制它 神经大人的工作原理是这样的:分析 Twitch Chat 并按常规向 ChatGPT 发送文本请求,然后当它收到来自 ChatGPT 的响应时,它会播放这种格式的响应“用户名,回复”

我发现这个任务很简单,并开始编写自己的代码,但我遇到了一些问题,我正在请求感兴趣的人帮助我,我准备支付 10 美元以获得合理的回应并指出我的错误,我在下面附上我失败的代码:

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()

使用这段代码我得到了错误:bot = twitchio.Client(bot_nickname, token=bot_token)TypeError:init() 为参数“token”获取了多个值,帮助我理解,这是我坐在这里想知道我的问题是什么的第 3 天

代码最初是通过ChatGPT生成的,请指出此服务可能存在的错误,以便我知道将来如何修复它们,谢谢!

最佳答案

我接近 AI Vtuber 项目的稳定版本,请改用新的 gpt-3.5-turbo 模型。此外,您还需要提供初始提示,以便我承担角色和反馈循环以提供短期内存(与机器人内存是自动的 chatgpt 不同)

https://www.youtube.com/watch?v=dkgJBcTitpE

尝试遵循文档中相同的代码结构:https://twitchio.dev/en/latest/quickstart.html

class Bot(commands.Bot):

def __init__(self):
# Initialise our Bot with our access token, prefix and a list of channels to join on boot...
# prefix can be a callable, which returns a list of strings or a string...
# initial_channels can also be a callable which returns a list of strings...

# --- GET YOUR TWITCH ACCEESS_TOKEN USING: https://twitchtokengenerator.com/ ----

super().__init__(token='ACCESS_TOKEN', prefix='?', initial_channels=['...'])

async def event_ready(self):
# Notify us when everything is ready!
# We are logged in and ready to chat and use commands...
print(f'Logged in as | {self.nick}')
print(f'User id is | {self.user_id}')

async def event_message(self, message):
# Messages with echo set to True are messages sent by the bot...
# For now we just want to ignore them...
if message.echo:
return

# ---------------PUT YOUR OPEN AI CODE HERE----------
# SOME VARIABLE
# user unique Id (never changes per account): message.author.id
# user chat name: message.author.name
# user's message you include in your prompt: message.content

# Since we have commands and are overriding the default `event_message`
# We must let the bot know we want to handle and invoke our commands...
await self.handle_commands(message)

# WHEN YOU SEND ?hello THIS STILL GOES THROUGH event_message() THEN CAUGHT BY THIS METHOD
@commands.command()
async def hello(self, ctx: commands.Context):
# Here we have a command hello, we can invoke our command with our prefix and command name
# e.g ?hello
# We can also give our commands aliases (different names) to invoke with.

# Send a hello back!
# Sending a reply back to the channel is easy... Below is an example.
await ctx.send(f'Hello {ctx.author.name}!')


bot = Bot()
bot.run() # bot.run() is blocking and will stop execution of any below code here until stopped or closed.

在开放的 Ai 代码块上集成此技术以赋予机器人内存和角色:https://github.com/daveshap/LongtermChatExternalSources

关于python - 我想为 twitch 创建我的 Neuro-sama 模拟,但是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75504586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com