Skip to content
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 #1147

Merged
merged 21 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions gui/pages/Content/Agents/AgentCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ export default function AgentCreate({
useEffect(() => {
getOrganisationConfig(organisationId, "model_api_key")
.then((response) => {
const apiKey = response.data.value
setHasAPIkey(!(apiKey === null || apiKey.replace(/\s/g, '') === ''));
console.log(response.data['api_key'])
const apiKey = response.data['api_key']
setHasAPIkey(!(apiKey === null));
})
.catch((error) => {
console.error('Error fetching project:', error);
Expand Down Expand Up @@ -455,7 +456,7 @@ export default function AgentCreate({

const validateAgentData = (isNewAgent) => {
if (isNewAgent && !hasAPIkey) {
toast.error("Your OpenAI/Palm API key is empty!", {autoClose: 1800});
toast.error("Your API key is empty!", {autoClose: 1800});
openNewTab(-3, "Settings", "Settings", false);
return false;
}
Expand Down
15 changes: 4 additions & 11 deletions superagi/controllers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fastapi import APIRouter
from pydantic import BaseModel

from superagi.models.models_config import ModelsConfig
from superagi.models.configuration import Configuration
from superagi.models.organisation import Organisation
from fastapi_sqlalchemy import db
Expand Down Expand Up @@ -106,9 +107,8 @@ def get_config_by_organisation_id_and_key(organisation_id: int, key: str,
if not db_organisation:
raise HTTPException(status_code=404, detail="Organisation not found")

config = db.session.query(Configuration).filter(Configuration.organisation_id == organisation_id,
Configuration.key == key).first()
if config is None and key == "model_api_key":
config = db.session.query(ModelsConfig).filter(ModelsConfig.org_id == organisation_id, ModelsConfig.provider == 'OpenAI').first()
if config is None:
api_key = get_config("OPENAI_API_KEY") or get_config("PALM_API_KEY")
if (api_key is not None and api_key != "YOUR_OPEN_API_KEY") or (
api_key is not None and api_key != "YOUR_PALM_API_KEY"):
Expand All @@ -118,17 +118,10 @@ def get_config_by_organisation_id_and_key(organisation_id: int, key: str,
db.session.commit()
db.session.flush()
return new_config
return config

# Decrypt the API key
if config is not None and config.key == "model_api_key":
if config.value is not None:
decrypted_data = decrypt_data(config.value)
config.value = decrypted_data

return config



@router.get("/get/organisation/{organisation_id}", status_code=201)
def get_config_by_organisation_id(organisation_id: int,
Authorize: AuthJWT = Depends(check_auth)):
Expand Down