代码拉取完成,页面将自动刷新
同步操作将从 mktime/python-learn 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import openai
import sys
import os
#api_key = os.getenv('OPENAI_API_KEY')
global_msg = [
{"role": "system", "content": "你是一位有用的助手"}
]
def get_reply(input_msg):
msg = {"role": "user", "content": input_msg}
global_msg.append(msg)
response = openai.ChatCompletion.create(
model = "gpt-3.5-turbo",
top_p = 1,
frequency_penalty = 0,
presence_penalty = 0,
temperature = 1,
max_tokens = 3000,
messages = global_msg
)
#print(response)
reply = ''
choices = response['choices']
for r in choices:
reply += r['message']['content']
return reply
def print_banner():
banner = '''
____ ____ _____
/ ___| _ \_ _|
| | _| |_) || |
| |_| | __/ | |
\____|_| |_|
'''
print(banner)
def start_robot():
print_banner()
print('>>', end='', flush=True)
while True:
try:
msg = sys.stdin.readline().strip()
except KeyboardInterrupt:
print('\n再见!')
break
if not msg:
print('>>', end='', flush=True)
continue
reply = get_reply(msg)
reply += '\n>>'
print('>>' + reply, end='', flush=True)
if __name__ == '__main__':
start_robot()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。