Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ai-examples/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.2.0
++++++
* Add AI generated examples to all group and command "--help"

0.1.0
++++++
* Initial release.
Expand Down
2 changes: 1 addition & 1 deletion src/ai-examples/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Azure CLI 'AI Examples' Extension
==========================================

Improve user experince by adding AI powered examples to command help content.
Improve user experience by adding AI powered examples to command help content.

This extension changes the default examples provided when calling `-h` or `--help` on a command, such as `az vm create -h`, with ones selected by an AI powered service. The service provides examples based on Azure usage, internet sources, and other factors.
4 changes: 2 additions & 2 deletions src/ai-examples/azext_ai_examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
def inject_functions_into_core():
# Replace the default examples from help calls
from azure.cli.core._help import AzCliHelp
from azext_ai_examples.custom import provide_examples
AzCliHelp.example_provider = provide_examples
from azext_ai_examples.custom import new_examples
AzCliHelp.update_examples = new_examples


class AiExamplesCommandsLoader(AzCommandsLoader):
Expand Down
2 changes: 1 addition & 1 deletion src/ai-examples/azext_ai_examples/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.81"
"azext.minCliCoreVersion": "2.2.0"
}
38 changes: 5 additions & 33 deletions src/ai-examples/azext_ai_examples/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,17 @@ def check_connection_aladdin():
print('Connection failed')


# Replacements for core functions
def provide_examples(help_file):
return replace_examples(help_file)
def new_examples(help_file):
help_file.examples = replace_examples(help_file.command)


# Provide two options for changing the examples

# Replace built in examples wirh Aladdin ones
def replace_examples(help_file):
# Replace built in examples with Aladdin ones
def replace_examples(command):
# Specify az to coerce the examples to be for the exact command
lookup_term = "az " + help_file.command
lookup_term = "az " + command
return get_generated_examples(lookup_term)


# Append Aladdin examples to the built in ones
def append_examples(help_file):
# Specify az to coerce the examples to be for the exact command
lookup_term = "az " + help_file.command
aladdin_examples = get_generated_examples(lookup_term)
return concat_unique_examples(help_file.examples, aladdin_examples)


# Support functions
def get_generated_examples(cli_term):
examples = []
Expand All @@ -57,23 +46,6 @@ def get_generated_examples(cli_term):
return examples


def concat_unique_examples(first_list, second_list):
for first_item in first_list:
for second_item in second_list:
if are_examples_equal(first_item, second_item):
second_list.remove(second_item)
return first_list + second_list


def are_examples_equal(first, second):
return clean_string(first.short_summary) == clean_string(second.short_summary) \
or clean_string(first.command) == clean_string(second.command)


def clean_string(text):
return text.strip()


def clean_from_http_answer(http_answer):
example = HelpExample()
example.short_summary = http_answer['title'].strip()
Expand Down
4 changes: 2 additions & 2 deletions src/ai-examples/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logger.warn("Wheel is not available, disabling bdist_wheel hook")

# HISTORY.rst entry.
VERSION = '0.1.0'
VERSION = '0.2.0'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down Expand Up @@ -48,7 +48,7 @@
author='Matthew Booe',
author_email='[email protected]',
url='https://github.com/Azure/azure-cli-extensions/tree/master/src/ai-examples',
long_description='Improve user experince by adding AI powered examples to command help content.',
long_description='Improve user experience by adding AI powered examples to command help content.',
license='MIT',
classifiers=CLASSIFIERS,
packages=find_packages(),
Expand Down