-
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
Draft
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/fix-llm-markdown-applies-to
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−9
Draft
Changes from all 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
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
110 changes: 110 additions & 0 deletions
110
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,110 @@ | ||
| // 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 (block level - for page or section) | ||
| /// </summary> | ||
| public static string RenderAppliesToBlock(ApplicableTo? appliesTo, IDocumentationConfigurationContext buildContext) | ||
| { | ||
| if (appliesTo is null || appliesTo == ApplicableTo.All) | ||
| return string.Empty; | ||
|
|
||
| var items = GetApplicabilityItems(appliesTo, buildContext); | ||
| if (items.Count == 0) | ||
| return string.Empty; | ||
|
|
||
| var sb = new StringBuilder(); | ||
| _ = sb.AppendLine(); | ||
| _ = sb.AppendLine("This applies to:"); | ||
|
|
||
| foreach (var (productName, availabilityText) in items) | ||
| _ = sb.AppendLine($"- {availabilityText} for {productName}"); | ||
|
|
||
| return sb.ToString(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts ApplicableTo to a readable inline 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 items = GetApplicabilityItems(appliesTo, buildContext); | ||
| if (items.Count == 0) | ||
| return string.Empty; | ||
|
|
||
| var itemList = items.Select(item => $"{item.availabilityText} for {item.productName}").ToList(); | ||
| return string.Join(", ", itemList); | ||
| } | ||
|
|
||
| private static List<(string productName, string availabilityText)> GetApplicabilityItems( | ||
| ApplicableTo appliesTo, | ||
| IDocumentationConfigurationContext buildContext) | ||
| { | ||
| var viewModel = new ApplicableToViewModel | ||
| { | ||
| AppliesTo = appliesTo, | ||
| Inline = false, | ||
| ShowTooltip = false, | ||
| VersionsConfig = buildContext.VersionsConfiguration | ||
| }; | ||
|
|
||
| var applicabilityItems = viewModel.GetApplicabilityItems(); | ||
| var results = new List<(string productName, string availabilityText)>(); | ||
|
|
||
| foreach (var item in applicabilityItems) | ||
| { | ||
| var renderData = item.RenderData; | ||
| var productName = item.Key; | ||
|
|
||
| // Get the availability text from the popover data | ||
| var availabilityText = GetAvailabilityText(renderData); | ||
| if (!string.IsNullOrEmpty(availabilityText)) | ||
| results.Add((productName, availabilityText)); | ||
| } | ||
|
|
||
| return results; | ||
| } | ||
|
|
||
| private static string GetAvailabilityText(ApplicabilityRenderer.ApplicabilityRenderData renderData) | ||
| { | ||
| // Use the first availability item's text if available (this is what the popover shows) | ||
| if (renderData.PopoverData?.AvailabilityItems is { Length: > 0 } items) | ||
| { | ||
| // The popover text already includes lifecycle and version info | ||
| // e.g., "Generally available since 9.1", "Preview in 8.0", etc. | ||
| // We use the first item because it represents the most current/relevant status | ||
| // (items are sorted by version descending in ApplicabilityRenderer) | ||
| return items[0].Text; | ||
| } | ||
|
|
||
| // Fallback to constructing from badge data | ||
| var parts = new List<string>(); | ||
|
|
||
| if (!string.IsNullOrEmpty(renderData.LifecycleName) && renderData.LifecycleName != "Generally available") | ||
| parts.Add(renderData.LifecycleName); | ||
|
|
||
| if (!string.IsNullOrEmpty(renderData.Version)) | ||
| parts.Add(renderData.Version); | ||
| else if (!string.IsNullOrEmpty(renderData.BadgeLifecycleText)) | ||
| parts.Add(renderData.BadgeLifecycleText); | ||
|
|
||
| return parts.Count > 0 ? string.Join(" ", parts) : "Available"; | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This test is useless if we cannot test the output of the frontmatter applies_to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 5a4c560. The test now directly calls
LlmAppliesToHelper.RenderAppliesToBlockto test the actual output that appears in the metadata section. The test verifies:ApplicableToobjectRenderAppliesToBlockproduces output containing "This applies to:"This tests the actual rendering logic that generates the applies_to metadata text in exported files.