fix: increase max_tokens to 16000 to prevent JSON truncation
This commit is contained in:
@@ -11,6 +11,11 @@ from app.services.ai import prompts
|
||||
from app.services.ai.claude_client import call_claude, DeckPayload
|
||||
from app.services.ai.constraints import build_constraint_context, build_owned_card_list
|
||||
|
||||
# A full 99-card deck with reasoning needs ~16000 tokens
|
||||
GENERATE_MAX_TOKENS = 16000
|
||||
COMPLETE_MAX_TOKENS = 16000
|
||||
CULL_MAX_TOKENS = 16000
|
||||
|
||||
|
||||
async def generate_deck(req: GenerateRequest, user_id: int, db: AsyncSession) -> Deck:
|
||||
owned_names = await _owned_names(user_id, db) if req.constraints.prefer_owned else []
|
||||
@@ -20,7 +25,7 @@ async def generate_deck(req: GenerateRequest, user_id: int, db: AsyncSession) ->
|
||||
constraint_text=build_constraint_context(req.constraints, owned_names or None),
|
||||
owned_list_text=build_owned_card_list(owned_names),
|
||||
)
|
||||
payload = await call_claude(system, user_msg)
|
||||
payload = await call_claude(system, user_msg, max_tokens=GENERATE_MAX_TOKENS)
|
||||
return await _persist_deck(
|
||||
payload=payload, user_id=user_id, mode=DeckMode.GENERATE,
|
||||
commander=req.commander, name=req.name or payload.deck_name,
|
||||
@@ -38,7 +43,7 @@ async def complete_deck(req: CompleteRequest, user_id: int, db: AsyncSession) ->
|
||||
constraint_text=build_constraint_context(req.constraints, owned_names or None),
|
||||
owned_list_text=build_owned_card_list(owned_names),
|
||||
)
|
||||
payload = await call_claude(system, user_msg)
|
||||
payload = await call_claude(system, user_msg, max_tokens=COMPLETE_MAX_TOKENS)
|
||||
return await _persist_deck(
|
||||
payload=payload, user_id=user_id, mode=DeckMode.COMPLETE,
|
||||
commander=req.commander, name=req.name or payload.deck_name,
|
||||
@@ -61,7 +66,7 @@ async def cull_deck(req: CullRequest, user_id: int, db: AsyncSession) -> Deck:
|
||||
owned_list_text=build_owned_card_list(owned_names),
|
||||
prefer_owned=req.constraints.prefer_owned,
|
||||
)
|
||||
payload = await call_claude(system, user_msg, max_tokens=10000)
|
||||
payload = await call_claude(system, user_msg, max_tokens=CULL_MAX_TOKENS)
|
||||
return await _persist_deck(
|
||||
payload=payload, user_id=user_id, mode=DeckMode.CULL,
|
||||
commander=req.commander, name=req.name or payload.deck_name,
|
||||
|
||||
Reference in New Issue
Block a user