Python: switch to uv (#8320)

### 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.
-->
Switches from poetry to uv
much faster and easier lock management
easier maintenance of pyproject.toml

fixes: #6584
fixes: #8326

### 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
- [ ] I didn't break anyone 😄
This commit is contained in:
Eduard van Valkenburg
2024-08-26 13:34:29 +02:00
committed by GitHub
parent 163d512753
commit f90538b9c0
24 changed files with 5836 additions and 8379 deletions
-45
View File
@@ -1,45 +0,0 @@
name: python-build-wheel
on:
workflow_dispatch:
push:
branches: [ "python_preview" ]
permissions:
contents: read
jobs:
build-wheel:
runs-on: ubuntu-latest
defaults:
run:
working-directory: python
steps:
- uses: actions/checkout@v4
- run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: "poetry"
cache-dependency-path: "python/pyproject.toml"
- name: Install Semantic Kernel
run: poetry install --no-ansi
- name: Build wheel
run: poetry build
- name: Upload wheel file to artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: python/dist/*
+64 -28
View File
@@ -49,27 +49,37 @@ jobs:
matrix:
python-version: ["3.11"]
os: [ubuntu-latest]
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Restore uv cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install dependencies with hnswlib native disabled
if: matrix.os == 'macos-latest' && matrix.python-version == '3.11'
run: |
export HNSWLIB_NO_NATIVE=1
python -m pip install --upgrade pip setuptools wheel
cd python && poetry install --with tests
uv sync --all-extras --dev
- name: Install dependencies with hnswlib native enabled
if: matrix.os != 'macos-latest' || matrix.python-version != '3.11'
run: |
python -m pip install --upgrade pip setuptools wheel
cd python
poetry install --with tests
uv sync --all-extras --dev
- name: Install Ollama
if: matrix.os == 'ubuntu-latest'
run: |
@@ -98,7 +108,7 @@ jobs:
- name: Run Integration Tests
id: run_tests
shell: bash
env: # Set Azure credentials secret as an input
env:
HNSWLIB_NO_NATIVE: 1
Python_Integration_Tests: Python_Integration_Tests
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }} # azure-text-embedding-ada-002
@@ -137,7 +147,7 @@ jobs:
REDIS_CONNECTION_STRING: ${{ vars.REDIS_CONNECTION_STRING }}
run: |
cd python
poetry run pytest -n logical --dist loadfile --dist worksteal ./tests/integration ./tests/samples -v --junitxml=pytest.xml
uv run pytest -n logical --dist loadfile --dist worksteal ./tests/integration ./tests/samples -v --junitxml=pytest.xml
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
@@ -155,6 +165,8 @@ jobs:
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: Minimize uv cache
run: uv cache prune --ci
python-integration-tests:
needs: paths-filter
@@ -168,26 +180,32 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Restore uv cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install dependencies with hnswlib native disabled
if: matrix.os == 'macos-latest' && matrix.python-version == '3.11'
run: |
export HNSWLIB_NO_NATIVE=1
python -m pip install --upgrade pip setuptools wheel
cd python && poetry install --with tests
uv sync --all-extras --dev
- name: Install dependencies with hnswlib native enabled
if: matrix.os != 'macos-latest' || matrix.python-version != '3.11'
run: |
python -m pip install --upgrade pip setuptools wheel
cd python && poetry install --with tests
uv sync --all-extras --dev
- name: Install Ollama
if: matrix.os == 'ubuntu-latest'
run: |
@@ -209,11 +227,15 @@ jobs:
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
- name: Setup Redis Stack Server
if: matrix.os == 'ubuntu-latest'
run: docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest
- name: Run Integration Tests
id: run_tests
shell: bash
env: # Set Azure credentials secret as an input
env:
HNSWLIB_NO_NATIVE: 1
Python_Integration_Tests: Python_Integration_Tests
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }} # azure-text-embedding-ada-002
@@ -240,6 +262,8 @@ jobs:
MISTRALAI_API_KEY: ${{secrets.MISTRALAI_API_KEY}}
MISTRALAI_CHAT_MODEL_ID: ${{ vars.MISTRALAI_CHAT_MODEL_ID }}
MISTRALAI_EMBEDDING_MODEL_ID: ${{ vars.MISTRALAI_EMBEDDING_MODEL_ID }}
ANTHROPIC_API_KEY: ${{secrets.ANTHROPIC_API_KEY}}
ANTHROPIC_CHAT_MODEL_ID: ${{ vars.ANTHROPIC_CHAT_MODEL_ID }}
OLLAMA_MODEL: "${{ matrix.os == 'ubuntu-latest' && vars.OLLAMA_MODEL || '' }}" # phi3
GOOGLE_AI_GEMINI_MODEL_ID: ${{ vars.GOOGLE_AI_GEMINI_MODEL_ID }}
GOOGLE_AI_EMBEDDING_MODEL_ID: ${{ vars.GOOGLE_AI_EMBEDDING_MODEL_ID }}
@@ -248,16 +272,28 @@ jobs:
VERTEX_AI_GEMINI_MODEL_ID: ${{ vars.VERTEX_AI_GEMINI_MODEL_ID }}
VERTEX_AI_EMBEDDING_MODEL_ID: ${{ vars.VERTEX_AI_EMBEDDING_MODEL_ID }}
REDIS_CONNECTION_STRING: ${{ vars.REDIS_CONNECTION_STRING }}
ANTHROPIC_API_KEY: ${{secrets.ANTHROPIC_API_KEY}}
ANTHROPIC_CHAT_MODEL_ID: ${{ vars.ANTHROPIC_CHAT_MODEL_ID }}
run: |
if ${{ matrix.os == 'ubuntu-latest' }}; then
docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest
fi
cd python
poetry run pytest -n logical --dist loadfile --dist worksteal ./tests/integration -v
poetry run pytest -n logical --dist loadfile --dist worksteal ./tests/samples -v
uv run pytest -n logical --dist loadfile --dist worksteal ./tests/integration ./tests/samples -v --junitxml=pytest.xml
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
with:
# A list of JUnit XML files, directories containing the former, and wildcard
# patterns to process.
# See @actions/glob for supported patterns.
path: python/pytest.xml
# (Optional) Add a summary of the results at the top of the report
summary: true
# (Optional) Select which results should be included in the report.
# Follows the same syntax as `pytest -r`
display-options: fEX
# (Optional) Fail the workflow if no JUnit XML was found.
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: Minimize uv cache
run: uv cache prune --ci
# This final job is required to satisfy the merge queue. It must only run (or succeed) if no tests failed
python-integration-tests-check:
+21 -6
View File
@@ -15,14 +15,29 @@ jobs:
python-version: ["3.10"]
runs-on: ubuntu-latest
continue-on-error: true
defaults:
run:
working-directory: python
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: cd python && poetry install
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install the project
run: uv sync --all-extras --dev
- uses: pre-commit/[email protected]
with:
extra_args: --config python/.pre-commit-config.yaml
- name: Minimize uv cache
run: uv cache prune --ci
+37 -14
View File
@@ -5,6 +5,9 @@ on:
branches: ["main", "feature*"]
paths:
- "python/**"
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache
jobs:
python-unit-tests:
@@ -28,17 +31,27 @@ jobs:
working-directory: python
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: poetry install --with unit-tests
- name: Restore uv cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install the project
run: uv sync --all-extras --dev
- name: Test with pytest
run: poetry run pytest --junitxml=pytest.xml ./tests/unit
run: uv run pytest --junitxml=pytest.xml ./tests/unit
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
@@ -56,6 +69,8 @@ jobs:
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: Minimize uv cache
run: uv cache prune --ci
python-test-coverage:
name: Python Test Coverage
runs-on: [ubuntu-latest]
@@ -65,21 +80,27 @@ jobs:
defaults:
run:
working-directory: python
env:
PYTHON_VERSION: "3.10"
steps:
- uses: actions/checkout@v4
- name: Setup filename variables
run: echo "FILE_ID=${{ github.event.number }}" >> $GITHUB_ENV
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.10
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
- name: Install dependencies
run: poetry install --with unit-tests
python-version: ${{ env.PYTHON_VERSION }}
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/uv.lock') }}
- name: Install the project
run: uv sync --all-extras --dev
- name: Test with pytest
run: poetry run pytest -q --junitxml=pytest.xml --cov=semantic_kernel --cov-report=term-missing:skip-covered ./tests/unit | tee python-coverage.txt
run: uv run pytest -q --junitxml=pytest.xml --cov=semantic_kernel --cov-report=term-missing:skip-covered ./tests/unit | tee python-coverage.txt
- name: Upload coverage
if: always()
uses: actions/upload-artifact@v4
@@ -96,3 +117,5 @@ jobs:
path: python/pytest.xml
overwrite: true
retention-days: 1
- name: Minimize uv cache
run: uv cache prune --ci
+1
View File
@@ -461,6 +461,7 @@ env/
venv/
myvenv/
ENV/
.venv*/
# Python dist
dist/
+13 -104
View File
@@ -8,7 +8,10 @@
"label": "setup (contributing-R#)",
"detail": "",
"group": "build",
"dependsOn": ["new tool-manifest", "# Setup"],
"dependsOn": [
"new tool-manifest",
"# Setup"
],
"dependsOrder": "sequence"
},
{
@@ -16,7 +19,10 @@
"detail": "Install ReSharper Global Tools",
"command": "dotnet",
"type": "process",
"args": ["new", "tool-manifest"],
"args": [
"new",
"tool-manifest"
],
"options": {
"cwd": "${workspaceFolder}/dotnet"
}
@@ -88,54 +94,6 @@
],
"dependsOrder": "sequence"
},
// *****************************
// Contributing (python) - Setup
// *****************************
{
"label": "setup (contributing-python)",
"detail": "",
"group": "build",
"dependsOn": ["install poetry", "install python packages"],
"dependsOrder": "sequence"
},
{
"label": "install poetry",
"detail": "Install poetry",
"command": "pip3",
"type": "shell",
"args": ["install", "poetry"],
"options": {
"cwd": "${workspaceFolder}/python"
}
},
{
"label": "install python packages",
"detail": "Install python packages",
"command": "poetry",
"type": "shell",
"args": ["install"],
"options": {
"cwd": "${workspaceFolder}/python"
}
},
// Formatting
{
"label": "validate (contributing-python)",
"command": "poetry",
"type": "shell",
"group": "build",
"args": [
"run",
"pre-commit",
"run",
"-c",
".conf/.pre-commit-config.yaml",
"-a"
],
"options": {
"cwd": "${workspaceFolder}/python"
}
},
// ***************
// Kernel (dotnet)
// ***************
@@ -163,7 +121,10 @@
"label": "test (Semantic-Kernel)",
"command": "dotnet",
"type": "process",
"args": ["test", "SemanticKernel.UnitTests.csproj"],
"args": [
"test",
"SemanticKernel.UnitTests.csproj"
],
"problemMatcher": "$msCompile",
"group": "test",
"presentation": {
@@ -271,58 +232,6 @@
}
},
// ****************
// Kernel (python)
// ****************
// Test
{
"label": "test (Semantic-Kernel-Python)",
"command": "poetry",
"type": "shell",
"args": ["run", "pytest", "tests/unit"],
"problemMatcher": "$msCompile",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared",
"group": "PR-Validate"
},
"options": {
"cwd": "${workspaceFolder}/python"
}
},
{
"label": "test (Semantic-Kernel-Python Integration)",
"command": "poetry",
"type": "shell",
"args": ["run", "pytest", "tests/integration", "-k", "${input:filter}"],
"problemMatcher": "$msCompile",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared",
"group": "PR-Validate"
},
"options": {
"cwd": "${workspaceFolder}/python"
}
},
{
"label": "test (Semantic-Kernel-Python ALL)",
"command": "poetry",
"type": "shell",
"args": ["run", "pytest", "tests", "-k", "${input:filter}"],
"problemMatcher": "$msCompile",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared",
"group": "PR-Validate"
},
"options": {
"cwd": "${workspaceFolder}/python"
}
},
// ****************
// Samples (dotnet)
// ****************
// Kernel Syntax Examples
@@ -380,4 +289,4 @@
"description": "Enter a filter to pass as argument or filter"
}
]
}
}
-14
View File
@@ -1,14 +0,0 @@
{
"black": {
"repo": "https://github.com/psf/black",
"rev": "${rev}"
},
"mypy": {
"repo": "https://github.com/pre-commit/mirrors-mypy",
"rev": "v${rev}"
},
"ruff": {
"repo": "https://github.com/astral-sh/ruff-pre-commit",
"rev": "v${rev}"
}
}
+5 -25
View File
@@ -8,30 +8,11 @@ AZURE_OPENAI_TEXT_DEPLOYMENT_NAME=""
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""
AZURE_OPENAI_API_VERSION="2024-02-15-preview"
AZURE_OPENAI_TEMPERATURE=0
AZURE_OPENAI_MAX_TOKENS=1000
AZURE_OPENAI_TOP_P=1.0
AZURE_OPENAI_STREAM=true
AZURE_OPENAI_API_VERSION=""
AZURE_AISEARCH_URL=""
AZURE_AISEARCH_SERVICE=""
AZURE_AISEARCH_API_KEY=""
AZURE_AISEARCH_INDEX_NAME=""
AZURE_AISEARCH_EMBEDDING_DEPLOYMENT_NAME=""
AZURE_AISEARCH_USE_SEMANTIC_SEARCH=false
AZURE_AISEARCH_SEMANTIC_SEARCH_CONFIG=default
AZURE_AISEARCH_INDEX_IS_PRECHUNKED=false
AZURE_AISEARCH_TOP_K=5
AZURE_AISEARCH_ENABLE_IN_DOMAIN=true
AZURE_AISEARCH_CONTENT_COLUMNS=content
AZURE_AISEARCH_FILEPATH_COLUMN=filepath
AZURE_AISEARCH_TITLE_COLUMN=title
AZURE_AISEARCH_URL_COLUMN=url
AZURE_AISEARCH_VECTOR_COLUMNS=contentVector
AZURE_AISEARCH_QUERY_TYPE=simple
AZURE_AISEARCH_PERMITTED_GROUPS_COLUMN=
AZURE_AISEARCH_STRICTNESS=3
AZURE_AISEARCH_FILTER=""
MONGODB_ATLAS_CONNECTION_STRING=""
PINECONE_API_KEY=""
PINECONE_ENVIRONMENT=""
@@ -40,11 +21,10 @@ WEAVIATE_URL=""
WEAVIATE_API_KEY=""
GOOGLE_SEARCH_ENGINE_ID=""
REDIS_CONNECTION_STRING=""
AZCOSMOS_API = "" // should be mongo-vcore for now, as CosmosDB only supports vector search in mongo-vcore for now.
AZCOSMOS_CONNSTR = ""
AZCOSMOS_DATABASE_NAME = ""
AZCOSMOS_CONTAINER_NAME = ""
# Starts with AstraCS:
AZCOSMOS_API=""
AZCOSMOS_CONNSTR=""
AZCOSMOS_DATABASE_NAME=""
AZCOSMOS_CONTAINER_NAME=""
ASTRADB_APP_TOKEN=""
ASTRADB_ID=""
ASTRADB_REGION=""
@@ -1,11 +1,6 @@
files: ^python/
fail_fast: true
repos:
- repo: https://github.com/floatingpurr/sync_with_poetry
rev: 1.1.0
hooks:
- id: sync_with_poetry
args: [--config=.pre-commit-config.yaml, --db=python/.conf/packages_list.json, python/poetry.lock]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
@@ -32,7 +27,7 @@ repos:
name: Check Valid Python Notebooks
types: ["jupyter"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py310-plus]
@@ -41,12 +36,19 @@ repos:
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.3.3
hooks:
# Update the uv lockfile
- id: uv-lock
- repo: local
hooks:
- id: mypy
files: ^python/semantic_kernel/
name: mypy
entry: poetry -C python/ run python -m mypy -p semantic_kernel --config-file=python/mypy.ini
entry: cd python && uv run mypy -p semantic_kernel --config-file mypy.ini
language: system
types: [python]
pass_filenames: false
+23 -14
View File
@@ -6,7 +6,7 @@
{
"label": "Python: Run Checks",
"type": "shell",
"command": "poetry",
"command": "uv",
"args": [
"run",
"pre-commit",
@@ -34,7 +34,7 @@
{
"label": "Python: Run Checks - Staged",
"type": "shell",
"command": "poetry",
"command": "uv",
"args": [
"run",
"pre-commit",
@@ -61,7 +61,7 @@
{
"label": "Python: Run Mypy",
"type": "shell",
"command": "poetry",
"command": "uv",
"args": [
"run",
"pre-commit",
@@ -90,21 +90,17 @@
{
"label": "Python: Install",
"type": "shell",
"command": "poetry",
"args": [
"install",
"--all-extras"
],
"command": "make install PYTHON_VERSION=${input:py_version}",
"presentation": {
"reveal": "silent",
"panel": "shared"
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
},
{
"label": "Python: Tests - Unit",
"type": "shell",
"command": "poetry",
"command": "uv",
"args": [
"run",
"pytest",
@@ -120,7 +116,7 @@
{
"label": "Python: Tests - Unit - Failed Only",
"type": "shell",
"command": "poetry",
"command": "uv",
"args": [
"run",
"pytest",
@@ -138,7 +134,7 @@
{
"label": "Python: Tests - Code Coverage",
"type": "shell",
"command": "poetry run pytest --cov=semantic_kernel --cov-report=term-missing:skip-covered tests/unit/",
"command": "uv run pytest --cov=semantic_kernel --cov-report=term-missing:skip-covered tests/unit/",
"group": "test",
"presentation": {
"reveal": "always",
@@ -149,7 +145,7 @@
{
"label": "Python: Tests - All",
"type": "shell",
"command": "poetry",
"command": "uv",
"args": [
"run",
"pytest",
@@ -168,5 +164,18 @@
},
"problemMatcher": []
}
],
"inputs": [
{
"type": "pickString",
"options": [
"3.10",
"3.11",
"3.12"
],
"id": "py_version",
"description": "Python version",
"default": "3.10"
}
]
}
+115 -157
View File
@@ -1,9 +1,88 @@
# Dev Setup
This document describes how to setup your environment with Python and Poetry,
This document describes how to setup your environment with Python and uv,
if you're working on new features or a bug fix for Semantic Kernel, or simply
want to run the tests included.
## System setup
## If you're on WSL
Check that you've cloned the repository to `~/workspace` or a similar folder.
Avoid `/mnt/c/` and prefer using your WSL user's home directory.
Ensure you have the WSL extension for VSCode installed.
## Using uv
uv allows us to use SK from the local files, without worrying about paths, as
if you had SK pip package installed.
To install SK and all the required tools in your system, first, navigate to the directory containing
this DEV_SETUP using your chosen shell.
### For windows (non-WSL)
Check the [uv documentation](https://docs.astral.sh/uv/getting-started/installation/) for the installation instructions. At the time of writing this is the command to install uv:
```powershell
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
```
You can then run the following commands manually:
```powershell
# Install Python 3.10, 3.11, and 3.12
uv python install 3.10 3.11 3.12
# Create a virtual environment with Python 3.10 (you can change this to 3.11 or 3.12)
$PYTHON_VERSION = "3.10"
uv venv --python $PYTHON_VERSION
# Install SK and all dependencies
uv sync --all-extras --dev
# Install pre-commit hooks
uv run pre-commit install -c python/.pre-commit-config.yaml
```
Or you can then either install [`make`](https://gnuwin32.sourceforge.net/packages/make.htm) and then follow the guide for Mac and Linux, or run the following commands, the commands are shown as bash but should work in powershell as well.
### For Mac and Linux (both native and WSL)
It is super simple to get started, run the following commands:
```bash
make install
```
This will install uv, python, Semantic Kernel and all dependencies and the pre-commit config. It uses python 3.10 by default, if you want to change that set the `PYTHON_VERSION` environment variable to the desired version (currently supported are 3.10, 3.11, 3.12). For instance for 3.12"
```bash
make install PYTHON_VERSION=3.12
```
If you want to change python version (without installing uv, python and pre-commit), you can use the same parameter, but do:
```bash
make install-sk PYTHON_VERSION=3.12
```
ℹ️ **Note**: Running the install or install-sk command will wipe away your existing virtual environment and create a new one.
Alternatively you can run the VSCode task `Python: Install` to run the same command.
## VSCode Setup
Open the workspace in [VSCode](https://code.visualstudio.com/docs/editor/workspaces).
> The workspace for python should be rooted in the `./python` folder.
Open any of the `.py` files in the project and run the `Python: Select Interpreter`
command from the command palette. Make sure the virtual env (default path is `.venv`) created by
`uv` is selected.
If prompted, install `ruff`. (It should have been installed as part of `uv sync --dev`).
You also need to install the `ruff` extension in VSCode so that auto-formatting uses the `ruff` formatter on save.
Read more about the extension [here](https://github.com/astral-sh/ruff-vscode).
## LLM setup
Make sure you have an
@@ -12,153 +91,36 @@ Make sure you have an
There are two methods to manage keys, secrets, and endpoints:
1. Store them in environment variables. SK Python leverages pydantic settings to load keys, secrets, and endpoints. This means that there is a first attempt to load them from environment variables. The `.env` file naming applies to how the names should be stored as environment variables.
1. Store them in environment variables. SK Python leverages pydantic settings to load keys, secrets, and endpoints from the environment.
> When you are using VSCode and have the python extension setup, it automatically loads environment variables from a `.env` file, so you don't have to manually set them in the terminal.
> During runtime on different platforms, environment settings set as part of the deployments should be used.
2. If you'd like to use the `.env` file, you will need to configure the `.env` file with the following keys into a `.env` file (see the `.env.example` file):
2. Store them in a separate `.env` file, like `dev.env`, you can then pass that name into the constructor for most services, to the `env_file_path` parameter, see below.
> Do not store `*.env` files in your repository, and make sure to add them to your `.gitignore` file.
```
There are a lot of settings, for a more extensive list of settings, see [ALL_SETTINGS.md](./samples/concepts/setup/ALL_SETTINGS.md).
### Example for file-based setup with OpenAI Chat Completions
To configure a `.env` file with just the keys needed for OpenAI Chat Completions, you can create a `openai.env` (this name is just as an example, a single `.env` with all required keys is more common) file in the root of the `python` folder with the following content:
Content of `openai.env`:
```env
OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=""
AZURE_OPENAI_TEXT_DEPLOYMENT_NAME=""
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""
OPENAI_CHAT_MODEL_ID="gpt-4o-mini"
```
You will then configure the Text/ChatCompletion class with the keyword argument `env_file_path`:
You will then configure the ChatCompletion class with the keyword argument `env_file_path`:
```python
chat_completion = OpenAIChatCompletion(service_id="test", env_file_path=<path_to_file>)
chat_completion = OpenAIChatCompletion(service_id="test", env_file_path="openai.env")
```
This optional `env_file_path` parameter will allow pydantic settings to use the `.env` file as a fallback to read the settings.
If using the second method, we suggest adding a copy of the `.env` file under these folders:
- [./tests](./tests)
- [./samples/getting_started](./samples/getting_started).
## System setup
To get started, you'll need VSCode and a local installation of Python 3.8+.
You can run:
```python
python3 --version ; pip3 --version ; code -v
```
to verify that you have the required dependencies.
## If you're on WSL
Check that you've cloned the repository to `~/workspace` or a similar folder.
Avoid `/mnt/c/` and prefer using your WSL user's home directory.
Ensure you have the WSL extension for VSCode installed (and the Python extension
for VSCode installed).
You'll also need `pip3` installed. If you don't yet have a `python3` install in WSL,
you can run:
```bash
sudo apt-get update && sudo apt-get install python3 python3-pip
```
ℹ️ **Note**: if you don't have your PATH setup to find executables installed by `pip3`,
you may need to run `~/.local/bin/poetry install` and `~/.local/bin/poetry shell`
instead. You can fix this by adding `export PATH="$HOME/.local/bin:$PATH"` to
your `~/.bashrc` and closing/re-opening the terminal.\_
## Using Poetry
Poetry allows to use SK from the local files, without worrying about paths, as
if you had SK pip package installed.
To install Poetry in your system, first, navigate to the directory containing
this README using your chosen shell. You will need to have Python 3.10, 3.11, or 3.12
installed.
Install the Poetry package manager and create a project virtual environment.
Note: SK requires at least Poetry 1.2.0.
### Note for MacOS Users
It is best to install Poetry using their
[official installer](https://python-poetry.org/docs/#installing-with-the-official-installer).
On MacOS, you might find that `python` commands are not recognized by default,
and you can only use `python3`. To make it easier to run `python ...` commands
(which Poetry requires), you can create an alias in your shell configuration file.
Follow these steps:
1. **Open your shell configuration file**:
- For **Bash**: `nano ~/.bash_profile` or `nano ~/.bashrc`
- For **Zsh** (default on macOS Catalina and later): `nano ~/.zshrc`
2. **Add the alias**:
```sh
alias python='python3'
```
3. **Save the file and exit**:
- In `nano`, press `CTRL + X`, then `Y`, and hit `Enter`.
4. **Apply the changes**:
- For **Bash**: `source ~/.bash_profile` or `source ~/.bashrc`
- For **Zsh**: `source ~/.zshrc`
After these steps, you should be able to use `python` in your terminal to run
Python 3 commands.
### Poetry Installation
```bash
# Install poetry package if not choosing to install via their official installer
pip3 install poetry
# optionally, define which python version you want to use
poetry env use python3.11
# Use poetry to install base project dependencies
poetry install
# If you want to get all dependencies for tests installed, use
# poetry install --with tests
# example: poetry install --with hugging_face
# Use poetry to activate project venv
poetry shell
# Optionally, you can install the pre-commit hooks
poetry run pre-commit install
# this will run linters and mypy checks on all the changed code.
```
## VSCode Setup
Open the [workspace](https://code.visualstudio.com/docs/editor/workspaces) in VSCode.
> The Python workspace is the `./python` folder if you are at the root of the repository.
Open any of the `.py` files in the project and run the `Python: Select Interpreter`
command from the command palette. Make sure the virtual env (venv) created by
`poetry` is selected.
The python you're looking for should be under `~/.cache/pypoetry/virtualenvs/semantic-kernel-.../bin/python`.
If prompted, install `ruff`. (It should have been installed as part of `poetry install`).
You also need to install the `ruff` extension in VSCode so that auto-formatting uses the `ruff` formatter on save.
Read more about the extension here: https://github.com/astral-sh/ruff-vscode
## Tests
You can run the unit tests under the [tests/unit](tests/unit/) folder.
```bash
poetry install --with unit-tests
poetry run pytest tests/unit
uv run pytest tests/unit
```
Alternatively, you can run them using VSCode Tasks. Open the command palette
@@ -167,21 +129,18 @@ Alternatively, you can run them using VSCode Tasks. Open the command palette
You can run the integration tests under the [tests/integration](tests/integration/) folder.
```bash
poetry install --with tests
poetry run pytest tests/integration
uv run pytest tests/integration
```
You can also run all the tests together under the [tests](tests/) folder.
```bash
poetry install
poetry run pytest tests
uv run pytest tests
```
Alternatively, you can run them using VSCode Tasks. Open the command palette
(`Ctrl+Shift+P`) and type `Tasks: Run Task`. Select `Python: Tests - All` from the list.
## Tools and scripts
## Implementation Decisions
@@ -203,9 +162,9 @@ They should contain:
- If necessary to further explain the logic a newline follows the first line and then the explanation is given.
- The following three sections are optional, and if used should be separated by a single empty line.
- Arguments are then specified after a header called `Args:`, with each argument being specified in the following format:
- `arg_name` (`arg_type`): Explanation of the argument, arg_type is optional, as long as you are consistent.
- `arg_name`: Explanation of the argument.
- if a longer explanation is needed for a argument, it should be placed on the next line, indented by 4 spaces.
- Default values do not have to be specified, they will be pulled from the definition.
- Type and default values do not have to be specified, they will be pulled from the definition.
- Returns are specified after a header called `Returns:` or `Yields:`, with the return type and explanation of the return value.
- Finally, a header for exceptions can be added, called `Raises:`, with each exception being specified in the following format:
- `ExceptionType`: Explanation of the exception.
@@ -227,12 +186,12 @@ def equal(arg1: str, arg2: str) -> bool:
Here is extra explanation of the logic involved.
Args:
arg1 (str): The first string to compare.
arg2 (str): The second string to compare.
arg1: The first string to compare.
arg2: The second string to compare.
This string requires extra explanation.
Returns:
bool: True if the strings are the same, False otherwise.
True if the strings are the same, False otherwise.
Raises:
ValueError: If one of the strings is empty.
@@ -244,11 +203,8 @@ If in doubt, use the link above to read much more considerations of what to do a
## Pydantic and Serialization
[Pydantic Documentation](https://docs.pydantic.dev/1.10/)
### Overview
This section describes how one can enable serialization for their class using Pydantic.
For more info you can refer to the [Pydantic Documentation](https://docs.pydantic.dev/latest/).
### Upgrading existing classes to use Pydantic
@@ -263,7 +219,7 @@ class A:
self.d = d
```
You would convert this to a Pydantic class by subclassing from the `KernelBaseModel` class.
You would convert this to a Pydantic class by sub-classing from the `KernelBaseModel` class.
```python
from pydantic import Field
@@ -298,10 +254,13 @@ class A:
You can use the `KernelBaseModel` to convert these to pydantic serializable classes.
```python
from typing import Generic
from typing import Generic, TypeVar
from semantic_kernel.kernel_pydantic import KernelBaseModel
T1 = TypeVar("T1")
T2 = TypeVar("T2", bound=<some class>)
class A(KernelBaseModel, Generic[T1, T2]):
# T1 and T2 must be specified in the Generic argument otherwise, pydantic will
# NOT be able to serialize this class
@@ -310,32 +269,31 @@ class A(KernelBaseModel, Generic[T1, T2]):
c: T2
```
## Pipeline checks
## Code quality checks
To run the same checks that run during the GitHub Action build, you can use
this command, from the [python](../python) folder:
To run the same checks that run during a commit and the GitHub Action `Python Code Quality Checks`, you can use this command, from the [python](../python) folder:
```bash
poetry run pre-commit run -a
uv run pre-commit run -a
```
or use the following task (using `Ctrl+Shift+P`):
- `Python - Run Checks` to run the checks on the whole project.
- `Python - Run Checks - Staged` to run the checks on the currently staged files only.
Ideally you should run these checks before committing any changes, use `poetry run pre-commit install` to set that up.
Ideally you should run these checks before committing any changes, when you install using the instructions above the pre-commit hooks should be installed already.
## Code Coverage
We try to maintain a high code coverage for the project. To run the code coverage on the unit tests, you can use the following command:
```bash
poetry run pytest --cov=semantic_kernel --cov-report=term-missing:skip-covered tests/unit/
uv run pytest --cov=semantic_kernel --cov-report=term-missing:skip-covered tests/unit/
```
or use the following task (using `Ctrl+Shift+P`):
- `Python: Tests - Code Coverage` to run the code coverage on the whole project.
This will show you which files are not covered by the tests, including the specific lines not covered.
This will show you which files are not covered by the tests, including the specific lines not covered. Make sure to consider the untested lines from the code you are working on, but feel free to add other tests as well, that is always welcome!
## Catching up with the latest changes
There are many people committing to Semantic Kernel, so it is important to keep your local repository up to date. To do this, you can run the following commands:
+59 -43
View File
@@ -1,54 +1,70 @@
SHELL = bash
SHELL = /bin/bash
.PHONY: help install recreate-env pre-commit
.PHONY: help install clean
.SILENT:
all: install
ifeq ($(PYTHON_VERSION),)
PYTHON_VERSION="3.10"
endif
.ONESHELL:
help:
@echo -e "\033[1mUSAGE:\033[0m"
@echo " make [target]"
@echo ""
@echo -e "\033[1mTARGETS:\033[0m"
@echo " install - install Poetry and project dependencies"
@echo " install-pre-commit - install and configure pre-commit hooks"
@echo " pre-commit - run pre-commit hooks on all files"
@echo " recreate-env - destroy and recreate Poetry's virtualenv"
echo -e "\033[1mUSAGE:\033[0m"
echo " make [target]"
echo ""
echo -e "\033[1mTARGETS:\033[0m"
echo " help - show this help message"
echo " install - install uv, python, Semantic Kernel and all dependencies"
echo " This is the default and will use Python 3.10."
echo " install-uv - install uv"
echo " install-python - install python distributions"
echo " install-sk - install Semantic Kernel and all dependencies"
echo " install-pre-commit - install pre-commit hooks"
echo " clean - remove the virtualenvs"
echo ""
echo -e "\033[1mVARIABLES:\033[0m"
echo " PYTHON_VERSION - Python version to use. Default is 3.10"
echo " By default, 3.10, 3.11 and 3.12 are installed as well."
.ONESHELL:
install:
@# Check to make sure Python is installed
@if ! command -v python3 &> /dev/null
then
echo "Python could not be found"
echo "Please install Python"
exit 1
fi
make install-uv
make install-python
make install-sk
make install-pre-commit
@# Check if Poetry is installed
@if ! command -v poetry &> /dev/null
then
echo "Poetry could not be found"
echo "Installing Poetry"
curl -sSL https://install.python-poetry.org | python3 -
fi
# Install the dependencies
poetry install
UV_VERSION = $(shell uv --version 2> /dev/null)
install-uv:
# Check if uv is installed
ifdef UV_VERSION
echo "uv found $(UV_VERSION)"
echo "running uv update"
uv self update
else
echo "uv could not be found"
echo "Installing uv"
curl -LsSf https://astral.sh/uv/install.sh | sh
endif
.ONESHELL:
recreate-env:
# Stop the current virtualenv if active or alternative use
# `exit` to exit from a Poetry shell session
(deactivate || exit 0)
# Remove all the files of the current environment of the folder we are in
export POETRY_LOCATION=$$(poetry env info -p)
echo "Poetry is $${POETRY_LOCATION}"
rm -rf "$${POETRY_LOCATION}"
pre-commit:
poetry run pre-commit run --all-files -c .conf/.pre-commit-config.yaml
install-python:
echo "Installing python 3.10, 3.11, 3.12"
uv python install 3.10 3.11 3.12
.ONESHELL:
install-pre-commit:
poetry run pre-commit install
# Edit the pre-commit config file to change the config path
sed -i 's|\.pre-commit-config\.yaml|\.conf/\.pre-commit-config\.yaml|g' .git/hooks/pre-commit
echo "Installing pre-commit hooks"
uv run pre-commit install -c python/.pre-commit-config.yaml
.ONESHELL:
install-sk:
echo "Creating and activating venv for python $(PYTHON_VERSION)"
uv venv --python $(PYTHON_VERSION)
echo "Installing Semantic Kernel and all dependencies"
uv sync --all-extras --dev
.ONESHELL:
clean:
# Remove the virtualenv
rm -rf .venv
+10 -9
View File
@@ -1,17 +1,18 @@
# Get Started with Semantic Kernel ⚡
Install the latest package:
python -m pip install --upgrade semantic-kernel
```bash
python -m pip install --upgrade semantic-kernel
```
If you want to use some of the optional dependencies (OpenAI is installed by default), you can install them with:
python -m pip install --upgrade semantic-kernel[hugging_face]
```bash
python -m pip install --upgrade semantic-kernel[hugging_face]
```
or all of them:
python -m pip install --upgrade semantic-kernel[all]
```bash
python -m pip install --upgrade semantic-kernel[all]
```
# AI Services
## OpenAI / Azure OpenAI API keys
@@ -26,7 +27,7 @@ There are two methods to manage keys, secrets, and endpoints:
2. If you'd like to use the `.env` file, you will need to configure the `.env` file with the following keys in the file (see the `.env.example` file):
```
```bash
OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=""
View File
-1
View File
@@ -1,6 +1,5 @@
[mypy]
python_version = 3.11
plugins = pydantic.mypy
ignore_missing_imports = true
-7715
View File
File diff suppressed because it is too large Load Diff
+117 -186
View File
@@ -1,195 +1,127 @@
[tool.poetry]
[project]
name = "semantic-kernel"
version = "1.8.0"
description = "Semantic Kernel Python SDK"
authors = ["Microsoft <[email protected]>"]
authors = [{ name = "Microsoft", email = "[email protected]"}]
readme = "pip/README.md"
packages = [{include = "semantic_kernel"}]
homepage = "https://learn.microsoft.com/en-us/semantic-kernel/overview/"
repository = "https://github.com/microsoft/semantic-kernel/"
requires-python = ">=3.10,<3.13"
urls.homepage = "https://learn.microsoft.com/en-us/semantic-kernel/overview/"
urls.source = "https://github.com/microsoft/semantic-kernel/tree/main/python"
urls.release_notes = "https://github.com/microsoft/semantic-kernel/releases?q=tag%3Apython-1&expanded=true"
urls.issues = "https://github.com/microsoft/semantic-kernel/issues"
# Version read from __version__ field in __init__.py by Flit
dynamic = ["version"]
dependencies = [
"aiohttp ~= 3.8",
"pydantic ~= 2.0",
"pydantic-settings ~= 2.0",
"defusedxml ~= 0.7",
[tool.poetry.urls]
"Source Code" = "https://github.com/microsoft/semantic-kernel/tree/main/python"
"Release Notes" = "https://github.com/microsoft/semantic-kernel/releases?q=tag%3Apython-1&expanded=true"
# embeddings
"numpy ~= 1.25.0; python_version < '3.12'",
"numpy ~= 1.26.0; python_version >= '3.12'",
[tool.poetry.dependencies]
python = "^3.10,<3.13"
# openai connector
"openai ~= 1.0",
# main dependencies
aiohttp = "^3.8"
pydantic = "^2"
pydantic-settings = "^2"
defusedxml = "^0.7.1"
# openapi and swagger
"openapi_core >= 0.18,<0.20",
# embeddings
numpy = [
{ version = ">=1.25", python = "<3.12" },
{ version = ">=1.26", python = ">=3.12" },
# OpenTelemetry
"opentelemetry-api ~= 1.24",
"opentelemetry-sdk ~= 1.24",
"prance ~= 23.6.21.0",
# templating
"pybars4 ~= 0.9",
"jinja2 ~= 3.1",
"nest-asyncio ~= 1.6"
]
# openai connector
openai = ">=1.0"
# openapi and swagger
openapi_core = ">=0.18,<0.20"
# OpenTelemetry
opentelemetry-api = "^1.24.0"
opentelemetry-sdk = "^1.24.0"
prance = "^23.6.21.0"
# templating
pybars4 = "^0.9.13"
jinja2 = "^3.1.3"
nest-asyncio = "^1.6.0"
### Optional dependencies
# azure
azure-ai-inference = {version = "^1.0.0b1", allow-prereleases = true, optional = true}
azure-search-documents = {version = "11.6.0b4", allow-prereleases = true, optional = true}
azure-core = { version = "^1.28.0", optional = true}
azure-identity = { version = "^1.13.0", optional = true}
azure-cosmos = { version = "^4.7.0", optional = true}
# chroma
chromadb = { version = ">=0.4.13,<0.6.0", optional = true}
# google
google-cloud-aiplatform = { version = "^1.60.0", optional = true}
google-generativeai = { version = "^0.7.2", optional = true}
# hugging face
transformers = { version = "^4.28.1", extras=['torch'], optional = true}
sentence-transformers = { version = "^2.2.2", optional = true}
torch = {version = "2.2.2", optional = true}
# mongo
motor = { version = "^3.3.2", optional = true }
# notebooks
ipykernel = { version = "^6.21.1", optional = true}
# milvus
pymilvus = { version = ">=2.3,<2.4.6", optional = true}
milvus = { version = ">=2.3,<2.3.8", markers = 'sys_platform != "win32"', optional = true}
# mistralai
mistralai = { version = "^0.4.1", optional = true}
# ollama
ollama = { version = "^0.2.1", optional = true}
# anthropic
anthropic = { version = "^0.32.0", optional = true }
# pinecone
pinecone-client = { version = "^5.0.0", optional = true}
# postgres
psycopg = { version="^3.2.1", extras=["binary","pool"], optional = true}
# qdrant
qdrant-client = { version = '^1.9', optional = true}
# redis
redis = { version = "^5.0.7", extras=['hiredis'], optional = true}
types-redis = { version="^4.6.0.20240425", optional = true }
# usearch
usearch = { version = "^2.9", optional = true}
pyarrow = { version = ">=12.0.1,<18.0.0", optional = true}
weaviate-client = { version = ">=3.18,<5.0", optional = true}
pandas = {version = "^2.2.2", optional = true}
[project.optional-dependencies]
azure = [
"azure-ai-inference >= 1.0.0b3",
"azure-search-documents >= 11.6.0b4",
"azure-identity ~= 1.13",
"azure-cosmos ~= 4.7"
]
chroma = [
"chromadb >= 0.4,<0.6"
]
google = [
"google-cloud-aiplatform ~= 1.60",
"google-generativeai ~= 0.7"
]
hugging_face = [
"transformers[torch] ~= 4.28",
"sentence-transformers ~= 2.2",
"torch == 2.2.2"
]
mongo = [
"motor ~= 3.3.2"
]
notebooks = [
"ipykernel ~= 6.29"
]
milvus = [
"pymilvus >= 2.3,<2.4",
"milvus >= 2.3,<2.3.8; platform_system != 'Windows'"
]
mistralai = [
"mistralai ~= 0.4"
]
ollama = [
"ollama ~= 0.2"
]
anthropic = [
"anthropic ~= 0.32"
]
pinecone = [
"pinecone-client ~= 5.0"
]
postgres = [
"psycopg[binary,pool] ~= 3.2"
]
qdrant = [
"qdrant-client ~= 1.9"
]
redis = [
"redis[hiredis] ~= 5.0",
"types-redis ~= 4.6.0.20240425"
]
usearch = [
"usearch ~= 2.9",
"pyarrow >= 12.0,<18.0"
]
weaviate = [
"weaviate-client >= 3.18,<5.0"
]
pandas = [
"pandas ~= 2.2"
]
[tool.poetry.group.dev.dependencies]
pre-commit = ">=3.7.1"
ipykernel = "^6.29.4"
nbconvert = "^7.16.4"
pytest = "^8.2.1"
pytest-xdist = { version="^3.6.1", extras=["psutil"]}
pytest-cov = ">=5.0.0"
pytest-asyncio = "^0.23.7"
snoop = "^0.4.3"
mypy = ">=1.10.0"
types-PyYAML = "^6.0.12.20240311"
ruff = ">=0.5.2,<0.7.0"
[tool.poetry.group.unit-tests]
optional = true
[tool.poetry.group.unit-tests.dependencies]
azure-ai-inference = {version = "^1.0.0b1", allow-prereleases = true}
azure-search-documents = {version = "11.6.0b4", allow-prereleases = true}
azure-core = "^1.28.0"
azure-cosmos = "^4.7.0"
mistralai = "^0.4.1"
ollama = "^0.2.1"
google-cloud-aiplatform = "^1.60.0"
anthropic = "^0.32.0"
google-generativeai = "^0.7.2"
transformers = { version = "^4.28.1", extras=['torch']}
sentence-transformers = { version = "^2.2.2"}
torch = {version = "2.2.2"}
# qdrant
qdrant-client = '^1.9'
# redis
redis = { version = "^5.0.7", extras=['hiredis']}
pandas = {version = "^2.2.2"}
[tool.poetry.group.tests]
optional = true
[tool.poetry.group.tests.dependencies]
# azure
azure-ai-inference = {version = "^1.0.0b1", allow-prereleases = true}
azure-search-documents = {version = "11.6.0b4", allow-prereleases = true}
azure-core = "^1.28.0"
azure-identity = "^1.13.0"
azure-cosmos = "^4.7.0"
msgraph-sdk = "^1.2.0"
# chroma
chromadb = ">=0.4.13,<0.6.0"
# google
google-cloud-aiplatform = "^1.60.0"
google-generativeai = "^0.7.2"
# hugging face
transformers = { version = "^4.28.1", extras=['torch']}
sentence-transformers = { version = "^2.2.2"}
torch = {version = "2.2.2"}
# milvus
pymilvus = ">=2.3,<2.4.6"
milvus = { version = ">=2.3,<2.3.8", markers = 'sys_platform != "win32"'}
# mistralai
mistralai = "^0.4.1"
# ollama
ollama = "^0.2.1"
# anthropic
anthropic = "^0.32.0"
# mongodb
motor = "^3.3.2"
# pinecone
pinecone-client = "^5.0.0"
# postgres
psycopg = { version="^3.1.9", extras=["binary","pool"]}
# qdrant
qdrant-client = '^1.9'
# redis
redis = { version="^5.0.7", extras=['hiredis']}
types-redis = { version="^4.6.0.20240425" }
# usearch
usearch = "^2.9"
pyarrow = ">=12.0.1,<18.0.0"
# weaviate
weaviate-client = ">=3.18,<5.0"
pandas = {version = "^2.2.2"}
# Extras are exposed to pip, this allows a user to easily add the right dependencies to their environment
[tool.poetry.extras]
all = ["transformers", "sentence-transformers", "torch", "qdrant-client", "chromadb", "pymilvus", "milvus", "mistralai", "ollama", "anthropic", "google", "weaviate-client", "pinecone-client", "psycopg", "redis", "azure-ai-inference", "azure-search-documents", "azure-core", "azure-identity", "azure-cosmos", "usearch", "pyarrow", "ipykernel", "motor"]
azure = ["azure-ai-inference", "azure-search-documents", "azure-core", "azure-identity", "azure-cosmos", "msgraph-sdk"]
chromadb = ["chromadb"]
google = ["google-cloud-aiplatform", "google-generativeai"]
hugging_face = ["transformers", "sentence-transformers", "torch"]
milvus = ["pymilvus", "milvus"]
mistralai = ["mistralai"]
ollama = ["ollama"]
anthropic = ["anthropic"]
mongo = ["motor"]
notebooks = ["ipykernel"]
pinecone = ["pinecone-client"]
postgres = ["psycopg"]
qdrant = ["qdrant-client"]
redis = ["redis", "types-redis"]
usearch = ["usearch", "pyarrow"]
weaviate = ["weaviate-client"]
[tool.uv]
prerelease = "if-necessary-or-explicit"
dev-dependencies = [
"pre-commit ~= 3.7",
"ipykernel ~= 6.29",
"nbconvert ~= 7.16",
"pytest ~= 8.2",
"pytest-xdist[psutil] ~= 3.6",
"pytest-cov >= 5.0",
"pytest-asyncio ~= 0.23",
"snoop ~= 0.4",
"mypy >= 1.10",
"types-PyYAML ~= 6.0.12.20240311",
"ruff ~= 0.5"
]
environments = [
"sys_platform == 'darwin'",
"sys_platform == 'linux'",
"sys_platform == 'win32'"
]
[tool.pytest.ini_options]
addopts = "-ra -q -r fEX"
@@ -198,11 +130,11 @@ addopts = "-ra -q -r fEX"
line-length = 120
target-version = "py310"
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
preview = true
[tool.ruff.lint]
fixable = ["ALL"]
unfixable = []
preview = true
select = [
"D", #pydocstyle checks
"E", #error checks
@@ -227,7 +159,6 @@ ignore = [
]
[tool.ruff.format]
preview = true
docstring-code-format = true
[tool.ruff.lint.pydocstyle]
@@ -246,10 +177,10 @@ notice-rgx = "^# Copyright \\(c\\) Microsoft\\. All rights reserved\\."
min-file-size = 1
[tool.bandit]
targets = ["python/semantic_kernel"]
exclude_dirs = ["python/tests"]
targets = ["semantic_kernel"]
exclude_dirs = ["tests"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["flit-core >= 3.8"]
build-backend = "flit_core.buildapi"
@@ -1,8 +1,10 @@
### Running the OpenAPI syntax example
For more generic setup instructions, including how to install the `uv` tool, see the [main README](../../../../DEV_SETUP.md).
1. In a terminal, navigate to `semantic_kernel/python/samples/kernel-syntax-examples/openapi_example`.
2. Run `poetry install` followed by `poetry shell` to enter poetry's virtual environment.
2. Run `uv sync` followed by `source .venv/bin/activate` to enter the virtual environment (depending on the os, the activate script may be in a different location).
3. Start the server by running `python openapi_server.py`.
@@ -14,6 +14,10 @@ OpenAI | [OpenAIChatCompletion](../../../semantic_kernel/connectors/ai/open_ai/s
| | | ai_model_id | OPENAI_EMBEDDING_MODEL_ID | Yes
| | | api_key | OPENAI_API_KEY | Yes
| | | org_id | OPENAI_ORG_ID | No
| | [OpenAITextToImage](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image.py)
| | | ai_model_id | OPENAI_TEXT_TO_IMAGE_MODEL_ID | Yes
| | | api_key | OPENAI_API_KEY | Yes
| | | org_id | OPENAI_ORG_ID | No
Azure OpenAI | [AzureOpenAIChatCompletion](../../../semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py) | | | | [AzureOpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/azure_open_ai_settings.py)
| | | deployment_name | AZURE_OPENAI_CHAT_DEPLOYMENT_NAME | Yes
| | | api_key | AZURE_OPENAI_API_KEY | Yes
@@ -32,6 +36,10 @@ Azure OpenAI | [AzureOpenAIChatCompletion](../../../semantic_kernel/connectors/a
| | | endpoint | AZURE_OPENAI_ENDPOINT | Yes
| | | api_version | AZURE_OPENAI_API_VERSION | Yes
| | | base_url | AZURE_OPENAI_BASE_URL | Yes
| | [AzureTextToImage](../../../semantic_kernel/connectors/ai/open_ai/services/azure_text_to_image.py)
| | | deployment_name | AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME | Yes
| | | api_key | AZURE_OPENAI_API_KEY | Yes
| | | endpoint | AZURE_OPENAI_ENDPOINT | Yes
## Memory Service Settings used across SK:
+2 -1
View File
@@ -2,4 +2,5 @@
from semantic_kernel.kernel import Kernel
__all__ = ["Kernel"]
__version__ = "1.8.0"
__all__ = ["Kernel", "__version__"]
@@ -10,7 +10,7 @@ from typing import Any, TypeVar
if sys.version < "3.11":
from typing_extensions import Self # pragma: no cover
else:
from typing import Self # pragma: no cover
from typing import Self # type: ignore # pragma: no cover
from pydantic import Field, ValidationError, field_validator, model_validator
from pydantic_core import Url
@@ -6,7 +6,7 @@ Please follow the [Azure Container Apps Documentation](https://learn.microsoft.c
## Configuring the Python Plugin
To successfully use the Python Plugin in Semantic Kernel, you must install the Poetry `azure` extras by running `poetry install -E azure`.
To successfully use the Python Plugin in Semantic Kernel, you must install the `azure` extras by running `uv sync --extra azure` or `pip install semantic-kernel[azure]`.
Next, as an environment variable or in the .env file, add the `poolManagementEndpoint` value from above to the variable `ACA_POOL_MANAGEMENT_ENDPOINT`. The `poolManagementEndpoint` should look something like:
-7
View File
@@ -1,7 +0,0 @@
#!/bin/sh
# this assumes Poetry is installed and in the Path, see https://python-poetry.org/docs/#installing-with-the-official-installer
# on macos run with `source ./setup_dev.sh`
poetry install
poetry run pre-commit install
poetry run pre-commit autoupdate
+5347
View File
File diff suppressed because it is too large Load Diff