LIANJie-Jason Claude Opus 4.6 commited on
Commit
112b4f4
·
1 Parent(s): b71f629

fix: curated model lists, reasoning model token scaling, skip temp files

Browse files

- Restrict each provider to 3 supported models instead of fetching all
from API (OpenAI: gpt-4.1/4o/4o-mini, Anthropic: sonnet/opus/haiku,
Gemini: 2.5-pro/2.5-flash/2.0-flash)
- Scale up max_completion_tokens 4x for OpenAI reasoning models (o1/o3/o4)
since reasoning tokens count against the budget
- Skip ~$ temp Excel files during ingestion
- Log LLM errors in codebook description generation for debugging

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

setup.py CHANGED
@@ -144,7 +144,7 @@ def run_wizard():
144
  except Exception:
145
  print(f" Warning: Could not validate API key for {provider}. Using default model list.")
146
  fallback = {
147
- "openai": ["gpt-4o", "gpt-4o-mini", "gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano"],
148
  "anthropic": ["claude-sonnet-4-6", "claude-opus-4-6", "claude-haiku-4-5"],
149
  "gemini": ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"],
150
  }
 
144
  except Exception:
145
  print(f" Warning: Could not validate API key for {provider}. Using default model list.")
146
  fallback = {
147
+ "openai": ["gpt-4.1", "gpt-4o", "gpt-4o-mini"],
148
  "anthropic": ["claude-sonnet-4-6", "claude-opus-4-6", "claude-haiku-4-5"],
149
  "gemini": ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"],
150
  }
src/ingest.py CHANGED
@@ -106,7 +106,7 @@ def discover_files(documents_dir: str) -> list[tuple[Path, str]]:
106
  continue
107
  if file_path.suffix.lower() not in supported:
108
  continue
109
- if file_path.name.startswith("."):
110
  continue
111
 
112
  rel = file_path.relative_to(root)
 
106
  continue
107
  if file_path.suffix.lower() not in supported:
108
  continue
109
+ if file_path.name.startswith(".") or file_path.name.startswith("~$"):
110
  continue
111
 
112
  rel = file_path.relative_to(root)
src/llm/anthropic.py CHANGED
@@ -1,5 +1,5 @@
1
  """Anthropic LLM provider."""
2
- FALLBACK_MODELS = ["claude-sonnet-4-6", "claude-opus-4-6", "claude-haiku-4-5"]
3
 
4
  def generate(system_prompt: str, user_message: str, api_key: str,
5
  model: str = None, temperature: float = 0.0,
@@ -21,10 +21,4 @@ def generate(system_prompt: str, user_message: str, api_key: str,
21
  raise RuntimeError(f"Anthropic API error ({error_type}). Check your API key and network connection.") from e
22
 
23
  def list_models(api_key: str) -> list[str]:
24
- try:
25
- from anthropic import Anthropic
26
- client = Anthropic(api_key=api_key)
27
- models = client.models.list()
28
- return sorted([m.id for m in models.data])
29
- except Exception:
30
- return FALLBACK_MODELS
 
1
  """Anthropic LLM provider."""
2
+ SUPPORTED_MODELS = ["claude-sonnet-4-6", "claude-opus-4-6", "claude-haiku-4-5"]
3
 
4
  def generate(system_prompt: str, user_message: str, api_key: str,
5
  model: str = None, temperature: float = 0.0,
 
21
  raise RuntimeError(f"Anthropic API error ({error_type}). Check your API key and network connection.") from e
22
 
23
  def list_models(api_key: str) -> list[str]:
24
+ return list(SUPPORTED_MODELS)
 
 
 
 
 
 
src/llm/gemini.py CHANGED
@@ -1,5 +1,5 @@
1
  """Google Gemini LLM provider."""
2
- FALLBACK_MODELS = ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"]
3
 
4
  def generate(system_prompt: str, user_message: str, api_key: str,
5
  model: str = None, temperature: float = 0.0,
@@ -26,14 +26,4 @@ def generate(system_prompt: str, user_message: str, api_key: str,
26
  return "[Gemini error: request failed]"
27
 
28
  def list_models(api_key: str) -> list[str]:
29
- try:
30
- import google.generativeai as genai
31
- genai.configure(api_key=api_key)
32
- models = genai.list_models()
33
- chat_models = sorted([
34
- m.name.replace("models/", "") for m in models
35
- if "generateContent" in (m.supported_generation_methods or [])
36
- ])
37
- return chat_models if chat_models else FALLBACK_MODELS
38
- except Exception:
39
- return FALLBACK_MODELS
 
1
  """Google Gemini LLM provider."""
2
+ SUPPORTED_MODELS = ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"]
3
 
4
  def generate(system_prompt: str, user_message: str, api_key: str,
5
  model: str = None, temperature: float = 0.0,
 
26
  return "[Gemini error: request failed]"
27
 
28
  def list_models(api_key: str) -> list[str]:
29
+ return list(SUPPORTED_MODELS)
 
 
 
 
 
 
 
 
 
 
src/llm/openai.py CHANGED
@@ -1,5 +1,5 @@
1
  """OpenAI LLM provider."""
2
- FALLBACK_MODELS = ["gpt-4o", "gpt-4o-mini", "gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano"]
3
 
4
  def generate(system_prompt: str, user_message: str, api_key: str,
5
  model: str = None, temperature: float = 0.0,
@@ -10,6 +10,9 @@ def generate(system_prompt: str, user_message: str, api_key: str,
10
  is_reasoning = model.startswith(("o1", "o3", "o4"))
11
  try:
12
  if is_reasoning:
 
 
 
13
  messages = [
14
  {"role": "developer", "content": system_prompt},
15
  {"role": "user", "content": user_message},
@@ -17,7 +20,7 @@ def generate(system_prompt: str, user_message: str, api_key: str,
17
  response = client.chat.completions.create(
18
  model=model,
19
  messages=messages,
20
- max_completion_tokens=max_tokens,
21
  )
22
  else:
23
  messages = [
@@ -38,11 +41,4 @@ def generate(system_prompt: str, user_message: str, api_key: str,
38
  raise RuntimeError(f"OpenAI API error ({error_type}). Check your API key and network connection.") from e
39
 
40
  def list_models(api_key: str) -> list[str]:
41
- try:
42
- from openai import OpenAI
43
- client = OpenAI(api_key=api_key)
44
- models = client.models.list()
45
- chat_models = sorted([m.id for m in models if "gpt" in m.id or m.id.startswith(("o1", "o3", "o4"))])
46
- return chat_models if chat_models else FALLBACK_MODELS
47
- except Exception:
48
- return FALLBACK_MODELS
 
1
  """OpenAI LLM provider."""
2
+ SUPPORTED_MODELS = ["gpt-4.1", "gpt-4o", "gpt-4o-mini"]
3
 
4
  def generate(system_prompt: str, user_message: str, api_key: str,
5
  model: str = None, temperature: float = 0.0,
 
10
  is_reasoning = model.startswith(("o1", "o3", "o4"))
11
  try:
12
  if is_reasoning:
13
+ # Reasoning models include thinking tokens in max_completion_tokens,
14
+ # so we need a larger budget to get enough output tokens.
15
+ reasoning_budget = max(max_tokens * 4, 4096)
16
  messages = [
17
  {"role": "developer", "content": system_prompt},
18
  {"role": "user", "content": user_message},
 
20
  response = client.chat.completions.create(
21
  model=model,
22
  messages=messages,
23
+ max_completion_tokens=reasoning_budget,
24
  )
25
  else:
26
  messages = [
 
41
  raise RuntimeError(f"OpenAI API error ({error_type}). Check your API key and network connection.") from e
42
 
43
  def list_models(api_key: str) -> list[str]:
44
+ return list(SUPPORTED_MODELS)
 
 
 
 
 
 
 
src/sql_ingest.py CHANGED
@@ -263,7 +263,8 @@ def _describe_columns_with_llm(
263
  if start >= 0 and end > start:
264
  return json.loads(text[start:end])
265
  return {}
266
- except Exception:
 
267
  return {}
268
 
269
 
 
263
  if start >= 0 and end > start:
264
  return json.loads(text[start:end])
265
  return {}
266
+ except Exception as e:
267
+ print(f" LLM description error: {e}")
268
  return {}
269
 
270