Spaces:
Runtime error
Runtime error
maxmon commited on
Commit ·
284628d
1
Parent(s): 6ebd5a9
feat: 初始化
Browse filesFiles changed (4)
- .gitignoreAdded+2
- LICENSEAdded+21
- app.pyAdded+59
- src/proxy.pyAdded+20
12data/
*.pyc123456789101112131415161718192021MIT License
Copyright (c) 2023 LLMLab
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import gradio
from src.proxy import chat
# 左边是介绍、聊天记录,右边是对话框
dd_prompt = '''下面是一个数字分身{name}的性格、介绍:
{desc}
下面是数字分身和别人的对话:
{chat}
请针对上文,扮演这个数字分身,和我聊天,接下来你会和我说:'''
# 哆啦A梦
# 哆啦A梦,有各种各样的道具,喜欢帮助别人,喜欢吃铜锣烧
# 哆啦A梦:大雄,你怎么又闯祸了!!!
def dd_chat(dd_name, dd_desc, dd_example_chat, msg, his):
dd_soul = dd_prompt.format(name=dd_name, desc=dd_desc, chat=dd_example_chat)
_his = [[dd_soul, ''], *his]
_res = chat(msg, _his)
his.append([msg, _res])
return '', his
# 用一个小故事来测试性格
# 人物介绍
# 聊天记录
# 基于性格、聊天记录来对话
import gradio as gr
import os
import random
import time
with gr.Blocks() as demo:
gr.Markdown("Start typing below and then click **Run** to see the output.")
with gr.Row():
with gr.Column():
dd_name = gr.Textbox(placeholder="昵称", lines=1)
dd_desc = gr.Textbox(placeholder="介绍一下你想做的分身,比如性格、爱好、职业、梦想、年龄等等", lines=5)
dd_example_chat = gr.Textbox(placeholder="输入分身语录,或和别人的对话", lines=10)
with gr.Column():
chatbot = gr.Chatbot(lines=10, placeholder="和分身聊天", live=True)
msg = gr.Textbox()
with gr.Row():
chat_btn = gr.Button("Chat")
clear = gr.Button("Clear")
chat_btn.click(dd_chat, [dd_name, dd_desc, dd_example_chat, msg, chatbot], [msg, chatbot])
msg.submit(dd_chat, [dd_name, dd_desc, dd_example_chat, msg, chatbot], [msg, chatbot])
gr.Examples(inputs=[dd_name, dd_desc, dd_example_chat], examples=[['哆啦A梦', '哆啦A梦,有各种各样的道具,喜欢帮助别人,喜欢吃铜锣烧', '哆啦A梦:大雄,你怎么又闯祸了!!!']])
# btn = gr.Button("Run")
# btn.click(fn=update, inputs=inp, outputs=out)
if __name__ == '__main__':
demo.launch()1234567891011121314151617181920import requests
def chat(input, history=[]):
headers = {
"Authorization": "Bearer sk-TmUhOQKWsJ5t43QVoGBblSw3GFOMZwZhpGFlCGX7jxwedsdN"
}
_history = []
for item in history:
_history.append({"role": "user", "content": item[0]})
_history.append({"role": "assistant", "content": item[1]})
j = {
"model": "gpt-3.5-turbo",
"messages": [*_history, {"role": "user", "content": input}],
"temperature": 0.7
}
result = requests.post('https://api.aiproxy.io/v1/chat/completions', json=j, headers=headers)
return result.json()['choices'][0]['message']['content']
if __name__ == '__main__':
print(chat('你好')).gitignoreAdded+2
LICENSEAdded+21
app.pyAdded+59
src/proxy.pyAdded+20