|
27 | 27 | # limitations under the License. |
28 | 28 |
|
29 | 29 | import json |
| 30 | +import logging |
30 | 31 | import os |
31 | 32 | from datetime import datetime |
32 | 33 | from typing import Dict, List, Any, Optional |
|
35 | 36 | import requests |
36 | 37 | from litellm import model_cost |
37 | 38 |
|
| 39 | +# Suppress litellm's verbose warnings and debug output |
| 40 | +litellm.suppress_debug_info = True |
| 41 | +logging.getLogger("LiteLLM").setLevel(logging.ERROR) |
| 42 | + |
38 | 43 | # --- Manual Override for Context Windows --- |
39 | 44 | # For models where litellm's data might be ambiguous or incorrect, |
40 | 45 | # we define the correct context window size here. |
@@ -289,10 +294,19 @@ def generate_model_specs(models, provider, mode, blocklist=None, tag_rules=None) |
289 | 294 | def create_openai_config(): |
290 | 295 | provider = "openai" |
291 | 296 |
|
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 | + ] |
296 | 310 |
|
297 | 311 | # Define tag rules |
298 | 312 | completion_tag_rules = { |
@@ -903,7 +917,13 @@ def create_openrouter_config(): |
903 | 917 | if data is None: |
904 | 918 | try: |
905 | 919 | 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') |
906 | 923 | 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") |
907 | 927 | with open(openrouter_file, 'r', encoding='utf-8') as f: |
908 | 928 | data = json.load(f) |
909 | 929 | print("✅ Successfully loaded OpenRouter models from local file") |
@@ -991,13 +1011,6 @@ def create_provider_config(): |
991 | 1011 | No need to pass parameters - block lists and tag rules are defined in each provider function. |
992 | 1012 | """ |
993 | 1013 |
|
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 | | - |
1001 | 1014 | # Generate provider configurations |
1002 | 1015 | result = [ |
1003 | 1016 | create_openai_config(), |
@@ -1164,33 +1177,28 @@ def main(): |
1164 | 1177 | """Main function to generate model configuration and SQL script""" |
1165 | 1178 | try: |
1166 | 1179 | 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)") |
1172 | 1181 | print() |
1173 | 1182 |
|
1174 | 1183 | providers_data = create_provider_config() |
1175 | 1184 |
|
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...") |
1177 | 1197 | sql_script = generate_sql_script(providers_data) |
1178 | 1198 |
|
1179 | 1199 | save_sql_to_file(sql_script) |
1180 | 1200 |
|
1181 | 1201 | 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']}") |
1194 | 1202 |
|
1195 | 1203 | except Exception as e: |
1196 | 1204 | print(f"❌ Error generating SQL script: {e}") |
|
0 commit comments