Compare commits
No commits in common. "65ddc69be703331417f45bd4f12bc5f2cdf9900c" and "6e67349eb0eaf3c625c886813cf628db776a7737" have entirely different histories.
65ddc69be7
...
6e67349eb0
5 changed files with 13 additions and 40 deletions
29
py/ai.py
29
py/ai.py
|
@ -1,6 +1,5 @@
|
||||||
from mistralai import Mistral
|
from mistralai import Mistral
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
import google.generativeai as genai
|
|
||||||
import anthropic
|
import anthropic
|
||||||
import ollama
|
import ollama
|
||||||
|
|
||||||
|
@ -73,31 +72,3 @@ class AI:
|
||||||
for text in stream.text_stream:
|
for text in stream.text_stream:
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
return_class.ai_response[access_token] += text
|
return_class.ai_response[access_token] += text
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def process_google(model, messages, return_class, access_token, api_key):
|
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
for msg in messages:
|
|
||||||
if msg['role'] == 'assistant':
|
|
||||||
msg['role'] = 'model'
|
|
||||||
|
|
||||||
genai.configure(api_key=api_key)
|
|
||||||
model = genai.GenerativeModel("gemini-1.5-flash")
|
|
||||||
chat = model.start_chat(
|
|
||||||
system_instruction=system,
|
|
||||||
history=[
|
|
||||||
{"role": "user", "parts": "Hello"},
|
|
||||||
{"role": "model", "parts": "Great to meet you. What would you like to know?"},
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
13
py/api.py
13
py/api.py
|
@ -42,22 +42,19 @@ class API:
|
||||||
return jsonify({'status': 200})
|
return jsonify({'status': 200})
|
||||||
elif model_type == "mistral":
|
elif model_type == "mistral":
|
||||||
api_key = data.get('api_key')
|
api_key = data.get('api_key')
|
||||||
thread = threading.Thread(target=self.ai.process_mistralai,
|
thread = threading.Thread(target=self.ai.process_mistralai, args=(ai_model, messages, self, access_token, api_key))
|
||||||
args=(ai_model, messages, self, access_token, api_key))
|
|
||||||
thread.start()
|
thread.start()
|
||||||
thread.join()
|
thread.join()
|
||||||
return jsonify({'status': 200})
|
return jsonify({'status': 200})
|
||||||
elif model_type == "openai":
|
elif model_type == "openai":
|
||||||
api_key = data.get('api_key')
|
api_key = data.get('api_key')
|
||||||
thread = threading.Thread(target=self.ai.process_openai,
|
thread = threading.Thread(target=self.ai.process_openai, args=(ai_model, messages, self, access_token, api_key))
|
||||||
args=(ai_model, messages, self, access_token, api_key))
|
|
||||||
thread.start()
|
thread.start()
|
||||||
thread.join()
|
thread.join()
|
||||||
return jsonify({'status': 200})
|
return jsonify({'status': 200})
|
||||||
elif model_type == "anthropic":
|
elif model_type == "anthropic":
|
||||||
api_key = data.get('api_key')
|
api_key = data.get('api_key')
|
||||||
thread = threading.Thread(target=self.ai.process_anthropic,
|
thread = threading.Thread(target=self.ai.process_anthropic, args=(ai_model, messages, self, access_token, api_key))
|
||||||
args=(ai_model, messages, self, access_token, api_key))
|
|
||||||
thread.start()
|
thread.start()
|
||||||
thread.join()
|
thread.join()
|
||||||
return jsonify({'status': 200})
|
return jsonify({'status': 200})
|
||||||
|
@ -121,7 +118,3 @@ class API:
|
||||||
|
|
||||||
ssl_context = ("cert.pem", "key.pem")
|
ssl_context = ("cert.pem", "key.pem")
|
||||||
self.app.run(debug=True, host='0.0.0.0', port=5000)
|
self.app.run(debug=True, host='0.0.0.0', port=5000)
|
||||||
|
|
||||||
|
|
||||||
api = API()
|
|
||||||
api.run()
|
|
||||||
|
|
|
@ -5,3 +5,4 @@ mistralai
|
||||||
openai
|
openai
|
||||||
anthropic
|
anthropic
|
||||||
pyOpenSSL
|
pyOpenSSL
|
||||||
|
pywebview
|
7
py/run.py
Normal file
7
py/run.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import os
|
||||||
|
import webview
|
||||||
|
|
||||||
|
os.system("python api.py")
|
||||||
|
webview.create_window('Hello world', 'http://localhost:3000')
|
||||||
|
webview.start()
|
||||||
|
|
1
py/webapp.py
Normal file
1
py/webapp.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
Loading…
Reference in a new issue