-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Models fixes #1126
Models fixes #1126
Changes from 6 commits
b63b759
47e676d
8267b8a
6b90e33
b84fdd6
815d518
4067eeb
dc294a9
6d105a4
a68a7f5
a01cc86
a1a9f3c
5d701b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from sqlalchemy.sql import func | ||
from typing import List, Dict, Union | ||
from superagi.models.base_model import DBBaseModel | ||
from superagi.helper.encyption_helper import encrypt_data, decrypt_data | ||
import requests, logging | ||
|
||
# marketplace_url = "https://app.superagi.com/api" | ||
|
@@ -201,3 +202,48 @@ def fetch_model_details(cls, session, organisation_id, model_id: int) -> Dict[st | |
except Exception as e: | ||
logging.error(f"Unexpected Error Occured: {e}") | ||
return {"error": "Unexpected Error Occured"} | ||
|
||
@classmethod | ||
def validate_model_in_db(cls, session, organisation_id, model): | ||
try: | ||
from superagi.models.models_config import ModelsConfig | ||
from superagi.models.configuration import Configuration | ||
|
||
models = {"gpt-3.5-turbo-0301": 4032, "gpt-4-0314": 8092, "gpt-3.5-turbo": 4032, | ||
"gpt-4": 8092, "gpt-3.5-turbo-16k": 16184, "gpt-4-32k": 32768} | ||
|
||
model_config = session.query(Models).filter(Models.model_name == model, | ||
Models.org_id == organisation_id).first() | ||
if model_config is None: | ||
model_provider = session.query(ModelsConfig).filter(ModelsConfig.provider == "OpenAI", | ||
ModelsConfig.org_id == organisation_id).first() | ||
|
||
if model_provider is None: | ||
configurations = session.query(Configuration).filter(Configuration.key == 'model_api_key', | ||
Configuration.organisation_id == organisation_id).first() | ||
model_api_key = decrypt_data(configurations.value) | ||
|
||
if configurations is None: | ||
return {"error": "Model not found and the API Key is missing"} | ||
|
||
model_details = ModelsConfig.store_api_key(session, organisation_id, "OpenAI", model_api_key) | ||
|
||
# Get 'model_provider_id' | ||
model_provider_id = model_details.get('model_provider_id') | ||
|
||
result = cls.store_model_details(session, organisation_id, model, model, '', | ||
model_provider_id, models[model], 'Custom', '') | ||
if result is not None: | ||
return {"success": "Model was not Installed, so I have dont it for you"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle using HTTP code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use HTTP Exception |
||
|
||
else: | ||
result = cls.store_model_details(session, organisation_id, model, model, '', | ||
model_provider.id, models[model], 'Custom', '') | ||
if result is not None: | ||
return {"success": "Model was not Installed, so I have dont it for you"} | ||
|
||
else: | ||
return {"success": "Model is found"} | ||
|
||
except Exception as e: | ||
logging.error(f"Unexpected Error occurred while Validating GPT Models: {e}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,14 +76,17 @@ def store_api_key(cls, session, organisation_id, model_provider, model_api_key): | |
ModelsConfig.provider == model_provider)).first() | ||
if existing_entry: | ||
existing_entry.api_key = encrypt_data(model_api_key) | ||
session.commit() | ||
result = {'message': 'The API key was successfully updated'} | ||
else: | ||
new_entry = ModelsConfig(org_id=organisation_id, provider=model_provider, | ||
api_key=encrypt_data(model_api_key)) | ||
session.add(new_entry) | ||
session.commit() | ||
session.flush() | ||
result = {'message': 'The API key was successfully stored', 'model_provider_id': new_entry.id} | ||
|
||
session.commit() | ||
|
||
return {'message': 'The API key was successfully stored'} | ||
return result | ||
|
||
@classmethod | ||
def fetch_api_keys(cls, session, organisation_id): | ||
|
@@ -107,6 +110,8 @@ def fetch_api_key(cls, session, organisation_id, model_provider): | |
if api_key_data is None: | ||
return [] | ||
else: | ||
print("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove print |
||
print(decrypt_data(api_key_data.api_key)) | ||
api_key = [{'id': api_key_data.id, 'provider': api_key_data.provider, | ||
'api_key': decrypt_data(api_key_data.api_key)}] | ||
return api_key | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the imports to top of the file.