Skip to content
Open
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
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"python.defaultInterpreterPath": "${workspaceFolder}/api/.venv/bin/python",
"python.analysis.extraPaths": [
"${workspaceFolder}/api"
],
"python.autoComplete.extraPaths": [
"${workspaceFolder}/api"
]
}

44 changes: 44 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,45 @@ def load_lang_config():

return loaded_config

# Load API keys configuration
def load_api_keys_config():
"""
Load API keys configuration, support configuration file and environment variable fallback

Returns format:
{
"google": ["key1", "key2"],
"openai": ["key1"],
...
}
"""
api_keys_config = load_json_config("api_keys.json")

result = {}
for provider_id, config in api_keys_config.items():
keys = config.get("keys", [])

# If keys are not present in the configuration file, try reading from environment variables
if not keys:
env_var_name = f"{provider_id.upper()}_API_KEYS"
env_value = os.environ.get(env_var_name)
if env_value:
keys = [k.strip() for k in env_value.split(',')]
else:
# If keys array element contains comma, split it into multiple keys
expanded_keys = []
for key in keys:
if isinstance(key, str) and ',' in key:
# This is a comma-separated string, split it
expanded_keys.extend([k.strip() for k in key.split(',') if k.strip()])
elif key: # Ignore empty strings
expanded_keys.append(key)
keys = expanded_keys

result[provider_id] = keys

return result

# Default excluded directories and files
DEFAULT_EXCLUDED_DIRS: List[str] = [
# Virtual environments and package managers
Expand Down Expand Up @@ -333,6 +372,7 @@ def load_lang_config():
embedder_config = load_embedder_config()
repo_config = load_repo_config()
lang_config = load_lang_config()
api_keys_config = load_api_keys_config()

# Update configuration
if generator_config:
Expand All @@ -355,6 +395,10 @@ def load_lang_config():
if lang_config:
configs["lang_config"] = lang_config

# Update API keys configuration
if api_keys_config:
configs["api_keys"] = api_keys_config


def get_model_config(provider="google", model=None):
"""
Expand Down
20 changes: 20 additions & 0 deletions api/config/api_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"google": {
"keys": ["${GOOGLE_API_KEYS}"]
},
"openai": {
"keys": ["${OPENAI_API_KEYS}"]
},
"openrouter": {
"keys": ["${OPENROUTER_API_KEYS}"]
},
"azure": {
"keys": ["${AZURE_OPENAI_API_KEYS}"]
},
"bedrock": {},
"dashscope": {
"keys": ["${DASHSCOPE_API_KEYS}"]
},
"ollama": {}
}

2 changes: 1 addition & 1 deletion api/config/generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
},
"openai": {
"default_model": "gpt-5-nano",
"default_model": "gpt-4.1",
"supportsCustomModel": true,
"models": {
"gpt-5": {
Expand Down
Loading