Skip to content

Commit 133f308

Browse files
committed
feat: update
1 parent ad093c8 commit 133f308

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

aperag/migration/sql/model_configs_init.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Model configuration initialization SQL script
2-
-- Generated directly from configuration data on 2026-03-03 14:09:57
2+
-- Generated directly from configuration data on 2026-03-03 14:16:57
33
-- This script populates llm_provider and llm_provider_models tables
44

55
BEGIN;
@@ -10236,6 +10236,6 @@ ON CONFLICT (provider_name, api, model) DO UPDATE SET
1023610236

1023710237
COMMIT;
1023810238

10239-
-- Script completed. Generated on 2026-03-03 14:09:57
10239+
-- Script completed. Generated on 2026-03-03 14:16:57
1024010240
-- Total providers: 9
1024110241
-- Total models: 670

models/generate_model_configs.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# limitations under the License.
2828

2929
import json
30+
import logging
3031
import os
3132
from datetime import datetime
3233
from typing import Dict, List, Any, Optional
@@ -35,6 +36,10 @@
3536
import requests
3637
from litellm import model_cost
3738

39+
# Suppress litellm's verbose warnings and debug output
40+
litellm.suppress_debug_info = True
41+
logging.getLogger("LiteLLM").setLevel(logging.ERROR)
42+
3843
# --- Manual Override for Context Windows ---
3944
# For models where litellm's data might be ambiguous or incorrect,
4045
# we define the correct context window size here.
@@ -289,10 +294,19 @@ def generate_model_specs(models, provider, mode, blocklist=None, tag_rules=None)
289294
def create_openai_config():
290295
provider = "openai"
291296

292-
# Define blocklists
293-
completion_blocklist = []
294-
embedding_blocklist = []
295-
rerank_blocklist = []
297+
# Define blocklists - deprecated/instruct models not in litellm's model_prices_and_context_window.json
298+
completion_blocklist = [
299+
"babbage-002", "davinci-002", "ft:babbage-002", "ft:davinci-002",
300+
"gpt-3.5-turbo-instruct", "gpt-3.5-turbo-instruct-0914",
301+
]
302+
embedding_blocklist = [
303+
"babbage-002", "davinci-002", "ft:babbage-002", "ft:davinci-002",
304+
"gpt-3.5-turbo-instruct", "gpt-3.5-turbo-instruct-0914",
305+
]
306+
rerank_blocklist = [
307+
"babbage-002", "davinci-002", "ft:babbage-002", "ft:davinci-002",
308+
"gpt-3.5-turbo-instruct", "gpt-3.5-turbo-instruct-0914",
309+
]
296310

297311
# Define tag rules
298312
completion_tag_rules = {
@@ -903,7 +917,13 @@ def create_openrouter_config():
903917
if data is None:
904918
try:
905919
if os.path.exists(openrouter_file):
920+
file_mtime = os.path.getmtime(openrouter_file)
921+
file_age_days = (datetime.now().timestamp() - file_mtime) / 86400
922+
file_date = datetime.fromtimestamp(file_mtime).strftime('%Y-%m-%d')
906923
print(f"📁 Reading OpenRouter models from local file: {openrouter_file}")
924+
print(f" (cached on {file_date}, {file_age_days:.0f} days ago)")
925+
if file_age_days > 30:
926+
print(f"⚠️ Warning: local cache is {file_age_days:.0f} days old — consider refreshing via VPN or proxy")
907927
with open(openrouter_file, 'r', encoding='utf-8') as f:
908928
data = json.load(f)
909929
print("✅ Successfully loaded OpenRouter models from local file")
@@ -991,13 +1011,6 @@ def create_provider_config():
9911011
No need to pass parameters - block lists and tag rules are defined in each provider function.
9921012
"""
9931013

994-
print("\n📋 Block List Usage:")
995-
print("- Block lists and tag rules are now defined internally in each provider function")
996-
print("- To modify block lists or tag rules, edit the provider functions directly")
997-
print("- Each provider supports completion_blocklist, embedding_blocklist, and rerank_blocklist")
998-
print("- Tag rules map tag names to model name patterns")
999-
print()
1000-
10011014
# Generate provider configurations
10021015
result = [
10031016
create_openai_config(),
@@ -1164,33 +1177,28 @@ def main():
11641177
"""Main function to generate model configuration and SQL script"""
11651178
try:
11661179
print("Generating model configuration data...")
1167-
print("\n📋 Block List Usage:")
1168-
print("- Block lists and tag rules are now defined internally in each provider function")
1169-
print("- To modify block lists or tag rules, edit the provider functions directly")
1170-
print("- Each provider supports completion_blocklist, embedding_blocklist, and rerank_blocklist")
1171-
print("- Tag rules map tag names to model name patterns")
1180+
print(" (Block lists and tag rules are defined internally in each provider function)")
11721181
print()
11731182

11741183
providers_data = create_provider_config()
11751184

1176-
print("Generating SQL script...")
1185+
print("\n📊 Summary:")
1186+
total_models = 0
1187+
for p in providers_data:
1188+
completion = len(p.get('completion', []))
1189+
embedding = len(p.get('embedding', []))
1190+
rerank = len(p.get('rerank', []))
1191+
subtotal = completion + embedding + rerank
1192+
total_models += subtotal
1193+
print(f" {p['label']:<20} completion={completion:>4} embedding={embedding:>3} rerank={rerank:>3}")
1194+
print(f" {'TOTAL':<20} {total_models} models across {len(providers_data)} providers")
1195+
1196+
print("\nGenerating SQL script...")
11771197
sql_script = generate_sql_script(providers_data)
11781198

11791199
save_sql_to_file(sql_script)
11801200

11811201
print("✅ Model configuration SQL script generated successfully!")
1182-
print("\nTo execute the script:")
1183-
print(" psql -h <host> -U <user> -d <database> -f aperag/sql/model_configs_init.sql")
1184-
print("\nOr copy the contents and run in your PostgreSQL client.")
1185-
1186-
print("\n🔧 Usage Examples:")
1187-
print("1. To customize block lists or tag rules:")
1188-
print(" Edit the block list and tag rule variables in each provider function")
1189-
print("2. To add/remove models from block lists:")
1190-
print(" Modify the completion_blocklist, embedding_blocklist, or rerank_blocklist in provider functions")
1191-
print("3. To add/modify model tags:")
1192-
print(" Update the tag_rules dictionaries in provider functions")
1193-
print(" Example: completion_tag_rules = {'enable_for_collection': ['model1', 'model2'], 'free': ['model3']}")
11941202

11951203
except Exception as e:
11961204
print(f"❌ Error generating SQL script: {e}")

0 commit comments

Comments
 (0)