Skip to content

Commit

Permalink
.Net: Fixed warning in release pipeline about Docker base image in ex…
Browse files Browse the repository at this point in the history
…amples (microsoft#6340)

### 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.
-->

There is a warning about using `python:3.12` base image in release
pipeline for one of our demo applications. I moved the content of
Dockerfile to README, so it can be used as an example.

### 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 😄
  • Loading branch information
dmytrostruk authored May 20, 2024
1 parent b250109 commit 06a3ce0
Showing 2 changed files with 34 additions and 21 deletions.
38 changes: 34 additions & 4 deletions dotnet/samples/Demos/QualityCheck/README.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
This sample provides a practical demonstration how to perform quality check on LLM results for such tasks as text summarization and translation with Semantic Kernel Filters.

Metrics used in this example:

- [BERTScore](https://github.com/Tiiiger/bert_score) - leverages the pre-trained contextual embeddings from BERT and matches words in candidate and reference sentences by cosine similarity.
- [BLEU](https://en.wikipedia.org/wiki/BLEU) (BiLingual Evaluation Understudy) - evaluates the quality of text which has been machine-translated from one natural language to another.
- [METEOR](https://en.wikipedia.org/wiki/METEOR) (Metric for Evaluation of Translation with Explicit ORdering) - evaluates the similarity between the generated summary and the reference summary, taking into account grammar and semantics.
@@ -14,7 +15,7 @@ In this example, SK Filters call dedicated [server](./python-server/) which is r

## Prerequisites

1. [Python 3.12](https://www.python.org/downloads/)
1. [Python 3.12](https://www.python.org/downloads/)
2. Get [Hugging Face API token](https://huggingface.co/docs/api-inference/en/quicktour#get-your-api-token).
3. Accept conditions to access [Unbabel/wmt22-cometkiwi-da](https://huggingface.co/Unbabel/wmt22-cometkiwi-da) model on Hugging Face portal.

@@ -25,29 +26,34 @@ It's possible to run Python server for task evaluation directly or with Docker.
### Run server

1. Open Python server directory:

```bash
cd python-server
```

2. Create and active virtual environment:

```bash
python -m venv venv
source venv/Scripts/activate # activate on Windows
source venv/bin/activate # activate on Unix/MacOS
```

3. Setup Hugging Face API key:

```bash
pip install "huggingface_hub[cli]"
huggingface-cli login --token <your_token>
```

4. Install dependencies:

```bash
pip install -r requirements.txt
```

5. Run server:

```bash
cd app
uvicorn main:app --port 8080 --reload
@@ -58,18 +64,42 @@ uvicorn main:app --port 8080 --reload
### Run server with Docker

1. Open Python server directory:

```bash
cd python-server
```

2. Create `.env/hf_token.txt` file and put Hugging Face API token in it.
2. Create following `Dockerfile`:

```dockerfile
# syntax=docker/dockerfile:1.2
FROM python:3.12

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install "huggingface_hub[cli]"
RUN --mount=type=secret,id=hf_token \
huggingface-cli login --token $(cat /run/secrets/hf_token)

RUN pip install cmake
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./app /code/app

CMD ["fastapi", "run", "app/main.py", "--port", "80"]
```

3. Create `.env/hf_token.txt` file and put Hugging Face API token in it.

4. Build image and run container:

3. Build image and run container:
```bash
docker-compose up --build
```

4. Open `http://localhost:8080/docs` and check available endpoints.
5. Open `http://localhost:8080/docs` and check available endpoints.

## Testing

17 changes: 0 additions & 17 deletions dotnet/samples/Demos/QualityCheck/python-server/Dockerfile

This file was deleted.

0 comments on commit 06a3ce0

Please sign in to comment.