見出し画像

Azure OpenAI Service実践ガイドを試してみる


関連情報


ソースコード
著作権:Avanade(URL

Azure Portal:  URL
Azure Machine Learning: URL

動作環境

Win11 + VSC + Python3.11.5

学習メモ

5.3 AI Search
基本は以下MS-Learnにて学習
AI Search学習リソース:クイック スタート: Azure portal で検索インデックスを作成する(URL

5.3.6.Vector-Search

 CreateIndex-Vector.py
最初以下エラー。ライブラリVer一致させたらエラー解消
from azure.search.documents.indexes.models import (
ImportError: cannot import name 'HnswVectorSearchAlgorithmConfiguration' from 'azure.search.documents.indexes.models

pip install azure-search-documents==11.4.0b8

 UploadDocument-Vector.py
最初以下エラー、コード修正により動作。
\UploadDocument-Vector.py", line 57, in <module>
response_description = openai.Embedding.create(input=doc['description'],engine='text-embedding-ada-002')
openai.error.InvalidRequestError: The API deployment for this resource does not exist. 

 # タイトルをベクトル化 
    #response_title = openai.Embedding.create(input=doc['title'],engine=model_name)
    response_title = openai.Embedding.create(input=doc['title'],deployment_id=model_name)
    doc['title_vector'] = response_title['data'][0]['embedding']
    time.sleep(10)
    # 説明をベクトル化
    #response_description = openai.Embedding.create(input=doc['description'],engine='text-embedding-ada-002')
    response_description = openai.Embedding.create(input=doc['description'],deployment_id=model_name)

 DocumentSerach-Vector.py

# 検索ワードのベクトル化
#response_search_word_vector = openai.Embedding.create(input = search_word, engine = model_name)
response_search_word_vector = openai.Embedding.create(input = search_word, deployment_id = model_name)

5.3.7.Semantic-Search

同様修正
UploadDocument-Semantic.py
DocumentSearch-Semantic-Hybrid.py

5.5 On your data
書籍だけと情報&演習が少ないので、以下で学習&動作確認すると良い。

上記MS-learnコンテンツ演習内容:URL

<その他参考情報>
クイック スタート: 独自のデータを使用して Azure OpenAI モデルとチャットする: URL
独自のデータに基づく Azure OpenAI (プレビュー): URL

5.6 LangChain

LangChainCognitiveSearchSample.py
はまったところ、最初以下エラー
If you have openai>=1.0.0 installed and are using Azure, please use the `AzureOpenAIEmbeddings` class.
→ AzureOpenAIEmbeddingsを利用したコード実装方法わかないので
ライブラリVerを書籍通りに古いVerに置き換えたらエラー解消。
pip install openai==0.28.1
pip install langchain==0.0.335

LangChainPromptTemplateSample.py
エラーのため以下の通り、コード修正
#Azure OpenAIのエンドポイントとAPIキーAZURE_OPENAI_ENDPOINT="https://xxx.openai.azure.com/"
AZURE_OPENAI_API_KEY="xxxx"
#DEPLOYMENT_NAME = "gpt-35-turbo-16k"
DEPLOYMENT_NAME = "My deployment name"

以下も全て同様
LangChainAzureOpenaiSample.py
LangChainLLMChainSample.py
LangChainOutputParserSample.py
LangChainOutputParserSample2.py
LangChainPluginRunSample.py

LangChainPluginRunSample.py
以下は正常動作だと思うがプラグイン実行は不可
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /.well-known/ai-plugin.json (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001FF9169A710>: Failed to establish a new connection: [WinError 10061] 対象のコンピューターによって拒否されたため、接続できませんでした。'))

5.9 Prompt Flow

デモのSTEP2:Faissベクトルインデクス作成(P302)
パイプライン処理成功しない、エラー


上記embeddings_model、以下になっているせい?修正してもNG
azure_open_ai://deployment/デプロイ名/model/text-embedding-ada-002

書籍と違ってたところ:P.319評価用のデータ資産の選択の画面内容
以下のように設定して動作成功

この記事が気に入ったらサポートをしてみませんか?