1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NLWeb とりあえず触ってみたゾ

Last updated at Posted at 2025-05-21

直近話題の(?)のNLWebをローカル環境とAzureでHello Worldしてみました。

正直、NLWebの利点を十分に理解できていない段階で恐縮なのですが、せっかくなので備忘録として残しておきます。

ローカルでHello World

こちらのREADME通りに環境を構築し、.envにOpenAIのAPIキーを記述します。
.env.templateには他の環境変数も書かれてますが、他の記載は必要ありません。

次に、code/config/config_llm.yamlcode/config/config_embedding.yamlcode/config/config_retrieval.yaml の最初の行を修正します。

code/config/config_llm.yaml
+ preferred_provider: openai
- preferred_provider: azure_openai

providers:
 ...

ローカルのベクターデータベースにテスト用のデータを追加します。
今回はAzure UpdateのRSSフィードを追加してみます。

python -m tools.db_load https://www.microsoft.com/releasecommunications/api/v2/azure/rss Azure-Update

データを追加できたら起動します。

python app-file.py

追加したRSSフィードが英語なので、英語で質問してみます。

img.gif

なお、追加したサイトを削除する場合は --only-delete <サイト名> で削除できるようです。

python -m tools.db_load --only-delete Azure-Update

AzureでHello World

次にこちらの手順でAzureにデプロイしてみます。
前もってAzureOpenAIとAzure AI Searchをプロビジョニングしておきます。
また、先ほど変更したconfig_**.yamlのデフォルトプロパイダーはazure_openai に変更しておきます。

code/config/config_llm.yaml
+ preferred_provider: azure_openai
- preferred_provider: openai

providers:
 ...

Azure OpenAI

aoai-deploy.png

  • US East2
    • gpt-4.1
    • gpt-4.1-mini
    • text-embedding-3-small

East US2のリージョンに上記モデルをデプロイし、エンドポイントとAPIキーをメモします。
aoaikey.png

Azure AI Search

  • Japan East: フリープラン

こちらもエンドポイントとAPIキーをメモします。
ai-search-key.png

手順通りにAZ CLIでApp Serviceを作成します。

rg=<リソースグループ名>
plan=<AppServiceプラン名>
appservice=<Service名>

az appservice plan create --name $plan --resource-group $rg --sku P1v3 --is-linux

az webapp create --resource-group $rg --plan $plan --name $appservice --runtime "PYTHON:3.13"

作成したAppServiceの環境変数を設定します。

az webapp config appsettings set --resource-group $rg --name $appservice --settings \
AZURE_VECTOR_SEARCH_ENDPOINT=<AISearchのエンドポイント> \
AZURE_VECTOR_SEARCH_API_KEY=<AISearchのAPIキー> \
AZURE_OPENAI_ENDPOINT=<AzureOpenAIエンドポイント> \
AZURE_OPENAI_API_KEY=<AzureOpenAIのAPIキー> \
WEBSITE_RUN_FROM_PACKAGE=1 \
SCM_DO_BUILD_DURING_DEPLOYMENT=true \
NLWEB_OUTPUT_DIR=/home/data

アプリをデプロイします!

az webapp config set --resource-group $rg \
--name $appservice --startup-file "startup.sh"

git archive --format zip --output ./app.zip main

az webapp deployment source config-zip --resource-group $rg \
--name $appservice --src ./app.zip

App ServiceのポータルメニューからSSHで接続し、ローカルで実行した際と同じ用にRSSフィードを追加するコマンドを実行しましょう。

ssh.png

実行後に、AI Searchを覗いてみるとドキュメントが追加されていることがわかります。
ai-search.png

App ServiceのデプロイされたURLからアプリの動作を確認してみるとローカルと同じ用に動作することが確認できました。
5.png

おわりに

今回は、ローカルとAzureでHello Worldしてみました。
正直まだNLWebの美味しさがよく分かってないので、今後追っていこうと思います!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?