Skip to content

Commit

Permalink
update sdk and other requirements; make changes as needed for that (#72)
Browse files Browse the repository at this point in the history
* update sdk and other requirements; make changes as needed for that

* udpate evaluation
  • Loading branch information
robch authored Oct 29, 2023
1 parent 441bce4 commit 9348eb6
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 145 deletions.
38 changes: 38 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda
{
"name": "AI CLI Dev Container",
"build": {
"context": "..",
"dockerfile": "../dockerfiles/debian12.Dockerfile"
},

"hostRequirements": {
"cpus": 8,
"memory": "4gb",
"storage": "64gb"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "python --version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion dockerfiles/debian10.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPY ./scripts/InstallAzureAICLIDeb.sh /_scratch/
COPY ./scripts/InstallAzureAICLIDeb-UpdateVersion.sh /_scratch/

# Feature flags/arguments
ARG AZURE_CLI_VERSION=1.0.0-alpha1010.2
ARG AZURE_CLI_VERSION=1.0.0-alpha1027.1
ARG DOWNLOAD_SCRIPT=false

# If we're downloading the script, do so
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/debian11.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPY ./scripts/InstallAzureAICLIDeb.sh /_scratch/
COPY ./scripts/InstallAzureAICLIDeb-UpdateVersion.sh /_scratch/

# Feature flags/arguments
ARG AZURE_CLI_VERSION=1.0.0-alpha1010.2
ARG AZURE_CLI_VERSION=1.0.0-alpha1027.1
ARG DOWNLOAD_SCRIPT=false

# If we're downloading the script, do so
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/debian12.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPY ./scripts/InstallAzureAICLIDeb.sh /_scratch/
COPY ./scripts/InstallAzureAICLIDeb-UpdateVersion.sh /_scratch/

# Feature flags/arguments
ARG AZURE_CLI_VERSION=1.0.0-alpha1010.2
ARG AZURE_CLI_VERSION=1.0.0-alpha1027.1
ARG DOWNLOAD_SCRIPT=false

# If we're downloading the script, do so
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/ubuntu2004.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY ./scripts/InstallAzureAICLIDeb.sh /_scratch/
COPY ./scripts/InstallAzureAICLIDeb-UpdateVersion.sh /_scratch/

# Feature flags/arguments
ARG AZURE_CLI_VERSION=1.0.0-alpha1010.2
ARG AZURE_CLI_VERSION=1.0.0-alpha1027.1
ARG DOWNLOAD_SCRIPT=false

# If we're downloading the script, do so
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/ubuntu2204.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY ./scripts/InstallAzureAICLIDeb.sh /_scratch/
COPY ./scripts/InstallAzureAICLIDeb-UpdateVersion.sh /_scratch/

# Feature flags/arguments
ARG AZURE_CLI_VERSION=1.0.0-alpha1010.2
ARG AZURE_CLI_VERSION=1.0.0-alpha1027.1
ARG DOWNLOAD_SCRIPT=false

# If we're downloading the script, do so
Expand Down
2 changes: 1 addition & 1 deletion ideas/azure-ai-cli-installation-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Customer Requirements:
- Support Debian 10, 11, and 12, and Ubunutu 20.04 and 22.04
- Uses VS Code base images (e.g. `mcr.microsoft.com/devcontainers/base:bookworm`)
- Tagged similarly to VS Code base images (e.g. `${REGISTRY}/azure-ai-cli:bookworm`)
- Tagged with versions as well (e.g. `${REGISTRY}/azure-ai-cli:bookworm-1.0.0-alpha924.3`)
- Tagged with versions as well (e.g. `${REGISTRY}/azure-ai-cli:bookworm-1.0.0-alpha1027.1`)
- `${REGISTRY}` is currently `acrbn.azurecr.io`
- `${REGISTRY}` likely (???) should be `mcr.microsoft.com`
- `latest` tag points to `${REGISTRY}/azure-ai-cli:bookworm`
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ ipykernel
openai
pydantic<2
azure-search-documents==11.4.0b11
azureml-metrics[generative-ai] @https://azuremlsdktestpypi.blob.core.windows.net/repo/Create-Dev-Index/108397413/azureml_metrics-0.1.0.108397413-py3-none-any.whl
azure-ai-generative[evaluate,index] @https://azuremlsdktestpypi.blob.core.windows.net/repo/test-azure-ai-generative/azure_ai_generative-0.8.3-py3-none-any.whl
azure-ai-resources @https://pkgs.dev.azure.com/azure-sdk/29ec6040-b234-4e31-b139-33dc4287b756/_packaging/3572dbf9-b5ef-433b-9137-fc4d7768e7cc/pypi/download/azure-ai-resources/1a20231026010/azure_ai_resources-1.0.0a20231026010-py3-none-any.whl
azure-ai-generative[evaluate,index,document_parsing] @https://pkgs.dev.azure.com/azure-sdk/29ec6040-b234-4e31-b139-33dc4287b756/_packaging/3572dbf9-b5ef-433b-9137-fc4d7768e7cc/pypi/download/azure-ai-generative/1a20231026010/azure_ai_generative-1.0.0a20231026010-py3-none-any.whl
azure-ai-ml @https://pkgs.dev.azure.com/azure-sdk/29ec6040-b234-4e31-b139-33dc4287b756/_packaging/3572dbf9-b5ef-433b-9137-fc4d7768e7cc/pypi/download/azure-ai-ml/1.12a20231026005/azure_ai_ml-1.12.0a20231026005-py3-none-any.whl

# promptflow dependencies, these should be optional in the future
# hardcoded the version of azureml-mlflow here for faster Docker image building speed
azureml-mlflow==1.53.0
promptflow[azure]
# python-dotenv # promptflow[azure] depends on this package
promptflow-tools
promptflow[azure]==0.1.0b8
promptflow-tools==0.1.0b10
keyring
pytest

# langchain dependencies, these should be optional in the future
# langchain moved Embeddings from langchain.embeddings.base to langchain.schema.embeddings while azureml-rag is still referencing it.
# once azureml-rag fixes, we should remove the langchain reference from this file
langchain==0.0.317
langchain==0.0.324
semantic-kernel

# inference server dependencies
Expand Down
57 changes: 44 additions & 13 deletions src/ai/.x/help/include.python.script.api_key_connection_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import json
import time
from datetime import datetime, timedelta
from azure.ai.generative import AIClient
from azure.ai.generative.entities import Connection
from azure.ai.resources.client import AIClient
from azure.ai.resources.entities import BaseConnection, AzureOpenAIConnection, AzureAISearchConnection, AzureAIServiceConnection
from azure.ai.ml.entities._credentials import ApiKeyConfiguration
from azure.identity import DefaultAzureCredential

def create_api_key_connection(subscription_id, resource_group_name, project_name, connection_name, connection_type, endpoint, key):

def create_api_key_connection(subscription_id, resource_group_name, project_name, connection_name, connection_type, endpoint, key, api_version, kind):
client = AIClient(
credential=DefaultAzureCredential(),
subscription_id=subscription_id,
Expand All @@ -17,14 +16,42 @@ def create_api_key_connection(subscription_id, resource_group_name, project_name
user_agent="ai-cli 0.0.1"
)

conn = Connection(
name=connection_name,
type=connection_type,
credentials=ApiKeyConfiguration(key=key),
target=endpoint,
metadata={"Kind": "dummy", "ApiVersion": "dummy", "ApiType": "dummy"}
)
conn_class = BaseConnection._get_ai_connection_class_from_type(connection_type)

if conn_class == BaseConnection:
# TODO print warning, users shouldn't run into this unless dealing with odd legacy stuff.
conn = conn_class(
name=connection_name,
type=connection_type,
credentials=ApiKeyConfiguration(key=key),
target=endpoint,
)
elif conn_class == AzureOpenAIConnection:
conn = conn_class(
name=connection_name,
credentials=ApiKeyConfiguration(key=key),
target=endpoint,
api_version = api_version,
)
elif conn_class == AzureAISearchConnection:
conn = conn_class(
name=connection_name,
credentials=ApiKeyConfiguration(key=key),
target=endpoint,
api_version=api_version,
)
elif conn_class == AzureAIServiceConnection:
if kind is None:
print("Error: --kind argument is required for Cognitive Service connection.")
return {}
conn = conn_class(
name=connection_name,
credentials=ApiKeyConfiguration(key=key),
target=endpoint,
api_version=api_version,
kind=kind,
)

conn = client.connections.create_or_update(conn)
conn2 = client.connections.get(conn.name)

Expand All @@ -45,9 +72,11 @@ def main():
parser.add_argument("--group", required=False, help="Azure resource group name")
parser.add_argument("--project-name", required=True, help="Azure AI project project name.")
parser.add_argument("--connection-name", required=True, help="Azure AI project connection name.")
parser.add_argument("--connection-type", required=True, help="Azure AI project connection type.")
parser.add_argument("--connection-type", required=True, help="Azure AI project connection type. Accepted types are 'azure-open-ai', 'cognitive-search', and 'cognitive-service'.")
parser.add_argument("--endpoint", required=True, help="Azure AI Project connection endpoint.")
parser.add_argument("--key", required=True, help="Azure AI Project connection key.")
parser.add_argument("--api-version", required=False, help="The expected api version of the service this connection will link to.", default="unset")
parser.add_argument("--kind", required=False, help="Kind of AI Service being connected to. Required for Cognitive Service connections.", default=None)
args = parser.parse_args()

subscription_id = args.subscription
Expand All @@ -57,6 +86,8 @@ def main():
connection_type = args.connection_type
endpoint = args.endpoint
key = args.key
api_version = args.api_version
kind = args.kind

timeout_seconds = 10

Expand All @@ -66,7 +97,7 @@ def main():

while datetime.now() - start_time < timeout:
try:
connection = create_api_key_connection(subscription_id, resource_group_name, project_name, connection_name, connection_type, endpoint, key)
connection = create_api_key_connection(subscription_id, resource_group_name, project_name, connection_name, connection_type, endpoint, key, api_version, kind))
if connection is not None:
success = True
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import json
import time
from datetime import datetime, timedelta
from azure.ai.generative import AIClient
from azure.ai.generative.entities import Connection
from azure.ai.ml.entities._credentials import ApiKeyConfiguration
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential

def get_api_key_connection(subscription_id, resource_group_name, project_name, connection_name):
Expand Down
4 changes: 1 addition & 3 deletions src/ai/.x/help/include.python.script.connection_delete.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import argparse
import json
from azure.ai.generative import AIClient
from azure.ai.generative.entities import Connection
from azure.ai.ml.entities._credentials import ApiKeyConfiguration
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential

def delete_connection(subscription_id, resource_group_name, project_name, connection_name):
Expand Down
4 changes: 1 addition & 3 deletions src/ai/.x/help/include.python.script.connection_list.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import argparse
import json
from azure.ai.generative import AIClient
from azure.ai.generative.entities import Connection
from azure.ai.ml.entities._credentials import ApiKeyConfiguration
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential

def list_connections(subscription_id, resource_group_name, project_name):
Expand Down
21 changes: 7 additions & 14 deletions src/ai/.x/help/include.python.script.function_call_evaluate.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import asyncio
import pathlib
import platform
import json
import os
import sys
from azure.identity import DefaultAzureCredential
from azure.ai.generative import AIClient
from azure.ai.generative.operations._index_data_source import LocalSource, ACSOutputConfig
from azure.ai.generative.functions.build_mlindex import build_mlindex
from azure.ai.generative.entities.mlindex import MLIndex
import asyncio
import argparse
import importlib
import inspect
import json
import os
import pathlib
import sys
from azure.identity import DefaultAzureCredential
from azure.ai.resources.client import AIClient
from typing import Any, List, Dict, Generator

class AutoFlushingStream:
Expand Down Expand Up @@ -257,7 +247,10 @@ def run_and_or_evaluate(subscription_id, resource_group_name, project_name, modu
print("Evaluating... Done!")
print(eval_results)

return eval_results
return {
"metrics_summary": eval_results.metrics_summary,
"artifacts": eval_results.artifacts
}

def main():

Expand Down
26 changes: 14 additions & 12 deletions src/ai/.x/help/include.python.script.hub_create.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import argparse
import json
from azure.ai.ml import MLClient
from azure.ai.ml.entities import WorkspaceHub, ManagedNetwork, WorkspaceHubConfig
from azure.ai.resources.client import AIClient
from azure.ai.resources.entities import AIResource
from azure.ai.ml.entities import ManagedNetwork
from azure.identity import DefaultAzureCredential

def create_hub(subscription_id, resource_group_name, resource_name, location, display_name, description):
"""Create Azure ML hub."""
ml_client = MLClient(
def create_hub(subscription_id, resource_group_name, ai_resource_name, location, display_name, description):
"""Create Azure AI hub."""
ai_client = AIClient(
credential=DefaultAzureCredential(),
subscription_id=subscription_id,
resource_group_name=resource_group_name,
user_agent="ai-cli 0.0.1"
)

wshub = WorkspaceHub(
name=resource_name,
resource = AIResource(
name=ai_resource_name,
location=location,
display_name=display_name,
description=description,
Expand All @@ -24,12 +25,13 @@ def create_hub(subscription_id, resource_group_name, resource_name, location, di
)
)

result = ml_client.workspace_hubs.begin_create(workspace_hub=wshub).result()
return result._to_dict()
# TODO allow setting of optional bool update_dependent_resources?
result = ai_client.ai_resources.begin_create(ai_resource=resource).result()
return result._workspace_hub._to_dict()

def main():
"""Parse command line arguments and print created hub."""
parser = argparse.ArgumentParser(description="Create Azure ML hub")
parser = argparse.ArgumentParser(description="Create Azure AI hub")
parser.add_argument("--subscription", required=True, help="Azure subscription ID")
parser.add_argument("--group", required=True, help="Azure resource group name")
parser.add_argument("--name", required=True, help="Azure AI resource display name. This is non-unique within the resource group.")
Expand All @@ -40,12 +42,12 @@ def main():

subscription_id = args.subscription
resource_group_name = args.group
resource_name = args.name
ai_resource_name = args.name
location = args.location
display_name = args.display_name
description = args.description

hub = create_hub(subscription_id, resource_group_name, resource_name, location, display_name, description)
hub = create_hub(subscription_id, resource_group_name, ai_resource_name, location, display_name, description)
formatted = json.dumps({"hub": hub}, indent=2)

print("---")
Expand Down
16 changes: 8 additions & 8 deletions src/ai/.x/help/include.python.script.hub_delete.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import argparse
import json
from azure.ai.ml import MLClient
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential

def delete_hub(subscription_id, resource_group_name, resource_name, delete_dependent_resources):
"""Delete Azure ML hubs."""
ml_client = MLClient(
def delete_hub(subscription_id, resource_group_name, ai_resource_name, delete_dependent_resources):
"""Delete Azure AI hubs."""
ai_client = AIClient(
credential=DefaultAzureCredential(),
subscription_id=subscription_id,
resource_group_name=resource_group_name,
user_agent="ai-cli 0.0.1"
)

result = ml_client.workspace_hubs.begin_delete(resource_name, delete_dependent_resources=delete_dependent_resources).result()
result = ai_client.ai_resources.begin_delete(name=ai_resource_name, delete_dependent_resources=delete_dependent_resources).result()
return result

def main():
"""Parse command line arguments and delete's the hub."""
parser = argparse.ArgumentParser(description="Delete Azure ML hub")
parser = argparse.ArgumentParser(description="Delete Azure AI hub")
parser.add_argument("--subscription", required=True, help="Azure subscription ID")
parser.add_argument("--group", required=True, help="Azure resource group name")
parser.add_argument("--name", required=True, help="Azure resource hub name")
Expand All @@ -26,10 +26,10 @@ def main():

subscription_id = args.subscription
resource_group_name = args.group
resource_name = args.name;
ai_resource_name = args.name;
delete_dependent_resources = args.delete_dependent_resources

result = delete_hub(subscription_id, resource_group_name, resource_name, delete_dependent_resources)
result = delete_hub(subscription_id, resource_group_name, ai_resource_name, delete_dependent_resources)
formatted = json.dumps(result, indent=2)

print("---")
Expand Down
Loading

0 comments on commit 9348eb6

Please sign in to comment.