From c9d33ad21ec63b20ccb0a6249dd6c3865559d5fc Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Wed, 6 Nov 2024 11:53:06 +0000 Subject: [PATCH 1/3] Split out a `ModelHint` type for clarity --- schema/schema.ts | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/schema/schema.ts b/schema/schema.ts index a61b2a089..7e95886f2 100644 --- a/schema/schema.ts +++ b/schema/schema.ts @@ -806,19 +806,7 @@ export interface ImageContent { */ export interface ModelPreferences { /** - * Optional string hints to use for model selection. How these hints are - * interpreted depends on the key(s) in each record: - * - * - If the record contains a `name` key: - * - The client SHOULD treat this as a substring of a model name; for example: - * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` - * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. - * - `claude` should match any Claude model - * - The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: - * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` - * - * All other keys are currently left unspecified by the spec and are up to the - * client to interpret. + * Optional hints to use for model selection. * * If multiple hints are specified, the client MUST evaluate them in order * (such that the first match is taken). @@ -826,7 +814,7 @@ export interface ModelPreferences { * The client SHOULD prioritize these hints over the numeric priorities, but * MAY still use the priorities to select from ambiguous matches. */ - hints?: Record<"name" | string, string>[]; + hints?: ModelHint[]; /** * How much to prioritize cost when selecting a model. A value of 0 means cost @@ -862,6 +850,35 @@ export interface ModelPreferences { intelligencePriority?: number; } +/** + * Hints to use for model selection. + * + * - If the record contains a `name` key: + * - The client SHOULD treat this as a substring of a model name; for example: + * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` + * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. + * - `claude` should match any Claude model + * - The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: + * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` + * + * Keys not declared here are currently left unspecified by the spec and are up + * to the client to interpret. + */ +export interface ModelHint { + /** + * A hint for a model name. + * + * The client SHOULD treat this as a substring of a model name; for example: + * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` + * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. + * - `claude` should match any Claude model + * + * The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: + * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` + */ + name?: string; +} + /* Autocomplete */ /** * A request from the client to the server, to ask for completion options. From 6aaaaf9484392cf78cfa862273e049d8299489d2 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Wed, 6 Nov 2024 11:54:15 +0000 Subject: [PATCH 2/3] Remove duplicated comment --- schema/schema.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/schema/schema.ts b/schema/schema.ts index 7e95886f2..d3928fe93 100644 --- a/schema/schema.ts +++ b/schema/schema.ts @@ -853,14 +853,6 @@ export interface ModelPreferences { /** * Hints to use for model selection. * - * - If the record contains a `name` key: - * - The client SHOULD treat this as a substring of a model name; for example: - * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` - * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. - * - `claude` should match any Claude model - * - The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: - * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` - * * Keys not declared here are currently left unspecified by the spec and are up * to the client to interpret. */ From 0cc9ae77195b5c50c462cb41d6d6fb0d823ff411 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Wed, 6 Nov 2024 11:54:24 +0000 Subject: [PATCH 3/3] Regenerate JSON Schema --- schema/schema.json | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/schema/schema.json b/schema/schema.json index 58d9fbea3..9d051ae27 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -1012,6 +1012,16 @@ ], "type": "object" }, + "ModelHint": { + "description": "Hints to use for model selection.\n\nKeys not declared here are currently left unspecified by the spec and are up\nto the client to interpret.", + "properties": { + "name": { + "description": "A hint for a model name.\n\nThe client SHOULD treat this as a substring of a model name; for example:\n - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022`\n - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc.\n - `claude` should match any Claude model\n\nThe client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example:\n - `gemini-1.5-flash` could match `claude-3-haiku-20240307`", + "type": "string" + } + }, + "type": "object" + }, "ModelPreferences": { "description": "The server's preferences for model selection, requested of the client during sampling.\n\nBecause LLMs can vary along multiple dimensions, choosing the \"best\" model is\nrarely straightforward. Different models excel in different areas—some are\nfaster but less capable, others are more capable but more expensive, and so\non. This interface allows servers to express their priorities across multiple\ndimensions to help clients make an appropriate selection for their use case.\n\nThese preferences are always advisory. The client MAY ignore them. It is also\nup to the client to decide how to interpret these preferences and how to\nbalance them against other considerations.", "properties": { @@ -1022,9 +1032,9 @@ "type": "number" }, "hints": { - "description": "Optional string hints to use for model selection. How these hints are\ninterpreted depends on the key(s) in each record:\n\n- If the record contains a `name` key:\n - The client SHOULD treat this as a substring of a model name; for example:\n - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022`\n - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc.\n - `claude` should match any Claude model\n - The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example:\n - `gemini-1.5-flash` could match `claude-3-haiku-20240307`\n\nAll other keys are currently left unspecified by the spec and are up to the\nclient to interpret.\n\nIf multiple hints are specified, the client MUST evaluate them in order\n(such that the first match is taken).\n\nThe client SHOULD prioritize these hints over the numeric priorities, but\nMAY still use the priorities to select from ambiguous matches.", + "description": "Optional hints to use for model selection.\n\nIf multiple hints are specified, the client MUST evaluate them in order\n(such that the first match is taken).\n\nThe client SHOULD prioritize these hints over the numeric priorities, but\nMAY still use the priorities to select from ambiguous matches.", "items": { - "$ref": "#/definitions/Record" + "$ref": "#/definitions/ModelHint" }, "type": "array" }, @@ -1340,9 +1350,6 @@ ], "type": "object" }, - "Record": { - "type": "object" - }, "Request": { "properties": { "method": {