diff --git a/llama.py b/llama.py index 44bd243..5749356 100644 --- a/llama.py +++ b/llama.py @@ -9,14 +9,22 @@ from inference import Inference, torch_reseed messages = [] inference = None +# systemmessage at the very begin of the chat. Will be concatenated with the automatic tool usage descriptions systemmessage = "Hold a casual conversation with the user. Keep responses short at max 3 sentences." +# system message for role flip so the model automatically answers for the user roleflip = {"role": "system", "content": "Keep the conversation going, ask for more information on the subject. Keep messages short at max 1-2 sentences. Do not thank and say goodbye."} +# system messages and user message to bring the model to summarize the entire conversation +summarize = {"role": "system", "content": "Summarize the conversation as a single, cohesive paragraph. Avoid using any bullet points, numbers, or list formatting. Write in plain text with natural sentences that flow together seamlessly."} +summarize_user = {"role": "system", "content": "Can you summarize the conversation?"} + +# system message to create a conversation title +title_prompt = {"role": "system", "content": "Please create a very short and descriptive title or label for this conversation. Maximum 2-5 words. Use only plain text, avoid numbering, special characters, or unnecessary formatting-focus on clarity and brevity."} + register_dummy() -# tool_functions = [current_time, random_float, random_int] @@ -126,6 +134,20 @@ def main(): messages = messages_backup + [last_message] append_generate_chat(None) # 'regular' chatbot answer + elif input_text.startswith("/summarize"): + messages_temp = list(filter(lambda x: x["role"] != "system", messages)) + messages_temp = [summarize] + messages_temp + [summarize_user] # copy dict in last instance + # messages_temp[-1]["role"] = "user" + input_ids = inference.tokenize(messages_temp, tokenize=True, assistant_prefix="The conversation was about ") + generated_tokens, full_output = inference.generate_incremental(input_ids) + + elif input_text.startswith("/title"): + messages_temp = list(filter(lambda x: x["role"] != "system", messages)) + messages_temp = [title_prompt] + messages_temp #+ [dict(title)] # copy dict in last instance + messages_temp[-1]["role"] = "user" + input_ids = inference.tokenize(messages_temp, tokenize=True, assistant_prefix="Title: ") + generated_tokens, full_output = inference.generate_incremental(input_ids) + elif input_text.startswith("/help"): print("! answer as 'tool' in tags") print("/clear clear chat history") @@ -134,6 +156,8 @@ def main(): print("/more generate more additional information") print("/file read prompt input from file") print("/auto automatically advance conversation") + print("/summarize generate a summary of the chat") + print("/title generate a title of the chat") print("/help print this message") print("")