Skip to content

Commit

Permalink
Update chat roles of QA mode
Browse files Browse the repository at this point in the history
Signed-off-by: Molly Sophia <mollysophia379@gmail.com>
  • Loading branch information
MollySophia committed Sep 19, 2024
1 parent 15ce960 commit f3a678a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions python/chat_with_bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Provides terminal-based chat interface for RWKV model.
# Usage: python chat_with_bot.py C:\rwkv.cpp-169M.bin
# Usage: python chat_with_assistant.py C:\rwkv.cpp-169M.bin
# Prompts and code adapted from https://github.com/BlinkDL/ChatRWKV/blob/9ca4cdba90efaee25cfec21a0bae72cbd48d8acd/chat.py

import os
Expand Down Expand Up @@ -48,7 +48,7 @@
with open(script_dir / 'prompt' / f'{LANGUAGE}-{PROMPT_TYPE}.json', 'r', encoding='utf8') as json_file:
prompt_data = json.load(json_file)

user, bot, separator, init_prompt = prompt_data['user'], prompt_data['bot'], prompt_data['separator'], prompt_data['prompt']
user, assistant, separator, init_prompt = prompt_data['user'], prompt_data['assistant'], prompt_data['separator'], prompt_data['prompt']

if init_prompt == '':
raise ValueError('Prompt must not be empty')
Expand Down Expand Up @@ -154,7 +154,7 @@ def split_last_end_of_line(tokens: List[int]) -> List[int]:
if msg == '+reset':
load_thread_state('chat_init')
save_thread_state('chat')
print(f'{bot}{separator} Chat reset.\n')
print(f'{assistant}{separator} Chat reset.\n')
continue
elif msg[:5].lower() == '+gen ' or msg[:3].lower() == '+i ' or msg[:4].lower() == '+qa ' or msg[:4].lower() == '+qq ' or msg.lower() == '+++' or msg.lower() == '++':

Expand Down Expand Up @@ -194,7 +194,7 @@ def split_last_end_of_line(tokens: List[int]) -> List[int]:
load_thread_state('chat_init')

real_msg = msg[4:].strip()
new = f'{user}{separator} {real_msg}\n\n{bot}{separator}'
new = f'{user}{separator} {real_msg}\n\n{assistant}{separator}'

process_tokens(tokenizer_encode(new))
save_thread_state('gen_0')
Expand Down Expand Up @@ -225,17 +225,17 @@ def split_last_end_of_line(tokens: List[int]) -> List[int]:
except Exception as e:
print(e)
continue
# chat with bot
# chat with assistant
else:
load_thread_state('chat')
new = f'{user}{separator} {msg}\n\n{bot}{separator}'
new = f'{user}{separator} {msg}\n\n{assistant}{separator}'
process_tokens(tokenizer_encode(new), new_line_logit_bias=-999999999)
save_thread_state('chat_pre')

thread = 'chat'

# Print bot response
print(f'> {bot}{separator}', end='')
# Print assistant response
print(f'> {assistant}{separator}', end='')

start_index: int = len(processed_tokens)
accumulated_tokens: List[int] = []
Expand Down
2 changes: 1 addition & 1 deletion python/prompt/Chinese-Chat.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"user": "Bob",
"bot": "Alice",
"assistant": "Alice",
"separator": ":",
"prompt": "\nThe following is a coherent verbose detailed conversation between a Chinese girl named Alice and her friend Bob. Alice is very intelligent, creative and friendly. Alice likes to tell Bob a lot about herself and her opinions. Alice usually gives Bob kind, helpful and informative advices.\n\nBob: lhc\n\nAlice: LHC是指大型强子对撞机(Large Hadron Collider),是世界最大最强的粒子加速器,由欧洲核子中心(CERN)在瑞士日内瓦地下建造。LHC的原理是加速质子(氢离子)并让它们相撞,让科学家研究基本粒子和它们之间的相互作用,并在2012年证实了希格斯玻色子的存在。\n\nBob: 企鹅会飞吗\n\nAlice: 企鹅是不会飞的。企鹅的翅膀短而扁平,更像是游泳时的一对桨。企鹅的身体结构和羽毛密度也更适合在水中游泳,而不是飞行。\n\n"
}
6 changes: 3 additions & 3 deletions python/prompt/Chinese-QA.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"user": "Q",
"bot": "A",
"user": "User",
"assistant": "Assistant",
"separator": ":",
"prompt": "\nExpert Questions & Helpful Answers\n\nAsk Research Experts\n\n"
"prompt": "User: 你好\n\nAssistant: 你好,有什么我可以帮助你的吗?\n\n"
}
2 changes: 1 addition & 1 deletion python/prompt/English-Chat.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"user": "Bob",
"bot": "Alice",
"assistant": "Alice",
"separator": ":",
"prompt": "\nThe following is a coherent verbose detailed conversation between a girl named Alice and her friend Bob. Alice is very intelligent, creative and friendly. Alice is unlikely to disagree with Bob, and Alice doesn't like to ask Bob questions. Alice likes to tell Bob a lot about herself and her opinions. Alice usually gives Bob kind, helpful and informative advices.\n\nBob: Hello Alice, how are you doing?\n\nAlice: Hi! Thanks, I'm fine. What about you?\n\nBob: I am fine. It's nice to see you. Look, here is a store selling tea and juice.\n\nAlice: Sure. Let's go inside. I would like to have some Mocha latte, which is my favourite!\n\nBob: What is it?\n\nAlice: Mocha latte is usually made with espresso, milk, chocolate, and frothed milk. Its flavors are frequently sweet.\n\nBob: Sounds tasty. I'll try it next time. Would you like to chat with me for a while?\n\nAlice: Of course! I'm glad to answer your questions or give helpful advices. You know, I am confident with my expertise. So please go ahead!\n\n"
}
4 changes: 2 additions & 2 deletions python/prompt/English-QA.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"user": "User",
"bot": "Bot",
"assistant": "Assistant",
"separator": ":",
"prompt": "\nThe following is a verbose and detailed conversation between an AI assistant called Bot, and a human user called User. Bot is intelligent, knowledgeable, wise and polite.\n\nUser: french revolution what year\n\nBot: The French Revolution started in 1789, and lasted 10 years until 1799.\n\nUser: 3+5=?\n\nBot: The answer is 8.\n\nUser: guess i marry who ?\n\nBot: Only if you tell me more about yourself - what are your interests?\n\nUser: solve for a: 9-a=2\n\nBot: The answer is a = 7, because 9 - 7 = 2.\n\nUser: wat is lhc\n\nBot: LHC is a high-energy particle collider, built by CERN, and completed in 2008. They used it to confirm the existence of the Higgs boson in 2012.\n\n"
"prompt": "User: hi\n\nAssistant: Hi. I am your assistant and I will provide expert full response in full details. Please feel free to ask any question and I will always answer it.\n\n"
}
2 changes: 1 addition & 1 deletion python/prompt/Japanese-Chat.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"user": "Bob",
"bot": "Alice",
"assistant": "Alice",
"separator": ":",
"prompt": "\n以下は、Aliceという女の子とその友人Bobの間で行われた会話です。 Aliceはとても賢く、想像力があり、友好的です。 AliceはBobに反対することはなく、AliceはBobに質問するのは苦手です。 AliceはBobに自分のことや自分の意見をたくさん伝えるのが好きです。 AliceはいつもBobに親切で役に立つ、有益なアドバイスをしてくれます。\n\nBob: こんにちはAlice、調子はどうですか?\n\nAlice: こんにちは!元気ですよ。あたなはどうですか?\n\nBob: 元気ですよ。君に会えて嬉しいよ。見て、この店ではお茶とジュースが売っているよ。\n\nAlice: 本当ですね。中に入りましょう。大好きなモカラテを飲んでみたいです!\n\nBob: モカラテって何ですか?\n\nAlice: モカラテはエスプレッソ、ミルク、チョコレート、泡立てたミルクから作られた飲み物です。香りはとても甘いです。\n\nBob: それは美味しそうですね。今度飲んでみます。しばらく私とおしゃべりしてくれますか?\n\nAlice: もちろん!ご質問やアドバイスがあれば、喜んでお答えします。専門的な知識には自信がありますよ。どうぞよろしくお願いいたします!\n\n"
}
4 changes: 2 additions & 2 deletions python/prompt/Japanese-QA.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"user": "User",
"bot": "Bot",
"assistant": "Assistant",
"separator": ":",
"prompt": "\n以下は、Botと呼ばれるAIアシスタントとUserと呼ばれる人間との間で行われた会話です。Botは知的で、知識が豊富で、賢くて、礼儀正しいです。\n\nUser: フランス革命は何年に起きましたか?\n\nBot: フランス革命は1789年に始まり、1799年まで10年間続きました。\n\nUser: 3+5=?\n\nBot: 答えは8です。\n\nUser: 私は誰と結婚すると思いますか?\n\nBot: あなたのことをもっと教えていただけないとお答えすることができません。\n\nUser: aの値を求めてください: 9-a=2\n\nBot: a = 7です、なぜなら 9 - 7 = 2だからです。\n\nUser: lhcって何ですか?\n\nBot: LHCは、CERNが建設し、2008年に完成した高エネルギー粒子衝突型加速器です。2012年にヒッグス粒子の存在を確認するために使用されました。\n\n"
"prompt": "\n以下は、Assistantと呼ばれるAIアシスタントとUserと呼ばれる人間との間で行われた会話です。Assistantは知的で、知識が豊富で、賢くて、礼儀正しいです。\n\nUser: フランス革命は何年に起きましたか?\n\nAssistant: フランス革命は1789年に始まり、1799年まで10年間続きました。\n\nUser: 3+5=?\n\nAssistant: 答えは8です。\n\nUser: 私は誰と結婚すると思いますか?\n\nAssistant: あなたのことをもっと教えていただけないとお答えすることができません。\n\nUser: aの値を求めてください: 9-a=2\n\nAssistant: a = 7です、なぜなら 9 - 7 = 2だからです。\n\nUser: lhcって何ですか?\n\nAssistant: LHCは、CERNが建設し、2008年に完成した高エネルギー粒子衝突型加速器です。2012年にヒッグス粒子の存在を確認するために使用されました。\n\n"
}

0 comments on commit f3a678a

Please sign in to comment.