diff options
author | mache102 <91365155+mache102@users.noreply.github.com> | 2023-05-01 16:58:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 16:58:57 +0200 |
commit | b59535129643b2988c16413e0f66bef5c7713a34 (patch) | |
tree | bec2815e11225ae3f07c9a6ed6a8d091953406ff /gui/pywebio-gui/pywebio-usesless.py | |
parent | fix index display for search (diff) | |
parent | Merge pull request #332 from mache102/main (diff) | |
download | gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.tar gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.tar.gz gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.tar.bz2 gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.tar.lz gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.tar.xz gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.tar.zst gpt4free-b59535129643b2988c16413e0f66bef5c7713a34.zip |
Diffstat (limited to 'gui/pywebio-gui/pywebio-usesless.py')
-rw-r--r-- | gui/pywebio-gui/pywebio-usesless.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gui/pywebio-gui/pywebio-usesless.py b/gui/pywebio-gui/pywebio-usesless.py new file mode 100644 index 00000000..c0843be6 --- /dev/null +++ b/gui/pywebio-gui/pywebio-usesless.py @@ -0,0 +1,59 @@ +from gpt4free import usesless
+import time
+from pywebio import start_server,config
+from pywebio.input import *
+from pywebio.output import *
+from pywebio.session import local
+message_id = ""
+def status():
+ try:
+ req = usesless.Completion.create(prompt="hello", parentMessageId=message_id)
+ print(f"Answer: {req['text']}")
+ put_success(f"Answer: {req['text']}",scope="body")
+ except:
+ put_error("Program Error",scope="body")
+
+def ask(prompt):
+ req = usesless.Completion.create(prompt=prompt, parentMessageId=local.message_id)
+ rp=req['text']
+ local.message_id=req["id"]
+ print("AI:\n"+rp)
+ local.conversation.extend([
+ {"role": "user", "content": prompt},
+ {"role": "assistant", "content": rp}
+ ])
+ print(local.conversation)
+ return rp
+
+def msg():
+ while True:
+ text= input_group("You:",[textarea('You:',name='text',rows=3, placeholder='请输入问题')])
+ if not(bool(text)):
+ break
+ if not(bool(text["text"])):
+ continue
+ time.sleep(0.5)
+ put_code("You:"+text["text"],scope="body")
+ print("Question:"+text["text"])
+ with use_scope('foot'):
+ put_loading(color="info")
+ rp= ask(text["text"])
+ clear(scope="foot")
+ time.sleep(0.5)
+ put_markdown("Bot:\n"+rp,scope="body")
+ time.sleep(0.7)
+
+@config(title="AIchat",theme="dark")
+def main():
+ put_scope("heads")
+ with use_scope('heads'):
+ put_html("<h1><center>AI Chat</center></h1>")
+ put_scope("body")
+ put_scope("foot")
+ status()
+ local.conversation=[]
+ local.message_id=""
+ msg()
+
+print("Click link to chat page")
+start_server(main, port=8099,allowed_origins="*",auto_open_webbrowser=True,debug=True)
|