Repository navigation
dashscope: follow model-info links and read pages with no Context limits section #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ export interface DashscopeModelLimits { | |
|
|
||
| export interface DashscopeLimitsDoc { | ||
| sourceHash: string | ||
| /** The page read when the requested one was an index linking it (#772). */ | ||
| sourceUrl?: string | ||
| models: Record<string, DashscopeModelLimits> | ||
| } | ||
|
|
||
|
|
@@ -122,17 +124,67 @@ function limitsFrom(rows: Array<Array<string>>): DashscopeModelLimits | null { | |
| return { contextWindow, maxOutput } | ||
| } | ||
|
|
||
| const LIMITS_HEADING = /^context limits$/i | ||
| const CAPABILITIES_HEADING = /^model capabilities$/i | ||
| const LIMIT_ROW = | ||
| /context window|max(?:imum)? input length|max(?:imum)? output length/i | ||
|
|
||
| function headings(markdown: string): Array<string> { | ||
| return markdown.split('\n').flatMap((line) => headingText(line) ?? []) | ||
| } | ||
|
|
||
| /** | ||
| * A model page with a capabilities table, no Context limits section and | ||
| * no limits table anywhere states no limits (qwen-audio-3.1-live.md, | ||
| * 2026-11-27): its one model, the h1, gets nulls. A page that still carries | ||
| * limit rows under a renamed heading is not read, so it throws. | ||
| */ | ||
| function statesNoLimits( | ||
| markdown: string, | ||
| ): Record<string, DashscopeModelLimits> | null { | ||
| const titles = headings(markdown) | ||
| const h1 = /^#\s+(.*)$/m.exec(markdown)?.[1]?.trim() | ||
| if (!h1 || !isModelId(h1)) return null | ||
| if (titles.some((title) => LIMITS_HEADING.test(title))) return null | ||
| if (!titles.some((title) => CAPABILITIES_HEADING.test(title))) return null | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Require a capabilities table before accepting null limits. For Require nonempty capabilities-table rows before returning this result. This preserves the As per coding guidelines, structured parsers must “fail closed, and a page that parses nothing throws.”
|
||
| if (LIMIT_ROW.test(markdown)) return null | ||
| return { [h1]: { contextWindow: null, maxOutput: null } } | ||
| } | ||
|
|
||
| /** | ||
| * An overview page that only links its model's info page | ||
| * (`[decision-model Model Info](/help/en/model-studio/decision-model-stable)`, | ||
| * decision-model.md since 2026-11-23): the `.md` URL of that link. | ||
| */ | ||
| export function dashscopeModelInfoLink(markdown: string): string | null { | ||
| const titles = headings(markdown) | ||
| if ( | ||
| titles.some( | ||
| (title) => LIMITS_HEADING.test(title) || CAPABILITIES_HEADING.test(title), | ||
| ) | ||
| ) { | ||
| return null | ||
| } | ||
| const slug = | ||
| /\[[^\]]*\bModel Info\]\(\/help\/en\/model-studio\/([a-z0-9-]+)\)/i.exec( | ||
| markdown, | ||
| )?.[1] | ||
| return slug ? `${PAGE_ORIGIN}/${slug}.md` : null | ||
| } | ||
|
|
||
| export function parseDashscopeModelLimits( | ||
| markdown: string, | ||
| ): Record<string, DashscopeModelLimits> { | ||
| const unstated = statesNoLimits(markdown) | ||
| if (unstated) return unstated | ||
| const lines = markdown.split('\n') | ||
| let current: string | null = null | ||
| const models: Record<string, DashscopeModelLimits> = {} | ||
| for (let i = 0; i < lines.length; i++) { | ||
| const title = headingText(lines[i] ?? '') | ||
| if (!title) continue | ||
| if (isModelId(title)) current = title | ||
| if (!/^context limits$/i.test(title) || !current) continue | ||
| if (!LIMITS_HEADING.test(title) || !current) continue | ||
| const limits = limitsFrom(tableRows(sectionAfter(lines, i + 1))) | ||
| if (limits) models[current] = limits | ||
| } | ||
|
|
@@ -237,12 +289,22 @@ export function dashscopeDocText(body: string, label: string): string { | |
| ) | ||
| } | ||
|
|
||
| /** | ||
| * One model page's limits. An overview page that links its model's info | ||
| * page is followed once (`fetchPage`), and the doc names the page read. | ||
| */ | ||
| export async function loadDashscopeModelLimits( | ||
| body: string, | ||
| fetchPage?: (url: string) => Promise<string>, | ||
| ): Promise<DashscopeLimitsDoc> { | ||
| const markdown = dashscopeDocText(body, 'dashscope model page') | ||
| let markdown = dashscopeDocText(body, 'dashscope model page') | ||
| const linked = fetchPage ? dashscopeModelInfoLink(markdown) : null | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve model-info links from rendered HTML. If the overview arrives as rendered HTML, Line 296 converts it before this lookup. This affects the HTML response format already supported by
|
||
| if (linked && fetchPage) { | ||
| markdown = dashscopeDocText(await fetchPage(linked), 'dashscope model page') | ||
| } | ||
| return { | ||
| sourceHash: await sha256Text(markdown), | ||
| ...(linked ? { sourceUrl: linked } : {}), | ||
| models: parseDashscopeModelLimits(markdown), | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the supported output-token labels in this guard.
If
REALTIME_FIXTUREusesToken limitsinstead ofContext limits, itsMaximum output tokensrow does not matchLIMIT_ROW.statesNoLimitsthen returnsmaxOutput: null, although the table publishes65536.Include the labels accepted by
MAX_OUTPUTin this detection. The renamed section must throw rather than produce null limits. Keep the original realtime fixture parsingmaxOutput: 65536.