From 3f8b047558aa541474bf561aab432ade328c9768 Mon Sep 17 00:00:00 2001 From: Maria Mercado Date: Fri, 2 Aug 2024 10:06:47 -0700 Subject: [PATCH] feedback 2 --- ai/ai_utils/get_available_apis.py | 5 ++++- ai/ai_utils/handle_response.py | 6 +++++- ai/providers/anthropic.py | 2 +- ai/providers/base_provider.py | 7 ++++--- ai/providers/openai.py | 2 +- manifest.json | 2 +- requirements.txt | 2 +- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ai/ai_utils/get_available_apis.py b/ai/ai_utils/get_available_apis.py index dfb7bca..fff724c 100644 --- a/ai/ai_utils/get_available_apis.py +++ b/ai/ai_utils/get_available_apis.py @@ -2,7 +2,10 @@ from ai.providers.openai import OpenAI_API """ -New providers need to be added below +This file defines a function to retrieve available API models from different AI providers. +It imports specific AI provider classes and combines their available models into a single dictionary. + +New AI providers must be added below """ diff --git a/ai/ai_utils/handle_response.py b/ai/ai_utils/handle_response.py index fe93601..87955fd 100644 --- a/ai/ai_utils/handle_response.py +++ b/ai/ai_utils/handle_response.py @@ -5,7 +5,11 @@ from state_store.get_user_state import get_user_state """ -New providers need to be added below +This file defines functions to handle AI responses by interacting with different AI providers. +The `_get_provider()` function returns an instance of the appropriate API provider based on the given API name. +The `get_ai_response` function retrieves the user's selected API provider and model, sets the model, and generates a response. + +New AI providers must be added below """ diff --git a/ai/providers/anthropic.py b/ai/providers/anthropic.py index 42a3500..a46eb6e 100644 --- a/ai/providers/anthropic.py +++ b/ai/providers/anthropic.py @@ -28,7 +28,7 @@ def get_models(self): if self.api_key is not None: return self.MODELS else: - return None + return {} def generate_response(self, prompt: str, system_content: str) -> str: try: diff --git a/ai/providers/base_provider.py b/ai/providers/base_provider.py index e941a16..9e90916 100644 --- a/ai/providers/base_provider.py +++ b/ai/providers/base_provider.py @@ -1,13 +1,14 @@ +# A base class for API providers, defining the interface and common properties for subclasses. + + class BaseProvider: MODELS = {} - BASELINE_MAX_TOKENS: int - API_NAME: str def __init__(self): - self.current_model = None self.api_key: str def set_model(self, model_name: str): + self.current_model = model_name raise NotImplementedError("Subclass must implement set_model") def get_models(self): diff --git a/ai/providers/openai.py b/ai/providers/openai.py index 1d96a1e..bb2a586 100644 --- a/ai/providers/openai.py +++ b/ai/providers/openai.py @@ -25,7 +25,7 @@ def get_models(self): if self.api_key is not None: return self.MODELS else: - return None + return {} def generate_response(self, prompt: str, system_content: str) -> str: try: diff --git a/manifest.json b/manifest.json index 015e2d1..b30350a 100644 --- a/manifest.json +++ b/manifest.json @@ -105,4 +105,4 @@ "token_rotation_enabled": false, "function_runtime": "remote" } -} \ No newline at end of file +} diff --git a/requirements.txt b/requirements.txt index 2342ddd..3890f00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ flake8==7.1.0 black==24.4.2 slack-cli-hooks==0.0.2 openai==1.37.1 -anthropic==0.32.0 \ No newline at end of file +anthropic==0.32.0