diff --git a/py/api.py b/py/api.py index d3db341..4290692 100644 --- a/py/api.py +++ b/py/api.py @@ -17,11 +17,11 @@ class API: # This method processes a message via ollama @staticmethod - def process_text_local(prompt, model): + def process_text_local(prompt, model, system): ollama_url = "http://localhost:11434" response = requests.post( - f"{ollama_url}/api/generate", json={"model": model, "prompt": prompt} + f"{ollama_url}/api/generate", json={"model": model, "prompt": prompt, "system": system} ) if response.status_code == 200: @@ -37,15 +37,17 @@ class API: return "Error: " + response.text # This method sends a message to a certain AI. - def send_message(self, message, model): + + + def send_message(self, message, model, system): if model == 1: - answer = self.process_text_local(message, "phi3.5") + answer = self.process_text_local(message, "phi3.5", system) elif model == 2: - answer = self.process_text_local(message, "gemma2:2b") + answer = self.process_text_local(message, "gemma2:2b", system) elif model == 3: - answer = self.process_text_local(message, "qwen2:0.5b") + answer = self.process_text_local(message, "qwen2:0.5b", system) elif model == 4: - answer = self.process_text_local(message, "codegemma:2b") + answer = self.process_text_local(message, "codegemma:2b", system) elif model == 5: answer = self.process_text_transformers(message, "meta-llama/Meta-Llama-3.1-8B") else: diff --git a/py/web_flask.py b/py/web_flask.py index cf58011..a3a5eea 100644 --- a/py/web_flask.py +++ b/py/web_flask.py @@ -13,6 +13,8 @@ messages = [] @APP.route('/', methods=['GET', 'POST']) def index(): global messages + system_prompt = 'You are a helpful assistant.' + system = 'Your system prompt is: \"'+system_prompt+'\" The following is your chat log so far: \n' if request.method == 'POST': option = request.form['option'] @@ -25,7 +27,12 @@ def index(): elif option == "chat": messages.append(f"User: {user_message}") - ai_response = "AI: " + api.send_message(user_message, 3) + for line in messages: + system += line + '\n' + + system += "The chat log is now finished." + + ai_response = "AI: " + api.send_message(user_message, 5, system) messages.append(ai_response) return render_template('index.html', messages=messages)