Skip to content

Commit 15a73e7

Browse files
committed
translate into English
1 parent decfcc0 commit 15a73e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+593
-562
lines changed

.deployment

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,27 @@ This repository is for a workshop using Azure OpenAI Service.
88

99
## Prerequisites
1010

11-
- [Python 3.10+](https://www.python.org/downloads/)
12-
- [Poetry](https://python-poetry.org/docs/#installation)
13-
- [GNU Make](https://www.gnu.org/software/make/)
14-
- [Azure OpenAI Service](https://azure.microsoft.com/ja-jp/products/ai-services/openai-service)
15-
- [Azure Cosmos DB](https://azure.microsoft.com/ja-jp/products/cosmos-db/)
16-
17-
## Development instructions
18-
19-
### Local development
20-
21-
Use Makefile to run the project locally.
22-
23-
```shell
24-
# help
25-
make
26-
27-
# install dependencies for development
28-
make install-deps-dev
29-
30-
# run tests
31-
make test
32-
33-
# run CI tests
34-
make ci-test
35-
```
36-
37-
### Docker development
38-
39-
```shell
40-
# build docker image
41-
make docker-build
42-
43-
# run docker container
44-
make docker-run
45-
46-
# run CI tests in docker container
47-
make ci-test-docker
48-
```
11+
To run all the projects in this repository, you need the followings.
4912

50-
To publish the docker image to Docker Hub, you need to set the following secrets in the repository settings.
51-
52-
```shell
53-
gh secret set DOCKERHUB_USERNAME --body $DOCKERHUB_USERNAME
54-
gh secret set DOCKERHUB_TOKEN --body $DOCKERHUB_TOKEN
55-
```
56-
57-
## Deployment
58-
59-
### From Docker Hub
60-
61-
You can run the docker image from Docker Hub.
62-
63-
```shell
64-
# Run 2_streamlit_chat
65-
docker run -p 8501:8501 ks6088ts/workshop-azure-openai:latest \
66-
python -m streamlit run apps/2_streamlit_chat/main.py
67-
68-
# Run 99_streamlit_llm_examples
69-
docker run -p 8501:8501 ks6088ts/workshop-azure-openai:latest \
70-
python -m streamlit run apps/99_streamlit_llm_examples/main.py
71-
```
72-
73-
### App Service
74-
75-
For deploying the Streamlit application to Azure App Service, you need to set the following two configurations.
76-
77-
1. Go to `Settings > Configuration > Startup Command` and set startup command as `python -m streamlit run apps/4_streamlit_chat_history/main.py --server.port 8000 --server.address 0.0.0.0`
78-
1. Set `SCM_DO_BUILD_DURING_DEPLOYMENT` to `true`
79-
80-
Notes:
13+
- [Python 3.10+](https://www.python.org/downloads/)
14+
- [Azure OpenAI Service](https://azure.microsoft.com/en-us/products/ai-services/openai-service)
15+
- [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db/)
16+
- [Azure AI Search](https://azure.microsoft.com/en-us/products/ai-services/ai-search)
8117

82-
- Update the startup command as needed. App Service listens on port 8000 by default, so `--server.port 8000` is required.
83-
- The default port of App Service is 8000, so `--server.port 8000` is required.
18+
Here are the preferred tools for development.
8419

85-
#### References
20+
- [Poetry](https://python-poetry.org/docs/#installation)
21+
- [GNU Make](https://www.gnu.org/software/make/)
8622

87-
- [Streamlit を Azure App Service で動かす!](https://qiita.com/takashiuesaka/items/491b21e9afb34bbb6e6d)
88-
- [WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv](https://stackoverflow.com/a/61720957)
89-
- [How to deploy a streamlit application on Azure App Service (WebApp)](https://learn.microsoft.com/en-us/answers/questions/1470782/how-to-deploy-a-streamlit-application-on-azure-app)
23+
## Projects
24+
25+
| Project | Description | Image |
26+
| --------------------------------------------------------------------------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
27+
| [1_call_azure_openai_chat](./apps/1_call_azure_openai_chat/README.md) | Call Azure OpenAI Service API from Python | No Image |
28+
| [2_streamlit_chat](./apps/2_streamlit_chat/README.md) | Create an Azure OpenAI Chat app using Streamlit | ![2_streamlit_chat](./docs/images/2_streamlit_chat.chat_page.png) |
29+
| [3_call_azure_cosmos_db](./apps/3_call_azure_cosmos_db/README.md) | Call Azure Cosmos DB from Python | No Image |
30+
| [4_streamlit_chat_history](./apps/4_streamlit_chat_history/README.md) | Add feature to store chat history using Azure Cosmos DB | ![4_streamlit_chat_history](./docs/images/4_streamlit_chat_history.chat_page.png) |
31+
| [5_streamlit_query_chat_history](./apps/5_streamlit_query_chat_history/README.md) | Search Chat History | ![5_streamlit_query_chat_history](./docs/images/5_streamlit_query_chat_history.main.png) |
32+
| [6_call_azure_ai_search](./apps/6_call_azure_ai_search/README.md) | Call Azure AI Search from Python | No Image |
33+
| [7_streamlit_chat_rag](./apps/7_streamlit_chat_rag/README.md) | Add RAG feature to Streamlit chat app | ![7_streamlit_chat_rag](./docs/images/7_streamlit_chat_rag.main.png) |
34+
| [99_streamlit_examples](./apps/99_streamlit_examples/README.md) | Code samples for Streamlit | ![99_streamlit_examples](./docs/images/99_streamlit_examples.explaindata.png) |

apps/1_call_azure_openai_chat/README.md

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
1-
# Azure OpenAI Service を Python から呼び出す
1+
# Call Azure OpenAI Service API from Python
22

3-
Azure OpenAI Service を Python から呼び出す方法を説明します。
3+
This article explains how to call Azure OpenAI Service API from Python.
44

5-
## 前提条件
5+
## Prerequisites
66

7-
- Python 3.11+ がインストールされていること
8-
- Azure OpenAI Service が利用できること
9-
- Azure OpenAI Service の API キーが取得できていること
7+
- Python 3.10 or later
8+
- Azure OpenAI Service
109

11-
## 手順
10+
## Usage
1211

13-
1. Azure OpenAI Service API キーを取得する
14-
1. [.env.template](../../.env.template) をコピーして `.env` ファイルを作成する
15-
1. `.env` ファイルに API キーを設定する
16-
1. [main.py](./main.py) を実行する
12+
1. Get Azure OpenAI Service API key
13+
1. Copy [.env.template](../../.env.template) to `.env` in the same directory
14+
1. Set credentials in `.env`
15+
1. Run [main.py](./main.py)
1716

1817
```shell
19-
# 仮想環境を作成してライブラリをインストールする
20-
python -m venv .venv
18+
# Create a virtual environment
19+
$ python -m venv .venv
2120

22-
# 仮想環境を有効化する
23-
source .venv/bin/activate
21+
# Activate the virtual environment
22+
$ source .venv/bin/activate
2423

25-
# ライブラリをインストールする
26-
pip install -r requirements.txt
24+
# Install dependencies
25+
$ pip install -r requirements.txt
2726

28-
# スクリプトを実行する
29-
python apps/1_call_azure_openai/main.py
27+
# Run the script
28+
$ python apps/1_call_azure_openai/main.py
3029
```
3130

32-
### 実行例
31+
### Example
3332

3433
```shell
35-
❯ python apps/1_call_azure_openai_chat/main.py
36-
こんにちは!どうされましたか?何かお手伝いできることがあれば教えてください。
34+
$ python apps/1_call_azure_openai_chat/main.py
3735
{
38-
"id": "chatcmpl-9rHSFKIBtJDOlDheesev79CO7RNMz",
36+
"id": "chatcmpl-9tVzJwEczzb40cXT1gHZkk7ThX5Lm",
3937
"choices": [
4038
{
4139
"finish_reason": "stop",
4240
"index": 0,
4341
"logprobs": null,
4442
"message": {
45-
"content": "こんにちは!どうされましたか?何かお手伝いできることがあれば教えてください。",
43+
"content": "Hello! How can I assist you today?",
4644
"role": "assistant",
4745
"function_call": null,
4846
"tool_calls": null
@@ -52,6 +50,14 @@ python apps/1_call_azure_openai/main.py
5250
"filtered": false,
5351
"severity": "safe"
5452
},
53+
"protected_material_code": {
54+
"filtered": false,
55+
"detected": false
56+
},
57+
"protected_material_text": {
58+
"filtered": false,
59+
"detected": false
60+
},
5561
"self_harm": {
5662
"filtered": false,
5763
"severity": "safe"
@@ -67,15 +73,15 @@ python apps/1_call_azure_openai/main.py
6773
}
6874
}
6975
],
70-
"created": 1722485507,
76+
"created": 1723018029,
7177
"model": "gpt-4o-2024-05-13",
7278
"object": "chat.completion",
7379
"service_tier": null,
7480
"system_fingerprint": "fp_abc28019ad",
7581
"usage": {
76-
"completion_tokens": 23,
82+
"completion_tokens": 9,
7783
"prompt_tokens": 18,
78-
"total_tokens": 41
84+
"total_tokens": 27
7985
},
8086
"prompt_filter_results": [
8187
{
@@ -107,6 +113,6 @@ python apps/1_call_azure_openai/main.py
107113
}
108114
```
109115

110-
## 参考資料
116+
## References
111117

112-
- [クイックスタート: Azure OpenAI Service で GPT-35-Turbo GPT-4 を使い始める](https://learn.microsoft.com/ja-jp/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python)
118+
- [Quickstart: Get started using GPT-35-Turbo and GPT-4 with Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python)

apps/1_call_azure_openai_chat/main.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,24 @@
44
from openai import AzureOpenAI
55

66
if __name__ == "__main__":
7-
# .env ファイルをパースして環境変数にセット
7+
# Parse .env file and set environment variables
88
load_dotenv()
99

10-
# Azure OpenAI API クライアントを初期化
10+
# Initialize AzureOpenAI client
1111
client = AzureOpenAI(
1212
api_key=getenv("AZURE_OPENAI_API_KEY"),
1313
api_version=getenv("AZURE_OPENAI_API_VERSION"),
1414
azure_endpoint=getenv("AZURE_OPENAI_ENDPOINT"),
1515
)
1616

17-
# Chat API を呼び出して、ユーザーの入力に対する応答を取得
17+
# Call completion API and get a response to user input
1818
response = client.chat.completions.create(
1919
model=getenv("AZURE_OPENAI_GPT_MODEL"),
2020
messages=[
2121
{"role": "system", "content": "You are a helpful assistant."},
22-
{"role": "user", "content": "こんにちは"},
22+
{"role": "user", "content": "Hello"},
2323
],
2424
)
2525

26-
# 応答を出力
27-
print(response.choices[0].message.content)
28-
29-
# レスポンスの JSON を出力
26+
# Print response to console
3027
print(response.model_dump_json(indent=2))

apps/2_streamlit_chat/README.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
1-
# Streamlit でチャットアプリを作成する
1+
# Create an Azure OpenAI Chat app using Streamlit
22

3-
Streamlit を使って、Azure OpenAI Service を利用したチャットアプリを作成します。
3+
This app demonstrates how to create a chat application using Azure OpenAI Service and Streamlit.
44

5-
## 前提条件
5+
## Prerequisites
66

7-
- Python 3.11+ がインストールされていること
8-
- Azure OpenAI Service が利用できること
9-
- Azure OpenAI Service の API キーが取得できていること
7+
- Python 3.10 or later
8+
- Azure OpenAI Service
109

11-
## 手順
10+
## Usage
1211

13-
1. Azure OpenAI Service API キーを取得する
14-
1. [.env.template](../../.env.template) をコピーして `.env` ファイルを作成する
15-
1. `.env` ファイルに API キーを設定する
16-
1. [main.py](./main.py) を実行する
12+
1. Get Azure OpenAI Service API key
13+
1. Copy [.env.template](../../.env.template) to `.env` in the same directory
14+
1. Set credentials in `.env`
15+
1. Run [main.py](./main.py)
1716

1817
```shell
19-
# 仮想環境を作成してライブラリをインストールする
20-
python -m venv .venv
18+
# Create a virtual environment
19+
$ python -m venv .venv
2120

22-
# 仮想環境を有効化する
23-
source .venv/bin/activate
21+
# Activate the virtual environment
22+
$ source .venv/bin/activate
2423

25-
# ライブラリをインストールする
26-
pip install -r requirements.txt
24+
# Install dependencies
25+
$ pip install -r requirements.txt
2726

28-
# スクリプトを実行する
29-
streamlit run ./apps/2_streamlit_chat/main.py
27+
# Run the script
28+
$ python -m streamlit run apps/2_streamlit_chat/main.py
3029
```
3130

32-
### 実行例
31+
### Example
3332

34-
http://localhost:8501 にアクセスすると、以下のような画面が表示されます。
33+
When you access `http://localhost:8501`, you will see the following screen.
3534

36-
![Streamlit Chat](../../docs/images/2_streamlit_chat.png)
35+
![Streamlit Chat](../../docs/images/2_streamlit_chat.initial_page.png)
3736

38-
## 補足
37+
To start a conversation, fill in the required fields in the sidebar and you will see the following screen.
3938

40-
本アプリでは、チャットのやり取りを保持するために、`st.session_state.messages` にメッセージを保持しています。
41-
これはアプリケーションのプロセス側で、セッションごとにメッセージを保持するための仕組みです。セッションが終了するとメッセージは消えます。
39+
![Streamlit Chat](../../docs/images/2_streamlit_chat.chat_page.png)
4240

43-
## 参考資料
41+
## Note
42+
43+
This app uses `st.session_state.messages` to store messages for chat. This is a mechanism to store messages per session on the process side of the application. Messages will disappear when the session ends.
44+
45+
## References
4446

4547
- [Your LLM code playground](https://streamlit.io/generative-ai)

apps/2_streamlit_chat/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@
3030
key="AZURE_OPENAI_GPT_MODEL",
3131
type="default",
3232
)
33-
"[Go to Azure Portal to get an Azure OpenAI API key](https://portal.azure.com/)"
34-
"[Go to Azure OpenAI Studio](https://oai.azure.com/resource/overview)"
33+
"[Azure Portal](https://portal.azure.com/)"
34+
"[Azure OpenAI Studio](https://oai.azure.com/resource/overview)"
3535
"[View the source code](https://github.com/ks6088ts-labs/workshop-azure-openai/blob/main/apps/2_streamlit_chat/main.py)"
3636

37-
st.title("Streamlit Chat")
37+
st.title("2_streamlit_chat")
3838

3939
if not azure_openai_api_key or not azure_openai_endpoint or not azure_openai_api_version or not azure_openai_gpt_model:
40-
st.warning("サイドバーに Azure OpenAI の設定を入力してください")
40+
st.warning("Please fill in the required fields at the sidebar.")
4141
st.stop()
4242

4343
if "messages" not in st.session_state:
4444
st.session_state["messages"] = [
4545
{
4646
"role": "assistant",
47-
"content": "こんにちは、何かお手伝いできますか?",
47+
"content": "Hello! I'm a helpful assistant.",
4848
}
4949
]
5050

51-
# 既存のメッセージを表示
51+
# Show chat messages
5252
for msg in st.session_state.messages:
5353
st.chat_message(msg["role"]).write(msg["content"])
5454

55-
# ユーザーからの入力を受け付ける
55+
# Receive user input
5656
if prompt := st.chat_input():
5757
client = AzureOpenAI(
5858
api_key=azure_openai_api_key,
@@ -67,7 +67,7 @@
6767
}
6868
)
6969
st.chat_message("user").write(prompt)
70-
with st.spinner("考え中..."):
70+
with st.spinner("Thinking..."):
7171
response = client.chat.completions.create(
7272
model=azure_openai_gpt_model,
7373
messages=st.session_state.messages,

0 commit comments

Comments
 (0)