Repository navigation
feat: add author-pluggable extension point for provider-specific message fields - #1586
Conversation
…age fields Signed-off-by: AngeloDanducci <[email protected]>
jakelorocco
left a comment
There was a problem hiding this comment.
I like this approach; thank you! A few comments on some of the specifics.
|
|
||
| def merge_provider_fields( | ||
| base: dict[str, Any], | ||
| provider_fields: dict[str, dict[str, Any]] | None, |
There was a problem hiding this comment.
I think we should be creating a copy of this dict (either in this function or at a higher level?) similar to what we do with model options. Editing the dict once it's passed into the function should not edit an existing Message. I believe that's what's happening here in this example / test I wrote:
pf = {"openai": {"prediction": {"type": "content"}}}
msg = Message("user", "hi", provider_fields=pf)
tr = msg.format_for_llm()
print(tr.provider_fields)
print(pf)
print(tr.provider_fields == pf)
# {'openai': {'prediction': {'type': 'content'}}}
# {'openai': {'prediction': {'type': 'content'}}}
# True
pf["openai"]["prediction"]["type"] = "new"
print(tr.provider_fields)
print(pf)
print(tr.provider_fields == pf)
# {'openai': {'prediction': {'type': 'new'}}}
# {'openai': {'prediction': {'type': 'new'}}}
# True
| if not _matches(key): | ||
| continue | ||
| matched_any = True | ||
| for field, value in fields.items(): |
There was a problem hiding this comment.
We may want to wrap this section in a larger try-catch block. I'm not sure if there are other places this can fail, but I think if field isn't a dict here, it will raise a generic error.
There was a problem hiding this comment.
Maybe lines 74 and 91 can error here as well.
Signed-off-by: AngeloDanducci <[email protected]>
ab2d172
Pull Request
Issue
Fixes #1565
Description
Allows author-pluggable fields via
provider_fields.Given the exploration around the original issue, I think this gives us the most extensibility for the least amount of headache.
I chose provider-keyed passthrough instead of widening
format_for_llmas this leaks wire shape into component code and doesn't compose well with images/docs (same issue with a global serializer registry). Open to discussion though if anyone can see reasons to alter the design - ie if we think authoring custom serialization logic itself is of greater benefit/immediate need.Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.