-
Notifications
You must be signed in to change notification settings - Fork 13
Batch Ailly calls from Lliam #175
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
Open
cpyle0819
wants to merge
2
commits into
main
Choose a base branch
from
corepyle/lliam-enhancements
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.
Open
Changes from all commits
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ __pycache__ | |
build/ | ||
dist/ | ||
.ailly_iam_policy | ||
*.log |
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 |
---|---|---|
|
@@ -2,17 +2,14 @@ | |
|
||
import logging | ||
import os | ||
import yaml | ||
from pathlib import Path | ||
from typing import List | ||
import yaml | ||
|
||
from aws_doc_sdk_examples_tools.doc_gen import DocGen, Snippet | ||
|
||
DEFAULT_METADATA_PREFIX = "[DEFAULT]" | ||
from aws_doc_sdk_examples_tools.doc_gen import DocGen | ||
|
||
DEFAULT_METADATA_PREFIX = "DEFAULT" | ||
|
||
# Setup logging | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -26,6 +23,8 @@ def make_doc_gen(root: Path) -> DocGen: | |
def write_prompts(doc_gen: DocGen, out_dir: Path, language: str) -> None: | ||
examples = doc_gen.examples | ||
snippets = doc_gen.snippets | ||
|
||
filtered_examples = [] | ||
for example_id, example in examples.items(): | ||
# TCXContentAnalyzer prefixes new metadata title/title_abbrev entries with | ||
# the DEFAULT_METADATA_PREFIX. Checking this here to make sure we're only | ||
|
@@ -35,30 +34,56 @@ def write_prompts(doc_gen: DocGen, out_dir: Path, language: str) -> None: | |
if title.startswith(DEFAULT_METADATA_PREFIX) and title_abbrev.startswith( | ||
DEFAULT_METADATA_PREFIX | ||
): | ||
prompt_path = out_dir / f"{example_id}.md" | ||
snippet_key = ( | ||
example.languages[language] | ||
.versions[0] | ||
.excerpts[0] | ||
.snippet_files[0] | ||
.replace("/", ".") | ||
) | ||
snippet = snippets[snippet_key] | ||
prompt_path.write_text(snippet.code, encoding="utf-8") | ||
filtered_examples.append((example_id, example)) | ||
|
||
batch_size = 150 | ||
total_examples = len(filtered_examples) | ||
num_batches = (total_examples + batch_size - 1) // batch_size | ||
|
||
logger.info( | ||
f"Splitting {total_examples} examples into {num_batches} batches of {batch_size}" | ||
) | ||
|
||
for batch_num in range(num_batches): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.python.org/3/library/itertools.html#itertools.batched
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not added til 3.12, but I'll add the recipe from earlier versions. |
||
batch_dir = out_dir / f"batch_{(batch_num + 1):03}" | ||
batch_dir.mkdir(exist_ok=True) | ||
|
||
start_idx = batch_num * batch_size | ||
end_idx = min((batch_num + 1) * batch_size, total_examples) | ||
|
||
for i in range(start_idx, end_idx): | ||
example_id, example = filtered_examples[i] | ||
prompt_path = batch_dir / f"{example_id}.md" | ||
|
||
try: | ||
snippet_key = ( | ||
example.languages[language] | ||
.versions[0] | ||
.excerpts[0] | ||
.snippet_files[0] | ||
.replace("/", ".") | ||
) | ||
snippet = snippets[snippet_key] | ||
prompt_path.write_text(snippet.code, encoding="utf-8") | ||
except (KeyError, IndexError, AttributeError) as e: | ||
logger.warning(f"Error processing example {example_id}: {e}") | ||
|
||
|
||
def setup_ailly(system_prompts: List[str], out_dir: Path) -> None: | ||
"""Create the .aillyrc configuration file.""" | ||
fence = "---" | ||
options = { | ||
"isolated": "true", | ||
"mcp": { | ||
"awslabs.aws-documentation-mcp-server": { | ||
"type": "stdio", | ||
"command": "uvx", | ||
"args": ["awslabs.aws-documentation-mcp-server@latest"], | ||
} | ||
}, | ||
"overwrite": "true", | ||
# MCP assistance did not produce noticeably different results, but it was | ||
# slowing things down by 10x. Disabled for now. | ||
# "mcp": { | ||
# "awslabs.aws-documentation-mcp-server": { | ||
# "type": "stdio", | ||
# "command": "uvx", | ||
# "args": ["awslabs.aws-documentation-mcp-server@latest"], | ||
# } | ||
# }, | ||
} | ||
options_block = yaml.dump(options).strip() | ||
prompts_block = "\n".join(system_prompts) | ||
|
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,41 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
from aws_doc_sdk_examples_tools.doc_gen import DocGen | ||
from aws_doc_sdk_examples_tools.metadata import Example | ||
from aws_doc_sdk_examples_tools.agent.update_doc_gen import update_examples | ||
|
||
|
||
@pytest.fixture | ||
def doc_gen_tributary(): | ||
""" | ||
Fixture that returns a DocGen instance using the doc_gen_tributary_test as root. | ||
""" | ||
tributary_root = ( | ||
Path(__file__).parent.parent / "test_resources" / "doc_gen_tributary_test" | ||
) | ||
doc_gen = DocGen.from_root(tributary_root) | ||
doc_gen.collect_snippets() | ||
return doc_gen | ||
|
||
|
||
def smoke_test_doc_gen(doc_gen_tributary: DocGen): | ||
assert isinstance(doc_gen_tributary, DocGen) | ||
|
||
|
||
def test_update_examples_title_abbrev(doc_gen_tributary: DocGen): | ||
"""Test that title_abbrev is updated correctly with service_main suffix.""" | ||
# Create an example with a title_abbrev to update | ||
update_example = Example( | ||
id="iam_policies_example", | ||
file=None, | ||
languages={}, | ||
title_abbrev="Updated Title Abbrev", | ||
) | ||
|
||
# Update the examples | ||
update_examples(doc_gen_tributary, [update_example]) | ||
|
||
# Verify title_abbrev was updated with the service_main suffix | ||
updated_example = doc_gen_tributary.examples["iam_policies_example"] | ||
assert updated_example.title_abbrev == "Updated Title Abbrev (from AWS Account Management)" |
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
21 changes: 21 additions & 0 deletions
21
...est_resources/doc_gen_tributary_test/.doc_gen/metadata/AccountControlApiDoc_metadata.yaml
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,21 @@ | ||
iam_policies_example: | ||
category: IAMPolicy | ||
languages: | ||
IAMPolicyGrammar: | ||
versions: | ||
- authors: | ||
- alias: amazonian@amazon.com | ||
name: Sir Peccy | ||
excerpts: | ||
- description: test | ||
owner: AWS/Documentation/Accounts Management Docs | ||
sdk_version: 1 | ||
source: | ||
title: AWS Account Management | ||
url: https://code.amazon.com/packages/AccountControlApiDoc | ||
services: | ||
iam: {} | ||
synopsis: This identity-based policy allows the attached identity to retrieve the | ||
billing alternate contact information for a specific account within an organization. | ||
title: Allow retrieval of a specific alternate contact type for an account | ||
title_abbrev: Allow retrieval of a specific alternate contact type for an account |
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 |
---|---|---|
|
@@ -19,5 +19,6 @@ | |
"pathspec==0.11.2", | ||
"PyYAML==6.0.1", | ||
"yamale==4.0.4", | ||
"typer==0.16.0", | ||
], | ||
) |
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.
CONSTANT up top