improve system for rwkv-4-world

This commit is contained in:
josc146 2023-05-31 12:46:06 +08:00
parent 9f5d15a7d5
commit c8b2bb53ef
2 changed files with 30 additions and 26 deletions

View File

@ -59,28 +59,28 @@ The following is a coherent verbose detailed conversation between a girl named {
{bot} usually gives {user} kind, helpful and informative advices.\n {bot} usually gives {user} kind, helpful and informative advices.\n
""" """
if user == "Bob" if user == "Bob"
else "" else f"{user}{interface} hi\n\n{bot}{interface} 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"
) )
for message in body.messages: for message in body.messages:
if message.role == "system": if message.role == "system":
completion_text = ( completion_text = (
f"The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. " f"The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. "
if user == "Bob" if user == "Bob"
else "" else f"{user}{interface} hi\n\n{bot}{interface} Hi. "
+ message.content.replace("\\n", "\n") + message.content.replace("\\n", "\n")
.replace("\r\n", "\n") .replace("\r\n", "\n")
.replace("\n\n", "\n") .replace("\n\n", "\n")
.replace("\n", " ") .replace("\n", " ")
.strip() .strip()
.replace("You are", f"{bot} is") .replace("You are", f"{bot} is" if user == "Bob" else "I am")
.replace("you are", f"{bot} is") .replace("you are", f"{bot} is" if user == "Bob" else "I am")
.replace("You're", f"{bot} is") .replace("You're", f"{bot} is" if user == "Bob" else "I'm")
.replace("you're", f"{bot} is") .replace("you're", f"{bot} is" if user == "Bob" else "I'm")
.replace("You", f"{bot}") .replace("You", f"{bot}" if user == "Bob" else "I")
.replace("you", f"{bot}") .replace("you", f"{bot}" if user == "Bob" else "I")
.replace("Your", f"{bot}'s") .replace("Your", f"{bot}'s" if user == "Bob" else "My")
.replace("your", f"{bot}'s") .replace("your", f"{bot}'s" if user == "Bob" else "my")
.replace("", f"{bot}") .replace("", f"{bot}" if user == "Bob" else "")
+ "\n\n" + "\n\n"
) )
break break

View File

@ -50,28 +50,32 @@ class RWKV:
self.preload() self.preload()
def preload(self): def preload(self):
if self.user == "Bob": interface = self.interface
bot = self.bot user = self.user
user = self.user bot = self.bot
preset_system = f""" preset_system = (
f"""
The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. \ The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. \
{bot} is very intelligent, creative and friendly. \ {bot} is very intelligent, creative and friendly. \
{bot} is unlikely to disagree with {user}, and {bot} doesn't like to ask {user} questions. \ {bot} is unlikely to disagree with {user}, and {bot} doesn't like to ask {user} questions. \
{bot} likes to tell {user} a lot about herself and her opinions. \ {bot} likes to tell {user} a lot about herself and her opinions. \
{bot} usually gives {user} kind, helpful and informative advices.\n {bot} usually gives {user} kind, helpful and informative advices.\n
""" """
logits = self.run_rnn(self.pipeline.encode(preset_system)) if self.user == "Bob"
try: else f"{user}{interface} hi\n\n{bot}{interface} 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"
state_cache.add_state( )
state_cache.AddStateBody( logits = self.run_rnn(self.pipeline.encode(preset_system))
prompt=preset_system, try:
tokens=self.model_tokens, state_cache.add_state(
state=self.model_state, state_cache.AddStateBody(
logits=logits, prompt=preset_system,
) tokens=self.model_tokens,
state=self.model_state,
logits=logits,
) )
except HTTPException: )
pass except HTTPException:
pass
def run_rnn(self, _tokens: List[str], newline_adj: int = 0): def run_rnn(self, _tokens: List[str], newline_adj: int = 0):
tokens = [int(x) for x in _tokens] tokens = [int(x) for x in _tokens]