Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion backend/services/model_health_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ def _normalize_embedding_url(base_url: str) -> str:
def _infer_model_factory(model_type: str, base_url: str, current_factory: Optional[str] = None) -> Optional[str]:
"""Infer model_factory from base_url if not already set or is generic.

Uses the shared W11 host map so embedding and LLM/VLM inference do not drift.
For embedding/multi_embedding, uses legacy logic (only dashscope) to avoid
changing existing behavior. For other types (VLM), uses extended inference
so tokenpony URLs can be recognized for catalog healthcheck.
"""
# Embedding types: keep legacy behavior (only dashscope)
if model_type in EMBEDDING_TYPES:
if "dashscope" in base_url.lower():
return DASHSCOPE_MODEL_FACTORY
return current_factory

# Non-embedding types (VLM, etc): use extended inference
try:
from services.model_capacity_suggestion_service import pick_provider_from_base_url

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Generate idempotent backfill SQL from capability_profiles.CATALOG.

Usage:
python scripts/generate_backfill_sql.py > docker/sql/v2.2.x_MMDD_backfill_from_catalog.sql
python deploy/sql/migrations/generate_backfill_sql.py > deploy/sql/migrations/v2.2.x_MMDD_backfill_from_catalog.sql

Run whenever capability_profiles.py changes, then commit the generated SQL.
"""
Expand All @@ -12,7 +12,7 @@
from datetime import date
from collections import namedtuple

_project_root = os.path.join(os.path.dirname(__file__), "..")
_project_root = os.path.join(os.path.dirname(__file__), "..", "..", "..")
sys.path.insert(0, os.path.join(_project_root, "backend"))

# Stub SDK types to avoid pulling in the full nexent SDK dependency chain
Expand Down Expand Up @@ -80,7 +80,7 @@
today = date.today().strftime("%Y-%m-%d")
lines: list[str] = []

lines.append(f"-- Generated by scripts/generate_backfill_sql.py on {today}")
lines.append(f"-- Generated by deploy/sql/migrations/generate_backfill_sql.py on {today}")
lines.append(f"-- Catalog revision: {CATALOG_REVISION}")
lines.append(f"-- Catalog entries: {len(CATALOG)}")
lines.append("--")
Expand Down Expand Up @@ -120,15 +120,15 @@
# --------------------------------------------------------------
# Phase 1a: catalog match + bare -> fill capacity + tag
# --------------------------------------------------------------
lines.append("-- ============================================================")

Check failure on line 123 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "-- ============================================================" 8 times.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4L&open=AZ8S_Z3J5S5cHCbRPw4L&pullRequest=3332
lines.append("-- Phase 1a: Backfill bare rows that match approved catalog entries")
lines.append("-- ============================================================")
lines.append("")
lines.append("DO $$")

Check failure on line 127 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "DO $$" 4 times.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4I&open=AZ8S_Z3J5S5cHCbRPw4I&pullRequest=3332
lines.append("DECLARE")
lines.append(" v_updated INTEGER := 0;")

Check failure on line 129 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal " v_updated INTEGER := 0;" 4 times.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4J&open=AZ8S_Z3J5S5cHCbRPw4J&pullRequest=3332
lines.append(" v_total INTEGER := 0;")
lines.append(" c_active_flag CONSTANT TEXT := 'N';")

Check failure on line 131 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal " c_active_flag CONSTANT TEXT := 'N';" 4 times.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4H&open=AZ8S_Z3J5S5cHCbRPw4H&pullRequest=3332
lines.append(" c_source_profile CONSTANT TEXT := 'profile';")
lines.append("BEGIN")

Expand All @@ -144,26 +144,26 @@
repo_match = _sql_repo_match(repo)
escaped_name = _sql_str(name)

lines.append(f" UPDATE nexent.model_record_t")

Check warning on line 147 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4M&open=AZ8S_Z3J5S5cHCbRPw4M&pullRequest=3332
lines.append(f" SET context_window_tokens = COALESCE(context_window_tokens,")

Check warning on line 148 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4N&open=AZ8S_Z3J5S5cHCbRPw4N&pullRequest=3332
lines.append(f" GREATEST({_sql_int(ctx)}, COALESCE(max_output_tokens, 0) + 1)),")
lines.append(f" max_output_tokens = COALESCE(max_output_tokens,")

Check warning on line 150 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4O&open=AZ8S_Z3J5S5cHCbRPw4O&pullRequest=3332
lines.append(f" LEAST({_sql_int(mout)}, COALESCE(context_window_tokens, {_sql_int(ctx)}) - 1)),")
lines.append(f" default_output_reserve_tokens = COALESCE(default_output_reserve_tokens,")

Check warning on line 152 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4P&open=AZ8S_Z3J5S5cHCbRPw4P&pullRequest=3332
lines.append(f" LEAST({_sql_int(reserve)}, COALESCE(max_output_tokens, {_sql_int(mout)}))),")
lines.append(f" capacity_source = COALESCE(capacity_source, c_source_profile),")

Check warning on line 154 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4Q&open=AZ8S_Z3J5S5cHCbRPw4Q&pullRequest=3332
lines.append(f" capability_profile_version = COALESCE(capability_profile_version, '{version}')")
lines.append(f" WHERE LOWER(model_factory) = '{_sql_str(provider.lower())}'")
lines.append(f" AND {repo_match}")
lines.append(f" AND model_name = '{escaped_name}'")
lines.append(f" AND delete_flag = c_active_flag")

Check warning on line 159 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4R&open=AZ8S_Z3J5S5cHCbRPw4R&pullRequest=3332
lines.append(f" AND (context_window_tokens IS NULL OR max_output_tokens IS NULL);")

Check warning on line 160 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4S&open=AZ8S_Z3J5S5cHCbRPw4S&pullRequest=3332
lines.append(f" GET DIAGNOSTICS v_updated = ROW_COUNT;")

Check warning on line 161 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4T&open=AZ8S_Z3J5S5cHCbRPw4T&pullRequest=3332
lines.append(f" v_total := v_total + v_updated;")

Check warning on line 162 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4U&open=AZ8S_Z3J5S5cHCbRPw4U&pullRequest=3332
lines.append("")

lines.append(" RAISE NOTICE 'Phase 1a catalog backfill (bare): % row(s) updated', v_total;")
lines.append("END $$;")

Check failure on line 166 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "END $$;" 4 times.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4K&open=AZ8S_Z3J5S5cHCbRPw4K&pullRequest=3332
lines.append("")

# --------------------------------------------------------------
Expand Down Expand Up @@ -198,18 +198,18 @@
repo_match = _sql_repo_match(repo)
escaped_name = _sql_str(name)

lines.append(f" UPDATE nexent.model_record_t")

Check warning on line 201 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4V&open=AZ8S_Z3J5S5cHCbRPw4V&pullRequest=3332
lines.append(f" SET capability_profile_version = '{version}',")
lines.append(f" capacity_source = CASE WHEN capacity_source = c_source_default THEN c_source_profile ELSE capacity_source END")

Check warning on line 203 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4W&open=AZ8S_Z3J5S5cHCbRPw4W&pullRequest=3332
lines.append(f" WHERE LOWER(model_factory) = '{_sql_str(provider.lower())}'")
lines.append(f" AND {repo_match}")
lines.append(f" AND model_name = '{escaped_name}'")
lines.append(f" AND delete_flag = c_active_flag")

Check warning on line 207 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4X&open=AZ8S_Z3J5S5cHCbRPw4X&pullRequest=3332
lines.append(f" AND context_window_tokens = {_sql_int(ctx)}")
lines.append(f" AND max_output_tokens = {_sql_int(mout)}")
lines.append(f" AND (capability_profile_version IS NULL OR (capability_profile_version = '{version}' AND capacity_source = c_source_default));")
lines.append(f" GET DIAGNOSTICS v_updated = ROW_COUNT;")

Check warning on line 211 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4Y&open=AZ8S_Z3J5S5cHCbRPw4Y&pullRequest=3332
lines.append(f" v_total := v_total + v_updated;")

Check warning on line 212 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4Z&open=AZ8S_Z3J5S5cHCbRPw4Z&pullRequest=3332
lines.append("")

lines.append(" RAISE NOTICE 'Phase 1b catalog tag (matching filled): % row(s) updated', v_total;")
Expand All @@ -228,13 +228,13 @@
lines.append(" c_source_default CONSTANT TEXT := 'default';")
lines.append("BEGIN")
lines.append(" UPDATE nexent.model_record_t")
lines.append(f" SET context_window_tokens = COALESCE(context_window_tokens,")

Check warning on line 231 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4a&open=AZ8S_Z3J5S5cHCbRPw4a&pullRequest=3332
lines.append(f" GREATEST({_sql_int(DEFAULT_CONTEXT_WINDOW)}, COALESCE(max_output_tokens, 0) + 1)),")
lines.append(f" max_output_tokens = COALESCE(max_output_tokens,")

Check warning on line 233 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4b&open=AZ8S_Z3J5S5cHCbRPw4b&pullRequest=3332
lines.append(f" LEAST({_sql_int(DEFAULT_MAX_OUTPUT)}, COALESCE(context_window_tokens, {_sql_int(DEFAULT_CONTEXT_WINDOW)}) - 1)),")
lines.append(f" default_output_reserve_tokens = COALESCE(default_output_reserve_tokens,")

Check warning on line 235 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4c&open=AZ8S_Z3J5S5cHCbRPw4c&pullRequest=3332
lines.append(f" LEAST({_sql_int(DEFAULT_RESERVE)}, COALESCE(max_output_tokens, {_sql_int(DEFAULT_MAX_OUTPUT)}))),")
lines.append(f" capacity_source = COALESCE(capacity_source, c_source_default)")

Check warning on line 237 in deploy/sql/migrations/generate_backfill_sql.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ8S_Z3J5S5cHCbRPw4d&open=AZ8S_Z3J5S5cHCbRPw4d&pullRequest=3332
lines.append(" WHERE delete_flag = c_active_flag")
lines.append(" AND COALESCE(model_type, 'llm') IN ('llm', 'vlm')")
lines.append(" AND (context_window_tokens IS NULL OR max_output_tokens IS NULL);")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ export default function AgentGenerateDetail({}) {
</Row>

<Row gutter={16}>
<Col span={8}>
<Col span={12}>
<Form.Item
name="mainAgentMaxStep"
label={t("businessLogic.config.maxSteps")}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ export default function AgentGenerateDetail({}) {
/>
</Form.Item>
</Col>
<Col span={8}>
<Col span={12}>
<Form.Item
name="provideRunSummary"
label={t("agent.provideRunSummary")}
Expand All @@ -1050,33 +1050,6 @@ export default function AgentGenerateDetail({}) {
/>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item
name="verificationEnabled"
label={t("agent.verification")}
rules={[
{
required: true,
message: t("agent.verification.error"),
},
]}
>
<Select
options={[
{ value: true, label: t("common.yes") },
{ value: false, label: t("common.no") },
]}
onChange={(value) => {
updateAgentConfig({
verification_config: {
...(editedAgent.verification_config || DEFAULT_AGENT_VERIFICATION_CONFIG),
enabled: value,
},
});
}}
/>
</Form.Item>
</Col>
</Row>

<Row gutter={16}>
Expand Down Expand Up @@ -1124,6 +1097,33 @@ export default function AgentGenerateDetail({}) {
/>
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
name="verificationEnabled"
label={t("agent.verification")}
rules={[
{
required: true,
message: t("agent.verification.error"),
},
]}
>
<Select
options={[
{ value: true, label: t("common.yes") },
{ value: false, label: t("common.no") },
]}
onChange={(value) => {
updateAgentConfig({
verification_config: {
...(editedAgent.verification_config || DEFAULT_AGENT_VERIFICATION_CONFIG),
enabled: value,
},
});
}}
/>
</Form.Item>
</Col>
</Row>

<Form.Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,6 @@ export const ModelAddDialog = ({
apiKey: form.apiKey.trim() === "" ? "sk-no-api-key" : form.apiKey,
maxTokens: maxTokensValue,
displayName: form.displayName || form.name,
modelFactory: form.provider,
...(supportsCapacityFields ? buildCapacityPayload(form) : {}),
...acceptSignalKwargs,
};
Expand Down Expand Up @@ -1214,7 +1213,6 @@ export const ModelAddDialog = ({
apiKey: form.apiKey.trim() === "" ? "sk-no-api-key" : form.apiKey,
maxTokens: maxTokensValue,
displayName: form.displayName || form.name,
modelFactory: form.provider,
...(supportsCapacityFields ? buildCapacityPayload(form) : {}),
...acceptSignalKwargs,
};
Expand Down
Loading