xu song
commited on
Commit
•
aad5245
1
Parent(s):
8344bac
update
Browse files
client.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client
|
2 |
+
|
3 |
+
client = Client("xu-song/self-chat")
|
4 |
+
|
5 |
+
|
6 |
+
def self_chat_demo(system_message, num_turn=4):
|
7 |
+
# 1. set system message for the agent
|
8 |
+
client.predict(
|
9 |
+
system=system_message,
|
10 |
+
api_name="/reset_state"
|
11 |
+
)
|
12 |
+
messages = []
|
13 |
+
# 2. self chat
|
14 |
+
for num in range(num_turn):
|
15 |
+
# 注意:history 是 gr.state类型,不能通过API传参
|
16 |
+
messages = client.predict(
|
17 |
+
chatbot=messages,
|
18 |
+
api_name="/generate"
|
19 |
+
)
|
20 |
+
if num % 2 == 0:
|
21 |
+
assert messages[-1][1] is None
|
22 |
+
print(f"Q: {messages[-1][0]}")
|
23 |
+
else:
|
24 |
+
print(f"A: {messages[-1][1]}")
|
25 |
+
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
self_chat_demo(system_message="你是一个小说家,擅长写武侠小说")
|