Python: updates to cicd and notebooks (#6485)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Small update to test coverage workflow, to retrigger based on workflow
run.
Small updates to samples notebooks, to use GLOBAL_LLM_SERVICE allowing
control of where they run through env.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
This commit is contained in:
Eduard van Valkenburg
2024-06-03 13:58:02 +00:00
committed by GitHub
parent b0dd67a54d
commit fb8edbef94
23 changed files with 167 additions and 74 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
name: Python Code Quality Checks
on:
workflow_dispatch:
pull_request:
pull_request_target:
branches: [ "main", "feature*" ]
paths:
- 'python/**'
@@ -18,6 +18,7 @@ jobs:
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
service: ['AzureOpenAI']
steps:
- uses: actions/checkout@v4
- name: Install poetry
@@ -31,6 +32,7 @@ jobs:
id: run_tests
shell: bash
env: # Set Azure credentials secret as an input
GLOBAL_LLM_SERVICE: ${{ matrix.service }}
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }}
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_CHAT_DEPLOYMENT_NAME }}
AZURE_OPENAI_TEXT_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_TEXT_DEPLOYMENT_NAME }}
@@ -5,6 +5,10 @@ on:
branches: ["main", "feature*"]
paths:
- "python/**"
workflow_run:
workflows: ["Python Unit Tests"]
types:
- in_progress
jobs:
python-tests-coverage:
@@ -45,8 +45,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.AzureOpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -170,7 +179,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.14"
}
},
"nbformat": 4,
@@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -97,19 +97,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -155,7 +164,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.14"
},
"polyglot_notebook": {
"kernelInfo": {
@@ -117,8 +117,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -60,8 +60,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -38,8 +38,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -35,8 +35,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -42,8 +42,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -82,7 +91,7 @@
"if selectedService == Service.AzureOpenAI:\n",
" azure_chat_service = AzureChatCompletion(service_id=chat_service_id)\n",
" # next line assumes embeddings deployment name is \"text-embedding\", adjust the deployment name to the value of your chat model if needed\n",
" embedding_gen = AzureTextEmbedding(deployment_name=\"text-embedding\")\n",
" embedding_gen = AzureTextEmbedding(service_id=\"embedding\")\n",
" kernel.add_service(azure_chat_service)\n",
" kernel.add_service(embedding_gen)\n",
"elif selectedService == Service.OpenAI:\n",
@@ -33,7 +33,8 @@
"from services import Service\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.HuggingFace"
"selectedService = Service.HuggingFace\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -58,8 +58,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -491,7 +500,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"from semantic_kernel.functions import kernel_function\n",
"\n",
"\n",
@@ -92,15 +92,25 @@
"metadata": {},
"outputs": [],
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"from semantic_kernel import Kernel\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")\n",
"\n",
"kernel = Kernel()\n",
"\n",
"useAzureOpenAI = False\n",
"\n",
"# Configure AI service used by the kernel\n",
"if useAzureOpenAI:\n",
"if selectedService == Service.AzureOpenAI:\n",
" service_id = \"default\"\n",
" azure_chat_service = AzureChatCompletion(\n",
" service_id=service_id\n",
@@ -37,8 +37,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.OpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -47,22 +56,7 @@
"id": "508ad44f",
"metadata": {},
"outputs": [],
"source": [
"from semantic_kernel.contents import ChatHistory\n",
"\n",
"if selectedService == Service.OpenAI or selectedService == Service.AzureOpenAI:\n",
" from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" AzureChatPromptExecutionSettings,\n",
" AzureTextCompletion,\n",
" OpenAIChatCompletion,\n",
" OpenAIChatPromptExecutionSettings,\n",
" OpenAITextCompletion,\n",
" OpenAITextPromptExecutionSettings,\n",
" )\n",
"if selectedService == Service.HuggingFace:\n",
" from semantic_kernel.connectors.ai.hugging_face import HuggingFaceTextCompletion"
]
"source": []
},
{
"attachments": {},
@@ -81,6 +75,19 @@
"outputs": [],
"source": [
"from semantic_kernel import Kernel\n",
"from semantic_kernel.connectors.ai.hugging_face import ( # noqa: F401\n",
" HuggingFacePromptExecutionSettings,\n",
" HuggingFaceTextCompletion,\n",
")\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatPromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.open_ai import OpenAIChatPromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.open_ai import OpenAITextPromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" AzureTextCompletion,\n",
" OpenAIChatCompletion,\n",
" OpenAITextCompletion,\n",
")\n",
"\n",
"kernel = Kernel()\n",
"\n",
@@ -201,10 +208,6 @@
"outputs": [],
"source": [
"if selectedService == Service.HuggingFace:\n",
" from semantic_kernel.connectors.ai.hugging_face.hf_prompt_execution_settings import (\n",
" HuggingFacePromptExecutionSettings,\n",
" )\n",
"\n",
" hf_prompt_execution_settings = HuggingFacePromptExecutionSettings(\n",
" service_id=\"hf_text\", extension_data={\"max_new_tokens\": 80, \"temperature\": 0.7, \"top_p\": 1}\n",
" )"
@@ -269,6 +272,8 @@
"metadata": {},
"outputs": [],
"source": [
"from semantic_kernel.contents import ChatHistory\n",
"\n",
"if selectedService == Service.OpenAI:\n",
" chat = ChatHistory()\n",
" chat.add_user_message(\n",
@@ -30,8 +30,17 @@
"source": [
"from services import Service\n",
"\n",
"from samples.service_settings import ServiceSettings\n",
"\n",
"service_settings = ServiceSettings()\n",
"\n",
"# Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)\n",
"selectedService = Service.AzureOpenAI"
"selectedService = (\n",
" Service.AzureOpenAI\n",
" if service_settings.global_llm_service is None\n",
" else Service(service_settings.global_llm_service.lower())\n",
")\n",
"print(f\"Using service type: {selectedService}\")"
]
},
{
@@ -40,25 +49,7 @@
"id": "508ad44f",
"metadata": {},
"outputs": [],
"source": [
"from semantic_kernel.contents import ChatHistory\n",
"\n",
"if selectedService == Service.OpenAI or selectedService == Service.AzureOpenAI:\n",
" from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" AzureChatPromptExecutionSettings,\n",
" AzureTextCompletion,\n",
" OpenAIChatCompletion,\n",
" OpenAIChatPromptExecutionSettings,\n",
" OpenAITextCompletion,\n",
" OpenAITextPromptExecutionSettings,\n",
" )\n",
"if selectedService == Service.HuggingFace:\n",
" from semantic_kernel.connectors.ai.hugging_face import (\n",
" HuggingFacePromptExecutionSettings,\n",
" HuggingFaceTextCompletion,\n",
" )"
]
"source": []
},
{
"attachments": {},
@@ -77,6 +68,18 @@
"outputs": [],
"source": [
"from semantic_kernel import Kernel\n",
"from semantic_kernel.connectors.ai.hugging_face import HuggingFacePromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.hugging_face import HuggingFaceTextCompletion\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatPromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.open_ai import OpenAIChatPromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.open_ai import OpenAITextPromptExecutionSettings # noqa: F401\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" AzureTextCompletion,\n",
" OpenAIChatCompletion,\n",
" OpenAITextCompletion,\n",
")\n",
"from semantic_kernel.contents import ChatHistory # noqa: F401\n",
"\n",
"kernel = Kernel()\n",
"\n",
+2 -2
View File
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft. All rights reserved.
from .service_settings import ServiceSettings
from .sk_service_configurator import add_service
from ..service_settings import ServiceSettings
from ..sk_service_configurator import add_service
__all__ = ["add_service", "ServiceSettings"]
@@ -3,7 +3,7 @@
import asyncio
import os
from samples.learn_resources.sk_service_configurator import add_service
from samples.sk_service_configurator import add_service
from semantic_kernel.kernel import Kernel
@@ -2,7 +2,7 @@
import asyncio
from samples.learn_resources.sk_service_configurator import add_service
from samples.sk_service_configurator import add_service
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai import PromptExecutionSettings
from semantic_kernel.contents import ChatHistory
+1 -1
View File
@@ -2,7 +2,7 @@
import asyncio
import os
from samples.learn_resources.sk_service_configurator import add_service
from samples.sk_service_configurator import add_service
from semantic_kernel import Kernel
from semantic_kernel.planners.function_calling_stepwise_planner import FunctionCallingStepwisePlanner
@@ -3,7 +3,7 @@
import asyncio
import semantic_kernel as sk
from samples.learn_resources.sk_service_configurator import add_service
from samples.sk_service_configurator import add_service
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
from semantic_kernel.contents.chat_history import ChatHistory
from semantic_kernel.core_plugins import ConversationSummaryPlugin
@@ -2,7 +2,7 @@
import asyncio
from samples.learn_resources.sk_service_configurator import add_service
from samples.sk_service_configurator import add_service
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai import PromptExecutionSettings
from semantic_kernel.functions import KernelArguments
@@ -2,7 +2,7 @@
from pydantic import ValidationError
from samples.learn_resources.service_settings import ServiceSettings
from samples.service_settings import ServiceSettings
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import (
AzureChatCompletion,
@@ -14,10 +14,7 @@ from semantic_kernel.exceptions.service_exceptions import ServiceInitializationE
def add_service(
kernel: Kernel,
use_chat: bool = True,
env_file_path: str | None = None,
env_file_encoding: str | None = None
kernel: Kernel, use_chat: bool = True, env_file_path: str | None = None, env_file_encoding: str | None = None
) -> Kernel:
"""
Configure the AI service for the kernel