Skip to content

1/3 Support Model rewrite capability - Configuration format change#151

Open
J3rome wants to merge 8 commits into
mainfrom
model-rewrite-1
Open

1/3 Support Model rewrite capability - Configuration format change#151
J3rome wants to merge 8 commits into
mainfrom
model-rewrite-1

Conversation

@J3rome
Copy link
Copy Markdown
Contributor

@J3rome J3rome commented Jun 4, 2026

This is PR 1/3 to enable the model rewrite capability.

This is a breaking change

What is in this PR

Change the provider.capability config format.
Was

"capability": {
    "models": ["model-1-*", "model-2-*"],
    "user_agents": []
}

Is now

"capability": {
    "models": {
        "model-1-*": {
            "rewrite": "new-model-name"
        },
        "model-2-*": {}
    },
    "user_agents": []
}

It is essentially a no-op other than the configuration changes.

@J3rome J3rome requested review from aviau and leameow June 4, 2026 20:06
@J3rome J3rome self-assigned this Jun 4, 2026
@J3rome J3rome changed the title Support Model rewrite capability 1/3 1/3 Support Model rewrite capability - Configuration format change Jun 4, 2026
Comment thread src/serde_utils.rs Outdated
.map(|s| glob::Pattern::new(&s).map_err(serde::de::Error::custom))
.collect()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like this belong to config.rs, it even use object from this module.

This module is an util module and aim to deal with "generic" serialization stuff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree. Will move

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to config.rs

Comment thread README.md
- `{ "rewrite": "<target>" }` ⇒ the model is allowed and the upstream is called with `<target>` instead. In the example, requests for `us.anthropic.claude-opus-4-5*` are sent to Bedrock as the configured application-inference-profile ARN.

Notes:
- Ordering matters: the **first matching pattern wins** for rewrite resolution. Authorization is order-independent (any match allows).
Copy link
Copy Markdown
Member

@aviau aviau Jun 4, 2026

Choose a reason for hiding this comment

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

If ordering matters, then it shouldn't be a dict. Otherwise people have to serialize a dict with ordered keys, which almost no library supports?

I suggest moving this to a list (sorry we didn't think of this during design!)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe now is a good time to ask the question: Do we really want to keep priority based on the ordering ?

Another way we could approach this would be to make the more specific pattern win
ex : claude-opus-* win over claude-* regardless of the ordering.

This way we don't have to duplicate the model key in the config to support rewrite & other capabilities and it's also less error prone then relying on ordering IMO

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I almost suggested to do the more specific pattern and I had given up because I was thinking of regexes, but its true that with fnmatch, just counting characters isn't that bad.

LGTM for your idea!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@leameow Thoughts ?
If your good with that i'll implement this in a separate PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, good idea! I've seen this in other systems as well, 🚢 🇮🇹

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok so remove this line from the docs and merge for now?

Comment thread src/config.rs
}

#[test]
fn preserves_declaration_order_when_deserializing_model_rules() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove this?

Comment thread src/config.rs
rewrite: Option<String>,
}

/// Serialize `Vec<ModelRule>` as an ordered object: `pattern => { "rewrite"?: target }`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no longer needed?

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.

3 participants