Files
semantic-kernel/python/DEV_SETUP.md
T
Abby Harrison a9b61b2cf4 Python: Optional dependencies (#820)
### Motivation and Context
The release of Python SK from 0.2.4 -> 0.2.6 significantly increased the
size of the pip package. The dependencies causing this are not core to
the kernel, so this PR establishes a pattern for SK connector
dependencies (ex: Hugging Face, memory storage)

### Description
- Added a poetry group called hugging_face - this is the same name as
the connectors namespace in the code.
- Added dependency installs to the Hugging Face sample notebook.
- removed Hugging Face dependencies from requirements.txt.
- Added import errors for torch, transformers, and sentence-transformers
in the hugging_face connector classes.
- Added command `--with hugging_face` to integration test setup.
2023-05-06 03:35:13 +00:00

124 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This document describes how to setup your environment with Python and Poetry,
if you're working on new features or a bug fix for Semantic Kernel, or simply
want to run the tests included.
# LLM setup
Make sure you have an
[Open AI API Key](https://openai.com/api/) or
[Azure Open AI service key](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api)
Copy those keys into a `.env` file (see the `.env.example` file):
```
OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""
```
We suggest adding a copy of the `.env` file under these folders:
- [python/tests](tests)
- [samples/notebooks/python](../samples/notebooks/python).
# System setup
To get started, you'll need VSCode and a local installation of Python 3.8+.
You can run:
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.8+ installed.
Install the Poetry package manager and create a project virtual environment.
Note: SK requires at least Poetry 1.2.0.
```bash
# Install poetry package
pip3 install poetry
# Use poetry to install base project dependencies
poetry install
# If you want to use connectors such as hugging face
# poetry install --with <connector group name>
# example: poetry install --with hugging_face
# Use poetry to activate project venv
poetry shell
```
# VSCode Setup
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 `black` and `flake8` (if VSCode doesn't find those packages,
it will prompt you to install them).
# Tests
You can run the unit tests under the [tests/unit](tests/unit/) folder.
cd python
poetry install
poetry run pytest tests/unit
You can run the integration tests under the [tests/integration](tests/integration/) folder.
cd python
poetry install
poetry run pytest tests/integration
You can also run all the tests together under the [tests](tests/) folder.
cd python
poetry install
poetry run pytest tests
# Tools and scripts
## Pipeline checks
To run the same checks that run during the GitHub Action build, you can use
this command, from the [python](../python) folder:
poetry run pre-commit run -c .conf/.pre-commit-config.yaml -a
## Running ruff
poetry run ruff check .