import openai
import time
from mcpi.minecraft import Minecraft
mc = Minecraft.create()
openai.api_key = '你的api密钥'#如果不想画前的话可以试试这个(https://github.com/chatanywhere/GPT_API_free)
while 1:
time.sleep(1)
with open('latest.log', 'r', encoding='GB2312') as f:
for data in f.readlines():
data = data.strip('\n') #去除文本中的换行符
print(data)
if data.find("@chatGPT")!=-1:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",#你的gpt模型,有gpt-3.5-turbo和gpt-4
messages=[{"role": "user", "content": data}]
)
chatdata=''
print(response.choices[0].message['content'])
for strdata in response.choices[0].message['content']:
strdata = strdata.strip('\n')
chatdata=chatdata+strdata
#mc.postToChat(strdata) #启用这个可以挤牙膏......&增加风格(超不划算)
mc.postToChat(chatdata)
需要安装mcpi和openai库
安装方法:
pip install openai==0.28
新版库的教程https://github.com/openai/openai-python
pip install mcpi
请把这个py文件放在服务器的logs文件夹里o
还需要个插件:
https://github.com/zhuowei/RaspberryJuice
找到zip中的jars文件夹,找一个比较新的版本复制到服务器的插件文件夹就大公告成啦!
具体教程:https://www.bilibili.com/video/BV1FG4y1X7SQ