-
Notifications
You must be signed in to change notification settings - Fork 399
add the "generate_resource" for the istio agent as tool #11
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
Merged
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from ._istio_crds import generate_resource | ||
| from ._istioctl import proxy_config, verify_install | ||
|
|
||
| __all__ = ["verify_install", "proxy_config"] | ||
| __all__ = ["verify_install", "proxy_config", "generate_resource"] |
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,92 @@ | ||
| from enum import Enum | ||
| from typing import Annotated | ||
|
|
||
| from autogen_core.models import SystemMessage, UserMessage | ||
| from autogen_core.tools import FunctionTool | ||
| from autogen_ext.models.openai import OpenAIChatCompletionClient | ||
|
|
||
| from .prompts import ( | ||
| AUTH_POLICY_PROMPT, | ||
| GATEWAY_PROMPT, | ||
| PEER_AUTHENTICATION_PROMPT, | ||
| VIRTUAL_SERVICE_PROMPT, | ||
| IstioResources, | ||
| ) | ||
|
|
||
|
|
||
| def get_model_client(): | ||
| # TODO: We should have a way to configure externally somehow. | ||
| return OpenAIChatCompletionClient( | ||
| model="gpt-4o-mini", | ||
| ) | ||
|
|
||
|
|
||
| async def _generate_crd(system_prompt: str, policy_description: str) -> str: | ||
| """ | ||
| Asynchronously generates a Custom Resource Definition (CRD) based on the provided system prompt and policy description. | ||
|
|
||
| Args: | ||
| system_prompt (str): The system prompt to guide the CRD generation. | ||
| policy_description (str): The description of the policy to be included in the CRD. | ||
|
|
||
| Returns: | ||
| str: The generated CRD content or an error message if the generation fails. | ||
|
|
||
| Raises: | ||
| Exception: If there is an error during the CRD generation process. | ||
| """ | ||
| try: | ||
| model_client = get_model_client() | ||
| result = await model_client.create( | ||
| messages=[SystemMessage(content=system_prompt), UserMessage(content=policy_description, source="user")], | ||
| json_output=True, | ||
| ) | ||
| return result.content | ||
| except Exception as e: | ||
| return f"Error generating policy: {str(e)}" | ||
|
|
||
|
|
||
| async def _generate_gateway_crd( | ||
| policy_description: Annotated[str, "Detailed description of the Gateway to generate YAML for"], | ||
| ) -> str: | ||
| return await _generate_crd(GATEWAY_PROMPT, policy_description) | ||
|
|
||
|
|
||
| async def _generate_auth_policy_crd( | ||
| policy_description: Annotated[str, "Detailed description of the AuthorizationPolicy to generate YAML for"], | ||
| ) -> str: | ||
| return await _generate_crd(AUTH_POLICY_PROMPT, policy_description) | ||
|
|
||
|
|
||
| async def _generate_peer_auth_crd( | ||
| policy_description: Annotated[str, "Detailed description of the PeerAuthentication to generate YAML for"], | ||
| ) -> str: | ||
| return await _generate_crd(PEER_AUTHENTICATION_PROMPT, policy_description) | ||
|
|
||
|
|
||
| async def _generate_virtual_service_crd( | ||
| policy_description: Annotated[str, "Detailed description of the VirtualService to generate YAML for"], | ||
| ) -> str: | ||
| return await _generate_crd(VIRTUAL_SERVICE_PROMPT, policy_description) | ||
|
|
||
| async def _generate_istio_resource( | ||
| istio_resource: Annotated[IstioResources, "Type of resources to generate"], | ||
| policy_description: Annotated[str, "Detailed description of the resource to generate YAML for"], | ||
| ) -> str: | ||
| if istio_resource == IstioResources.AUTH_POLICY: | ||
| return await _generate_auth_policy_crd(policy_description) | ||
| elif istio_resource == IstioResources.GATEWAY: | ||
| return await _generate_gateway_crd(policy_description) | ||
| elif istio_resource == IstioResources.PEER_AUTHENTICATION: | ||
| return await _generate_peer_auth_crd(policy_description) | ||
| elif istio_resource == IstioResources.VIRTUAL_SERVICE: | ||
| return await _generate_virtual_service_crd(policy_description) | ||
| else: | ||
| return "Unsupported Istio resource type" | ||
|
|
||
|
|
||
| generate_resource = FunctionTool( | ||
| _generate_istio_resource, | ||
| description="Generates an Istio resource YAML configuration from a detailed description", | ||
| name="generate_istio_resource", | ||
| ) | ||
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,11 @@ | ||
| from .auth_policy import AUTH_POLICY_PROMPT | ||
| from .gateway import GATEWAY_PROMPT | ||
| from .peer_auth import PEER_AUTHENTICATION_PROMPT | ||
| from .virtual_service import VIRTUAL_SERVICE_PROMPT | ||
|
|
||
| __all__ = [ | ||
| "AUTH_POLICY_PROMPT", | ||
| "GATEWAY_PROMPT", | ||
| "PEER_AUTHENTICATION_PROMPT", | ||
| "VIRTUAL_SERVICE_PROMPT", | ||
| ] |
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.