This commit is contained in:
Patrick_Pluto 2024-09-17 08:18:19 +02:00
parent 164b1288e1
commit e1df8869fb
2 changed files with 17 additions and 8 deletions

View file

@ -17,11 +17,11 @@ class API:
# This method processes a message via ollama # This method processes a message via ollama
@staticmethod @staticmethod
def process_text_local(prompt, model): def process_text_local(prompt, model, system):
ollama_url = "http://localhost:11434" ollama_url = "http://localhost:11434"
response = requests.post( 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: if response.status_code == 200:
@ -37,15 +37,17 @@ class API:
return "Error: " + response.text return "Error: " + response.text
# This method sends a message to a certain AI. # 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: if model == 1:
answer = self.process_text_local(message, "phi3.5") answer = self.process_text_local(message, "phi3.5", system)
elif model == 2: elif model == 2:
answer = self.process_text_local(message, "gemma2:2b") answer = self.process_text_local(message, "gemma2:2b", system)
elif model == 3: 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: elif model == 4:
answer = self.process_text_local(message, "codegemma:2b") answer = self.process_text_local(message, "codegemma:2b", system)
elif model == 5: elif model == 5:
answer = self.process_text_transformers(message, "meta-llama/Meta-Llama-3.1-8B") answer = self.process_text_transformers(message, "meta-llama/Meta-Llama-3.1-8B")
else: else:

View file

@ -13,6 +13,8 @@ messages = []
@APP.route('/', methods=['GET', 'POST']) @APP.route('/', methods=['GET', 'POST'])
def index(): def index():
global messages 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': if request.method == 'POST':
option = request.form['option'] option = request.form['option']
@ -25,7 +27,12 @@ def index():
elif option == "chat": elif option == "chat":
messages.append(f"User: {user_message}") 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) messages.append(ai_response)
return render_template('index.html', messages=messages) return render_template('index.html', messages=messages)