Skip to content

feat(pricing): add function_tags, max_prompt_tokens, max_completion_tokens to model metadata and /api/pricing (#5931) - #5934

Open
Gravirei wants to merge 3 commits into
QuantumNous:mainfrom
Gravirei:fix/issue-5931-api-pricing-capability-metadata
Open

feat(pricing): add function_tags, max_prompt_tokens, max_completion_tokens to model metadata and /api/pricing (#5931)#5934
Gravirei wants to merge 3 commits into
QuantumNous:mainfrom
Gravirei:fix/issue-5931-api-pricing-capability-metadata

Conversation

@Gravirei

@Gravirei Gravirei commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📝 变更描述 / Description

Adds function_tags, max_prompt_tokens, and max_completion_tokens fields to model metadata (backend GORM struct) and exposes them via /api/pricing. This enables users to see model capability tags and context length limits directly in the pricing catalog.

  • Backend: New fields added to model.Model with *int64 for token counts (nullable) and string for function_tags. model.Pricing response populates these from metadata. Update() Select list includes all three fields.
  • Frontend: Model create/edit form now has inputs for function_tags (comma-separated) and token limits. Pricing model detail page displays all three fields with token count formatting.
  • i18n: 9 new translation keys added across all 6 locales (en/zh/fr/ja/ru/vi).

🚀 变更类型 / Type of change

  • ✨ 新功能 (New feature)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: I have searched existing Issues and PRs.
  • 变更理解: I understand the changes and how they work.
  • 范围聚焦: Only the intended changes are included.
  • 本地验证: go vet ./..., go test ./model/..., go test ./controller/..., bun run typecheck all pass.
  • 安全合规: No credentials, follows project conventions.

Note: This PR was created with AI assistance. The git user (Gravirei) is not a historical core contributor of this repository. The code was AI-generated/AI-assisted.

📸 运行证明 / Proof of Work

  • go vet ./... — only pre-existing web/classic/dist warning
  • go test ./model/... — ok
  • go test ./controller/... — ok
  • Frontend typecheck — pass
  • 9 missing i18n keys found and added across all 6 locales

Summary by CodeRabbit

  • New Features
    • Added function tags and prompt/completion token limit fields to model settings and pricing/model details display.
    • Extended model creation/edit UI with these inputs (including digit-only validation for token limits).
  • Bug Fixes
    • Ensured create/edit and pricing rebuild flows persist and propagate the new limit metadata consistently.
  • Documentation
    • Updated localized UI labels across multiple languages for function tags, token limits, and related context/output length wording.

Copilot AI review requested due to automatic review settings July 6, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 49d6fdba-b2bc-4c75-9067-2c5c1342646d

📥 Commits

Reviewing files that changed from the base of the PR and between 8a746cb and 916de45.

📒 Files selected for processing (7)
  • model/model_meta.go
  • model/pricing.go
  • web/default/src/features/models/components/drawers/model-mutate-drawer.tsx
  • web/default/src/features/models/lib/model-form.ts
  • web/default/src/features/models/types.ts
  • web/default/src/features/pricing/components/model-details.tsx
  • web/default/src/features/pricing/types.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • web/default/src/features/pricing/types.ts
  • web/default/src/features/models/types.ts
  • web/default/src/features/models/lib/model-form.ts
  • model/model_meta.go
  • web/default/src/features/pricing/components/model-details.tsx
  • web/default/src/features/models/components/drawers/model-mutate-drawer.tsx
  • model/pricing.go

Walkthrough

Adds function tags and prompt/completion token limits to backend model metadata and pricing output, carries them through the model management form and pricing display, and updates locale strings for the new labels and messages.

Changes

Model Capability Metadata

Layer / File(s) Summary
Backend metadata and pricing propagation
model/model_meta.go, model/pricing.go
Model metadata stores token limits, persists them during updates, and copies function tags and limits into pricing entries.
Frontend metadata contracts and validation
web/default/src/features/models/types.ts, web/default/src/features/pricing/types.ts, web/default/src/features/models/lib/model-form.ts
Frontend model, pricing, and form schemas define the new metadata fields and validate token limits as positive integers.
Model metadata form flow
web/default/src/features/models/components/drawers/model-mutate-drawer.tsx, web/default/src/features/models/lib/model-form.ts
The model drawer supports defaults, editing, digit-only inputs, validation, and payload conversion for the new fields.
Pricing metadata display
web/default/src/features/pricing/components/model-details.tsx
Pricing details render function-tag pills and formatted prompt/completion limits when provided.
Localized metadata labels
web/default/src/i18n/locales/{en,fr,ja,ru,vi,zh}.json
Locales add capability, function-tag, context, and token-limit labels and update audit-history text.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Admin
  participant Drawer as Model mutate drawer
  participant ModelAPI
  participant ModelMetadata
  participant PricingAPI

  Admin->>Drawer: enter function tags and token limits
  Drawer->>ModelAPI: submit model payload
  ModelAPI->>ModelMetadata: persist metadata
  PricingAPI->>ModelMetadata: rebuild pricing metadata
  ModelMetadata-->>PricingAPI: return function tags and token limits
  PricingAPI-->>Admin: expose metadata in pricing details
Loading

Poem

A bunny hopped through model lore,
With prompt limits and tags galore.
Pricing now displays the stream,
In many tongues, a tidy dream.
Hop, hop—the metadata’s neat!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR covers /api/pricing and model UI updates, but it doesn't show the requested channel management/API support from #5931. Add read/write support for these fields in channel APIs and control-panel channel editors, and verify consistent pricing/management views.
Out of Scope Changes check ⚠️ Warning Several locale files also change unrelated audit-history disclaimer text, which is outside the requested metadata/pricing scope. Remove or isolate the audit-history string edits unless they are required for this feature.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the new pricing/model metadata fields and the /api/pricing scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
web/default/src/features/models/lib/model-form.ts (2)

98-118: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant ?? undefined — schema already yields number | undefined.

formData.max_prompt_tokens can't be null per the Zod schema, so ?? undefined has no effect here.

♻️ Suggested simplification
-    max_prompt_tokens: formData.max_prompt_tokens ?? undefined,
-    max_completion_tokens: formData.max_completion_tokens ?? undefined,
+    max_prompt_tokens: formData.max_prompt_tokens,
+    max_completion_tokens: formData.max_completion_tokens,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/features/models/lib/model-form.ts` around lines 98 - 118, The
redundant nullish coalescing in transformFormDataToModelPayload should be
removed because ModelFormValues already provides number | undefined for
max_prompt_tokens and max_completion_tokens. Update the payload mapping in
model-form.ts to pass formData.max_prompt_tokens and
formData.max_completion_tokens directly, keeping the rest of the Model payload
transformation unchanged.

37-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer .optional() over z.union([..., z.undefined()]).

z.union([z.number().int().positive(), z.undefined()]) is functionally equivalent to .optional() but less idiomatic and produces a less precise inferred type (number | undefined required key vs number optional key).

♻️ Suggested simplification
-  max_prompt_tokens: z.union([z.number().int().positive(), z.undefined()]),
-  max_completion_tokens: z.union([z.number().int().positive(), z.undefined()]),
+  max_prompt_tokens: z.number().int().positive().optional(),
+  max_completion_tokens: z.number().int().positive().optional(),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/features/models/lib/model-form.ts` around lines 37 - 39, The
schema in model-form.ts uses z.union([..., z.undefined()]) for max_prompt_tokens
and max_completion_tokens, which should be simplified to the idiomatic optional
form. Update the zod definitions near function_tags in the model form schema to
use .optional() on the positive integer number schema instead of explicitly
unioning with z.undefined(), so the inferred types are cleaner and the key is
truly optional.
web/default/src/features/pricing/components/model-details.tsx (1)

494-500: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the map parameter to avoid shadowing the t translation function.

.map((t) => t.trim()) shadows the outer const { t } = useTranslation(). It doesn't break current behavior, but it's a lint hazard (no-shadow) and a latent bug risk if this scope is later extended to call t(...).

♻️ Proposed fix
-        <CatalogPillList items={model.function_tags.split(',').map((t) => t.trim()).filter(Boolean)} />
+        <CatalogPillList items={model.function_tags.split(',').map((tag) => tag.trim()).filter(Boolean)} />
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/features/pricing/components/model-details.tsx` around lines
494 - 500, The `model-details.tsx` rendering for `function_tags` should avoid
shadowing the `t` translation function from `useTranslation()`. Update the
`model.function_tags.split(',').map((t) => t.trim())` callback in the
`CatalogInfoCell` / `CatalogPillList` block to use a different parameter name so
`t(...)` remains unambiguous and lint-safe.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/default/src/features/models/lib/model-form.ts`:
- Around line 98-118: The redundant nullish coalescing in
transformFormDataToModelPayload should be removed because ModelFormValues
already provides number | undefined for max_prompt_tokens and
max_completion_tokens. Update the payload mapping in model-form.ts to pass
formData.max_prompt_tokens and formData.max_completion_tokens directly, keeping
the rest of the Model payload transformation unchanged.
- Around line 37-39: The schema in model-form.ts uses z.union([...,
z.undefined()]) for max_prompt_tokens and max_completion_tokens, which should be
simplified to the idiomatic optional form. Update the zod definitions near
function_tags in the model form schema to use .optional() on the positive
integer number schema instead of explicitly unioning with z.undefined(), so the
inferred types are cleaner and the key is truly optional.

In `@web/default/src/features/pricing/components/model-details.tsx`:
- Around line 494-500: The `model-details.tsx` rendering for `function_tags`
should avoid shadowing the `t` translation function from `useTranslation()`.
Update the `model.function_tags.split(',').map((t) => t.trim())` callback in the
`CatalogInfoCell` / `CatalogPillList` block to use a different parameter name so
`t(...)` remains unambiguous and lint-safe.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c846d62b-711c-455b-bc05-7118ca6567dc

📥 Commits

Reviewing files that changed from the base of the PR and between fc26b88 and c69e453.

📒 Files selected for processing (13)
  • model/model_meta.go
  • model/pricing.go
  • web/default/src/features/models/components/drawers/model-mutate-drawer.tsx
  • web/default/src/features/models/lib/model-form.ts
  • web/default/src/features/models/types.ts
  • web/default/src/features/pricing/components/model-details.tsx
  • web/default/src/features/pricing/types.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json

@huhu-tiger

Copy link
Copy Markdown

需要这个功能,能合并吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] /api/pricing 返回模型能力标签与上下文长度元数据

3 participants