-
Notifications
You must be signed in to change notification settings - Fork 34
Render applies_to as readable text in LLM markdown output #2439
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
17d78a6
Initial plan
Copilot 809fb58
Work in progress on applies_to in LLM markdown output
Copilot c2b9180
Implement LLM-friendly applies_to rendering using popover data
Copilot 1c2a134
Update test expectations for LLM applies_to rendering
Copilot fcbf94b
Address code review comments with clarifying documentation
Copilot 0c1252f
Add test for page-level applies_to in frontmatter
Copilot e8369f5
Improve page-level applies_to test with clearer assertions
Copilot b3a3094
Add clearer documentation for page-level applies_to test with expecte…
Copilot 5a4c560
Add public API to test LLM export metadata and test applies_to rendering
Copilot 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
Some comments aren't visible on the classic Files Changed page.
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
94 changes: 94 additions & 0 deletions
94
src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmAppliesToHelper.cs
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,94 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using System.Text; | ||
| using Elastic.Documentation; | ||
| using Elastic.Documentation.AppliesTo; | ||
| using Elastic.Documentation.Configuration; | ||
| using Elastic.Markdown.Myst.Components; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Renderers.LlmMarkdown; | ||
|
|
||
| /// <summary> | ||
| /// Helper class to render ApplicableTo information in LLM-friendly text format | ||
| /// </summary> | ||
| public static class LlmAppliesToHelper | ||
| { | ||
| /// <summary> | ||
| /// Converts ApplicableTo to a readable text format for LLM consumption | ||
| /// </summary> | ||
| public static string RenderApplicableTo(ApplicableTo? appliesTo, IDocumentationConfigurationContext buildContext) | ||
| { | ||
| if (appliesTo is null || appliesTo == ApplicableTo.All) | ||
| return string.Empty; | ||
|
|
||
| var viewModel = new ApplicableToViewModel | ||
| { | ||
| AppliesTo = appliesTo, | ||
| Inline = false, | ||
| ShowTooltip = false, | ||
| VersionsConfig = buildContext.VersionsConfiguration | ||
| }; | ||
|
|
||
| var items = viewModel.GetApplicabilityItems(); | ||
| if (items.Count == 0) | ||
| return string.Empty; | ||
|
|
||
| var itemList = new List<string>(); | ||
|
|
||
| foreach (var item in items) | ||
| { | ||
| var text = BuildApplicabilityText(item); | ||
| if (!string.IsNullOrEmpty(text)) | ||
| itemList.Add(text); | ||
| } | ||
|
|
||
| if (itemList.Count == 0) | ||
| return string.Empty; | ||
|
|
||
| return string.Join(", ", itemList); | ||
| } | ||
|
|
||
| private static string BuildApplicabilityText(ApplicabilityItem item) | ||
| { | ||
| // For LLM output, use the shorter Key name for better readability | ||
| var parts = new List<string> { item.Key }; | ||
|
|
||
| // For LLM output, show the actual applicability information directly | ||
| var applicability = item.Applicability; | ||
|
|
||
| // Add lifecycle if it's not GA | ||
| if (applicability.Lifecycle != ProductLifecycle.GenerallyAvailable) | ||
| parts.Add(applicability.GetLifeCycleName()); | ||
|
|
||
| // Add version information if present | ||
| if (applicability.Version is not null and not AllVersionsSpec) | ||
| { | ||
| var versionText = FormatVersion(applicability.Version); | ||
| if (!string.IsNullOrEmpty(versionText)) | ||
| parts.Add(versionText); | ||
| } | ||
|
|
||
| return string.Join(" ", parts); | ||
| } | ||
|
|
||
| private static string FormatVersion(VersionSpec versionSpec) | ||
| { | ||
| var min = versionSpec.Min; | ||
| var max = versionSpec.Max; | ||
| var showMinPatch = versionSpec.ShowMinPatch; | ||
| var showMaxPatch = versionSpec.ShowMaxPatch; | ||
|
|
||
| static string FormatSemVersion(SemVersion v, bool showPatch) => | ||
| showPatch ? $"{v.Major}.{v.Minor}.{v.Patch}" : $"{v.Major}.{v.Minor}"; | ||
|
|
||
| return versionSpec.Kind switch | ||
| { | ||
| VersionSpecKind.GreaterThanOrEqual => $"{FormatSemVersion(min, showMinPatch)}+", | ||
| VersionSpecKind.Range when max is not null => $"{FormatSemVersion(min, showMinPatch)}-{FormatSemVersion(max, showMaxPatch)}", | ||
| VersionSpecKind.Exact => FormatSemVersion(min, showMinPatch), | ||
| _ => string.Empty | ||
| }; | ||
| } | ||
| } | ||
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
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.