Skip to content

Instantly share code, notes, and snippets.

@mahiya
Created December 13, 2023 06:12
Show Gist options
  • Save mahiya/1fc501e002720cae356ac022fd8dd2eb to your computer and use it in GitHub Desktop.
Save mahiya/1fc501e002720cae356ac022fd8dd2eb to your computer and use it in GitHub Desktop.
Python で Azure AI Search の Analyze Text API を使用するコード
# https://learn.microsoft.com/ja-jp/rest/api/searchservice/test-analyzer
import os, sys, json, requests
search_name = os.environ["AZURE_SEARCH_NAME"]
index_name = os.environ["AZURE_SEARCH_INDEX_NAME"]
api_key = os.environ["AZURE_SEARCH_KEY"]
api_version = "2020-06-30"
target_analyzer_name = "ja.microsoft"
target_analyze_text = "Azure AI Search は、従来の会話型検索アプリケーションのユーザー所有コンテンツに対して、安全な情報取得を大規模に提供します。"
resp = requests.post(
f"https://{search_name}.search.windows.net/indexes/{index_name}/analyze?api-version={api_version}",
data=json.dumps({"text": target_analyze_text, "analyzer": target_analyzer_name}),
headers={"Content-Type": "application/json", "api-key": api_key},
)
result = json.loads(resp.text)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment