From d83aeb2c7400ea4e99664822d2a7281b4f310254 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 30 Sep 2024 11:30:30 +0200 Subject: [PATCH] mild changes to the ais and added models to models.tsx --- app/components/Models.tsx | 12 ++++++++++++ py/ai.py | 9 ++------- py/api.py | 7 +++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/components/Models.tsx b/app/components/Models.tsx index fefd765..1f9dc56 100644 --- a/app/components/Models.tsx +++ b/app/components/Models.tsx @@ -4,6 +4,7 @@ import React, { useState, useEffect } from 'react'; // Define all models that should be available. const modelList = { 'Offline Fast': { + 'model_type': 'local', 'Math': 'qwen2-math:1.5b', 'Code': 'starcoder2', 'Language': 'llama3.2', @@ -14,6 +15,7 @@ const modelList = { 'Image': 'llava-phi3' }, 'Offline Slow': { + 'model_type': 'local', 'Math': 'wizard-math', 'Code': 'starcoder2:7b', 'Language': 'llama3.1', @@ -24,6 +26,7 @@ const modelList = { 'Image': 'llava' }, 'Offline Fast (FOSS)': { + 'model_type': 'local', 'Math': 'qwen2-math:1.5b', 'Code': 'qwen2.5-coder:1.5b', 'Language': 'phi3.5', @@ -34,6 +37,7 @@ const modelList = { 'Image': 'llava' }, 'Offline Slow (FOSS)': { + 'model_type': 'local', 'Math': 'mathstral', 'Code': 'qwen2.5-coder', 'Language': 'qwen2.5', @@ -44,6 +48,7 @@ const modelList = { 'Image': 'llava' }, 'Online Cheap (OpenAI)': { + 'model_type': 'openai', 'Math': 'gpt-4o-mini', 'Code': 'gpt-4o-mini', 'Language': 'gpt-4o-mini', @@ -54,6 +59,7 @@ const modelList = { 'Image': 'gpt-4o-mini' }, 'Online Expensive (OpenAI)': { + 'model_type': 'openai', 'Math': 'gpt-4o', 'Code': 'gpt-4o', 'Language': 'gpt-4o', @@ -64,6 +70,7 @@ const modelList = { 'Image': 'gpt-4o' }, 'Online Cheap (Anthropic)': { + 'model_type': 'anthropic', 'Math': 'claude-3-haiku', 'Code': 'claude-3-haiku', 'Language': 'claude-3-haiku', @@ -74,6 +81,7 @@ const modelList = { 'Image': 'claude-3-haiku' }, 'Online Expensive (Anthropic)': { + 'model_type': 'anthropic', 'Math': 'claude-3-5-sonnet', 'Code': 'claude-3-5-sonnet', 'Language': 'claude-3-5-sonnet', @@ -84,6 +92,7 @@ const modelList = { 'Image': 'claude-3-5-sonnet' }, 'Online Cheap (Google)': { + 'model_type': 'google', 'Math': 'gemini-1.5-flash-latest', 'Code': 'gemini-1.5-flash-latest', 'Language': 'gemini-1.5-flash-latest', @@ -94,6 +103,7 @@ const modelList = { 'Image': 'gemini-1.5-flash-latest' }, 'Online Expensive (Google)': { + 'model_type': 'google', 'Math': 'gemini-1.5-pro-latest', 'Code': 'gemini-1.5-pro-latest', 'Language': 'gemini-1.5-pro-latest', @@ -104,6 +114,7 @@ const modelList = { 'Image': 'gemini-1.5-pro-latest' }, 'Online (La Plateforme)': { + 'model_type': 'mistral', 'Math': 'open-mistral-nemo', 'Code': 'codestral-latest', 'Language': 'mistral-small-latest', @@ -114,6 +125,7 @@ const modelList = { 'Image': 'pixtral-12b-2409' }, 'Online (FOSS) (La Plateforme)': { + 'model_type': 'mistral', 'Math': 'open-mistral-nemo', 'Code': 'open-codestral-mamba', 'Language': 'open-mistral-nemo', diff --git a/py/ai.py b/py/ai.py index 5879e9d..2554fd5 100644 --- a/py/ai.py +++ b/py/ai.py @@ -80,11 +80,6 @@ class AI: message = messages[-1]['content'] messages.pop() - system = None - if messages and messages[0]['role'] == 'system': - system = messages[0]['content'] - messages.pop(0) - for msg in messages: msg['parts'] = msg.pop('content') @@ -97,8 +92,8 @@ class AI: model = genai.GenerativeModel(model) chat = model.start_chat( - system_instruction=system, - history=messages + history=messages, + ) response = chat.send_message(message, stream=True) diff --git a/py/api.py b/py/api.py index 84df891..75fbfd4 100644 --- a/py/api.py +++ b/py/api.py @@ -70,6 +70,13 @@ class API: thread.start() thread.join() return jsonify({'status': 200}) + elif model_type == "google": + api_key = data.get('api_key') + thread = threading.Thread(target=self.ai.process_google, + args=(ai_model, messages, self, access_token, api_key)) + thread.start() + thread.join() + return jsonify({'status': 200}) return jsonify({'status': 401, 'error': 'Invalid AI model type'})