diff --git a/py/ai.py b/py/ai.py index a8c5537..bfde713 100644 --- a/py/ai.py +++ b/py/ai.py @@ -1,6 +1,5 @@ from mistralai import Mistral from openai import OpenAI -import anthropic import ollama @@ -45,8 +44,7 @@ class AI: stream_response = client.chat.completions.create( model=model, - messages=messages, - stream=True + messages=messages ) with return_class.ai_response_lock: @@ -54,21 +52,4 @@ class AI: for chunk in stream_response: with return_class.ai_response_lock: - return_class.ai_response[access_token] += chunk.choices[0].delta.content - - @staticmethod - def process_anthropic(model, messages, return_class, access_token, api_key): - - client = anthropic.Anthropic(api_key=api_key) - - with return_class.ai_response_lock: - return_class.ai_response[access_token] = "" - - with client.messages.stream( - max_tokens=1024, - model=model, - messages=messages, - ) as stream: - for text in stream.text_stream: - with return_class.ai_response_lock: - return_class.ai_response[access_token] += text + return_class.ai_response[access_token] += chunk.choices[0].delta.content \ No newline at end of file diff --git a/py/api.py b/py/api.py index 55d0483..386cd4f 100644 --- a/py/api.py +++ b/py/api.py @@ -46,18 +46,6 @@ class API: thread.start() thread.join() return jsonify({'status': 200}) - elif model_type == "openai": - api_key = data.get('api_key') - thread = threading.Thread(target=self.ai.process_openai, args=(ai_model, messages, self, access_token, api_key)) - thread.start() - thread.join() - return jsonify({'status': 200}) - elif model_type == "anthropic": - api_key = data.get('api_key') - thread = threading.Thread(target=self.ai.process_anthropic, 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'}) diff --git a/py/requirements.txt b/py/requirements.txt index bd93ad7..3c2be3b 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -3,5 +3,4 @@ flask-cors ollama mistralai openai -anthropic pyOpenSSL \ No newline at end of file