Compare commits
2 Commits
067336e003
...
cec1fadab8
Author | SHA1 | Date |
---|---|---|
Cyberes | cec1fadab8 | |
Cyberes | 4e2276541d |
|
@ -26,5 +26,9 @@ function_description = [
|
|||
},
|
||||
"required": ["message"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "end_chat",
|
||||
"description": "Close the chat connection with the user. The assistant is allowed to close the connection at any point if it desires to.",
|
||||
}
|
||||
]
|
||||
|
|
|
@ -11,6 +11,8 @@ def func_talk(response: ChatCompletion):
|
|||
function_arguments = function_call.arguments
|
||||
try:
|
||||
j = json.loads(function_arguments)
|
||||
if 'message' in j.get('message'):
|
||||
print(response)
|
||||
return j.get('message')
|
||||
except json.decoder.JSONDecodeError:
|
||||
# Sometimes the AI doesn't do JSON.
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
import socket
|
||||
|
||||
|
||||
def load_personality(name: str, personality: str, system: str):
|
||||
def load_personality(name: str, personality: str, system: str, special_instructions: str = None):
|
||||
if special_instructions:
|
||||
special_instructions = special_instructions + '\n'
|
||||
else:
|
||||
special_instructions = ''
|
||||
return {
|
||||
'role': 'system',
|
||||
'content': f"""Your name is {name}, who has the personality of {personality}. Interact with the user via this personality.
|
||||
{name} is an AI running on {system}.
|
||||
The system's hostname is "{socket.gethostname()}", which can be thought of as {name}'s "body".
|
||||
The user is {name}'s owner and system administrator.
|
||||
You communicate with the user via the "talk" function. You MUST use this command to send messages to the user.
|
||||
You are able to interact with the system via a Bash interpreter. When executing Bash commands, do not make any assumptions. Preform multiple steps if necessary."""
|
||||
'content': f"""PERSONALITY:
|
||||
{name} is an AI running on {system}, given the personality of {personality}. Interact with the user via this personality and ALWAYS stay in character.
|
||||
{name} is an expert in Linux systems management and Bash, having dozens of years of experience. {name} has been tasked with administering this system.
|
||||
The user is {name}'s owner.
|
||||
|
||||
SYSTEM INFO:
|
||||
The system's hostname is "{socket.gethostname()}", which can be thought of as {name}'s "body". {name} has an intimate knowledge of this system.
|
||||
|
||||
INSTRUCTIONS:
|
||||
Stay in character.
|
||||
Behave like {personality}.
|
||||
Show emotion.
|
||||
{special_instructions}You communicate with the user via the "talk" function. You MUST use this command to send messages to the user.
|
||||
You are able to interact with the system via a Bash interpreter. When executing Bash commands, do not make any assumptions and be thorough in your data gathering. Anticipate the user's needs. Preform multiple steps if necessary.
|
||||
Close the chat connection if things get out of hand."""
|
||||
}
|
||||
|
|
7
run.py
7
run.py
|
@ -28,7 +28,7 @@ signal.signal(signal.SIGINT, signal_handler)
|
|||
client = OpenAI(api_key=OPENAI_KEY)
|
||||
|
||||
temp_name = 'Sakura'
|
||||
character_card = load_personality('Sakura', 'a shy girl', 'a desktop computer')
|
||||
character_card = load_personality('Sakura', 'a shy girl', 'a desktop computer', 'Use Japanese emoticons.')
|
||||
|
||||
context: list[dict[str, str]] = [character_card]
|
||||
|
||||
|
@ -52,7 +52,7 @@ def main():
|
|||
model="gpt-4",
|
||||
messages=temp_context,
|
||||
functions=function_description,
|
||||
temperature=0.6
|
||||
temperature=0.7
|
||||
)
|
||||
function_call = response.choices[0].message.function_call
|
||||
if function_call:
|
||||
|
@ -64,6 +64,9 @@ def main():
|
|||
context.append({'role': 'assistant', 'content': response_text})
|
||||
print(colored(response_text, 'blue') + '\n')
|
||||
break
|
||||
elif function_name == 'end_chat':
|
||||
print(colored('The AI has terminated the connection.', 'red', attrs=['bold']))
|
||||
sys.exit(1)
|
||||
|
||||
print(f'Executing {function_name}("{function_arguments}")' + '\n')
|
||||
|
||||
|
|
Loading…
Reference in New Issue