Repository navigation
refactor: share codec identity types #765
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
Merged
rapids-bot
merged 3 commits into
NVIDIA:main
from
willkill07:refactor/shared-codec-identities
Aug 13, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Stable LLM codec identities shared across Relay runtime and SDK boundaries. | ||
| //! | ||
| //! These types identify a codec selected by the Relay runtime. They do not | ||
| //! provide codec implementations, provider detection, or runtime capabilities. | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Relay's built-in LLM codec identities. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum BuiltinLlmCodec { | ||
| /// OpenAI Chat Completions request and response payloads. | ||
| #[serde(rename = "openai_chat")] | ||
| OpenAiChat, | ||
| /// OpenAI Responses request and response payloads. | ||
| #[serde(rename = "openai_responses")] | ||
| OpenAiResponses, | ||
| /// Anthropic Messages request and response payloads. | ||
| AnthropicMessages, | ||
| /// OCI Generative AI chat request and response payloads. | ||
| OCIGenAI, | ||
| /// Gemini generateContent request and response payloads. | ||
| GeminiGenerateContent, | ||
| } | ||
|
|
||
| impl BuiltinLlmCodec { | ||
| /// Stable identifier used in configuration and SDK transport boundaries. | ||
| #[must_use] | ||
| pub const fn id(self) -> &'static str { | ||
| match self { | ||
| Self::OpenAiChat => "openai_chat", | ||
| Self::OpenAiResponses => "openai_responses", | ||
| Self::AnthropicMessages => "anthropic_messages", | ||
| Self::OCIGenAI => "oci_genai", | ||
| Self::GeminiGenerateContent => "gemini_generate_content", | ||
| } | ||
| } | ||
|
|
||
| /// Resolve a stable built-in codec identifier. | ||
| #[must_use] | ||
| pub fn from_id(id: &str) -> Option<Self> { | ||
| match id { | ||
| "openai_chat" => Some(Self::OpenAiChat), | ||
| "openai_responses" => Some(Self::OpenAiResponses), | ||
| "anthropic_messages" => Some(Self::AnthropicMessages), | ||
| "oci_genai" => Some(Self::OCIGenAI), | ||
| "gemini_generate_content" => Some(Self::GeminiGenerateContent), | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Per-call LLM codec identity supplied to sanitizer and SDK callbacks. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] | ||
| #[serde(tag = "kind", content = "id", rename_all = "snake_case")] | ||
| pub enum LlmCodecIdentity { | ||
| /// No codec was active for this payload direction. | ||
| #[default] | ||
| None, | ||
| /// A Relay built-in codec was active. | ||
| #[serde(rename = "builtin")] | ||
| BuiltIn(BuiltinLlmCodec), | ||
| /// A runtime-registered codec was active, identified by its stable ID. | ||
| Runtime(String), | ||
| /// A codec was active but does not expose a registered identity. | ||
| Opaque, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Compatibility tests for shared LLM codec identities. | ||
|
|
||
| use nemo_relay_types::codec::identity::{BuiltinLlmCodec, LlmCodecIdentity}; | ||
| use serde_json::json; | ||
|
|
||
| #[test] | ||
| fn builtin_codec_ids_round_trip() { | ||
| let cases = [ | ||
| (BuiltinLlmCodec::OpenAiChat, "openai_chat"), | ||
| (BuiltinLlmCodec::OpenAiResponses, "openai_responses"), | ||
| (BuiltinLlmCodec::AnthropicMessages, "anthropic_messages"), | ||
| (BuiltinLlmCodec::OCIGenAI, "oci_genai"), | ||
| ( | ||
| BuiltinLlmCodec::GeminiGenerateContent, | ||
| "gemini_generate_content", | ||
| ), | ||
| ]; | ||
|
|
||
| for (codec, id) in cases { | ||
| assert_eq!(codec.id(), id); | ||
| assert_eq!(BuiltinLlmCodec::from_id(id), Some(codec)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn builtin_codec_ids_reject_unknown_values() { | ||
| for id in ["", "openai-chat", "OpenAI_chat", "unknown"] { | ||
| assert_eq!(BuiltinLlmCodec::from_id(id), None); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn codec_identity_preserves_the_native_plugin_json_contract() { | ||
| let cases = [ | ||
| (LlmCodecIdentity::None, json!({"kind": "none"})), | ||
| ( | ||
| LlmCodecIdentity::BuiltIn(BuiltinLlmCodec::OpenAiChat), | ||
| json!({"kind": "builtin", "id": "openai_chat"}), | ||
| ), | ||
| ( | ||
| LlmCodecIdentity::Runtime("com.example.chat.v1".to_owned()), | ||
| json!({"kind": "runtime", "id": "com.example.chat.v1"}), | ||
| ), | ||
| (LlmCodecIdentity::Opaque, json!({"kind": "opaque"})), | ||
| ]; | ||
|
|
||
| for (identity, expected) in cases { | ||
| assert_eq!(serde_json::to_value(&identity).unwrap(), expected); | ||
| assert_eq!( | ||
| serde_json::from_value::<LlmCodecIdentity>(expected).unwrap(), | ||
| identity | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.