Skip to content

Commit

Permalink
better logic for interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
minimaxir committed Jun 7, 2023
1 parent 289017c commit 22d58d0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions simpleaichat/simpleaichat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Config:
def __init__(
self,
character: str = None,
character_command: str = None,
system: str = None,
id: Union[str, UUID] = uuid4(),
prime: bool = True,
Expand All @@ -40,13 +41,13 @@ def __init__(
):

client = Client()
system = self.build_system(character, system)
system_format = self.build_system(character, character_command, system)

sessions = {}
new_default_session = None
if default_session:
new_session = self.new_session(
return_session=True, system=system, id=id, **kwargs
return_session=True, system=system_format, id=id, **kwargs
)

new_default_session = new_session
Expand All @@ -56,7 +57,7 @@ def __init__(
client=client, default_session=new_default_session, sessions=sessions
)

if character or console:
if not system and console:
character = "ChatGPT" if not character else character
new_default_session.title = character
self.interactive_console(character=character, prime=prime)
Expand Down Expand Up @@ -153,7 +154,9 @@ def stream(
params=params,
)

def build_system(self, character: str = None, system: str = None) -> str:
def build_system(
self, character: str = None, character_command: str = None, system: str = None
) -> str:
default = "You are a helpful assistant."
if character:
character_prompt = """
Expand All @@ -163,11 +166,13 @@ def build_system(self, character: str = None, system: str = None) -> str:
- Concisely introduce yourself first in character.
"""
prompt = character_prompt.format(wikipedia_search_lookup(character)).strip()
if system:
if character_command:
character_system = """
- {0}
"""
prompt = prompt + "\n" + character_system.format(system).strip()
prompt = (
prompt + "\n" + character_system.format(character_command).strip()
)
return prompt
elif system:
return system
Expand Down

0 comments on commit 22d58d0

Please sign in to comment.