### Good Example: Initialization with setUp Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/README.md Demonstrates proper initialization of a tracker object within the setUp method for isolated test cases. ```python class TestBedrockUsageTracker(unittest.TestCase): def setUp(self): self.tracker = BedrockUsageTracker() def test_first(self): # self.trackerを使用 pass def test_second(self): # 独立したself.trackerを使用 pass ``` -------------------------------- ### Get Usage Summary with Cache Tokens Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/TEST_README.md Example of a usage summary that includes cache tokens and their estimated cost. ```json { "estimatedCostInfo": { "inputTokens": 1300, "outputTokens": 500, "estimatedCost": 0.012028500000000001 } } ``` -------------------------------- ### Create Virtual Environment and Install Dependencies Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/app/README.md Creates a Python virtual environment and installs necessary packages from requirements.txt. Ensure you are in the 'app/' directory. ```powershell cd .\app\\ # 仮想環境を作成 python -m venv venv # 仮想環境を有効化 .\venv\Scripts\Activate.ps1 # 依存パッケージをインストール pip install -r requirements.txt ``` -------------------------------- ### Required Libraries Installation Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/tools/add_metadata_json/README.md Install the necessary Python libraries, pandas and openpyxl, to run the metadata generation scripts. ```bash pip install pandas openpyxl ``` -------------------------------- ### Default Configuration Example (TOML) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/config/README.md Example of a default configuration file in TOML format, specifying model settings, system prompts, and other parameters. ```toml # モデル設定 modelId = "anthropic.claude-3-5-sonnet-20241022-v2:0" temperature = 0.0 maxTokens = 4096 # システムプロンプト systemPrompt = ''' あなたは優秀なアシスタントです。 提供された情報を元に、正確に回答してください。 ''' # その他の設定 streamingEnabled = false stopSequences = [] ``` -------------------------------- ### Application-Specific Configuration Example (TOML) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/config/README.md Example of an application-specific configuration file in TOML format, overriding default settings and adding custom parameters. ```toml # アプリケーション名 name = "qerag" description = "Query Expansion RAG" # デフォルトを上書き [answer_generation] temperature = 0.1 # デフォルトの0.0を上書き systemPrompt = ''' カスタムプロンプト... ''' # レスポンスフッター responseFooter = "※ この回答は生成AIにより作成されています。" ``` -------------------------------- ### Install Dependencies with npm ci Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.md Run this command in the project root to install all project dependencies, including those for custom-resources, thanks to npm workspaces. ```bash npm ci ``` -------------------------------- ### Install Project Dependencies (Bash) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.en.md Run 'npm ci' in the project root to install all project dependencies, including those for 'custom-resources', leveraging npm workspaces. ```bash # Project root (all dependencies will be installed with this single command) npm ci ``` -------------------------------- ### Add Python Libraries to vLLM Container Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md List additional Python libraries to be installed in the vLLM container within the 'infra/core/vmss/cloudinit/requirements.txt' file. These libraries will be installed via 'pip install' during VM setup. ```text # 例: 追加したいライブラリを1行ずつ記載 scipy transformers==4.48.2 ``` -------------------------------- ### Get Usage Summary for Single Model Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/TEST_README.md Example of retrieving the usage summary for a specific model, including estimated cost. ```json { "modelVersion": "anthropic.claude-3-haiku-20240307-v1:0", "requestCount": 2, "tokens": { "inputTokens": 300, "outputTokens": 150, "totalTokens": 450 }, "estimatedCostInfo": { "estimatedCost": 0.0002625, "currency": "USD", "inputTokens": 300, "inputToken1KUnitPrice": 0.00025, "outputTokens": 150, "outputToken1KUnitPrice": 0.00125 } } ``` -------------------------------- ### UsageRecord Creation Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/TEST_README.md Demonstrates the creation of a UsageRecord object with model ID and usage details. ```python UsageRecord( model_id="anthropic.claude-3-haiku-20240307-v1:0", usage={ 'inputTokens': 100, 'outputTokens': 50, 'totalTokens': 150 } ) ``` -------------------------------- ### Example Prompt Types for Dynamic Report Generation Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/README.md These examples illustrate different types of prompts used to guide the AI in generating dynamic reports. They cover definition confirmation, procedure checking, comparison, interpretation, policy research, and comprehensive analysis. ```text 定義確認型 ("デジタル社会形成基本法における「デジタル社会」の定義を教えてください") 手続き確認型 ("行政手続きのデジタル化において、本人確認はどのような手順で行われますか?") 比較検討型 ("個人情報保護法と行政機関個人情報保護法の適用範囲の違いを比較して") 解釈適用型 ("AIを活用した行政サービスにおいて、個人情報保護法第27条の「利用目的の変更」はどのように解釈されますか?") 政策研究型 ("デジタル田園都市国家構想における地方自治体のDX推進について、法的課題と政策的な解決策を分析してください") 包括分析型 ("日本のデジタル・ガバメント政策について、関連法制度を包括的に分析し、今後の展望を教えてください") ``` -------------------------------- ### View cloud-init Logs Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.en.md Check the overall cloud-init log file for errors during VM initial setup. The output log contains command execution results. ```bash cat /var/log/cloud-init.log ``` ```bash cat /var/log/cloud-init-output.log ``` -------------------------------- ### vLLM Completions API Request Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/docs/APIM_POLICY_CUSTOMIZATION_GUIDE.md Example cURL command to test the vLLM Completions API in passthrough mode. Ensure to replace 'your-subscription-key' with your actual key. ```bash # パススルーモード(enablePlamoCustomApiTransform = false)で実際にリクエストして確認 curl -X POST "https://apim-xyz.azure-api.net/vllm/v1/completions" \ -H "Content-Type: application/json" \ -H "x-api-key: your-subscription-key" \ -d '{ "model": "pfnet/plamo-2-translate", "max_tokens": 1024, "temperature": 0, "stop": "<|plamo:op|>", "prompt": "<|plamo:op|>dataset translation <|plamo:op|>input lang=Japanese テスト <|plamo:op|>output lang=English\n" }' ``` -------------------------------- ### Completions Response Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example JSON response from the Completions API, showing completion text and usage token counts. ```json { "id": "cmpl-xxx", "object": "text_completion", "created": 1758264203, "model": "pfnet/plamo-2-translate", "choices": [ { "index": 0, "text": "ここに翻訳対象のテキストを入力してください。", "finish_reason": "stop" } ], "usage": { "prompt_tokens": 22, "total_tokens": 32, "completion_tokens": 10 } } ``` -------------------------------- ### Provision Azure Environment Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Use this command to provision the Azure environment. This process can take 30-40 minutes. If `deployVllmSupportModel` is true, additional time is needed for VM environment setup. ```bash azd provision ``` -------------------------------- ### Responses API Request Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example curl request for the Responses API, specifying the model, instructions, and user input. ```bash curl -X POST "https://apim-xyz.azure-api.net/openai/v1/responses" \ -H "Content-Type: application/json" \ -H "x-api-key: your-subscription-key" \ -d '{ "model": "gpt-4o", "instructions": "You are a helpful assistant.", "input": "What is 2+2?" }' ``` -------------------------------- ### Install Google Cloud SDK on macOS Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/README.md Command to install the Google Cloud SDK using Homebrew on macOS. This SDK is necessary for interacting with Google Cloud services. ```bash # macOS の場合 brew install google-cloud-sdk ``` -------------------------------- ### Example: Single Model, Multiple Requests Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/TEST_README.md Illustrates adding multiple usage records for the same model and then retrieving a summary. ```python tracker = BedrockUsageTracker() # 1回目のリクエスト tracker.add_usage( model_id="anthropic.claude-3-haiku-20240307-v1:0", usage={'inputTokens': 100, 'outputTokens': 50, 'totalTokens': 150} ) ``` -------------------------------- ### Chat Completions API Request Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example curl request for the Chat Completions API, including system and user messages. ```bash curl -X POST "https://apim-xyz.azure-api.net/openai/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "x-api-key: your-subscription-key" \ -d '{ "model": "gpt-4o", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"} ] }' ``` -------------------------------- ### Completions Request Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example of a curl request for the Completions API, specifying model, max tokens, temperature, stop sequence, and prompt for translation. ```bash curl -X POST https://apim-xyz.azure-api.net/vllm/v1/completions \ -H "Content-Type: application/json" \ -H "x-api-key: your-subscription-key" \ -d '{ "model": "pfnet/plamo-2-translate", "max_tokens": 1024, "temperature": 0, "stop": "<|plamo:op|>", "prompt": "<|plamo:op|>dataset translation <|plamo:op|>input lang=English Write the text to be translated here. <|plamo:op|>output lang=Japanese" }' ``` -------------------------------- ### Simple Client Request JSON Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/docs/APIM_POLICY_CUSTOMIZATION_GUIDE.md Example of a simplified JSON request format expected by the client. ```json { "inputs": { "input_text": "今日はいい天気です", "option": "Jp2En" } } ``` -------------------------------- ### Simple Client Response JSON Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/docs/APIM_POLICY_CUSTOMIZATION_GUIDE.md Example of the simplified JSON response format returned to the client. ```json { "statusCode": 200, "outputs": "It's nice weather today." } ``` -------------------------------- ### Install Terraform on macOS Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/README.md Command to install Terraform using Homebrew on macOS. Ensure Homebrew is installed and configured before running. ```bash # macOS の場合 brew install terraform ``` -------------------------------- ### View cloud-init Logs Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Check the cloud-init logs for VM initialization errors. '/var/log/cloud-init.log' contains the overall log, while '/var/log/cloud-init-output.log' shows command execution results. ```bash # cloud-init全体のログ cat /var/log/cloud-init.log ``` ```bash # cloud-initの出力ログ(コマンド実行結果など) cat /var/log/cloud-init-output.log ``` -------------------------------- ### Load Configuration Dynamically Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/core/README.md Demonstrates loading configuration parameters, such as system prompts and temperature settings, from configuration files using a ConfigManager. This avoids hardcoding and increases flexibility. ```python from config.config_manager import ConfigManager config = ConfigManager('answer_generation') system_prompt = config.get('systemPrompt') temperature = config.get('temperature') ``` -------------------------------- ### Start Azure Functions Locally Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/app/README.md Starts the Azure Functions host locally. The API will be accessible at http://localhost:7071/api/code-interpreter/responses. ```powershell # Azure Functionsをローカルで起動 func start ``` -------------------------------- ### Responses API Response Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example JSON response from the Responses API, showing the model's output and usage details. ```json { "id": "resp_...", "object": "response", "created_at": 1764584192, "status": "completed", "model": "gpt-4o", "output": [ { "type": "message", "content": [ { "type": "output_text", "text": "2 + 2 equals 4!" } ], "role": "assistant" } ], "usage": { "input_tokens": 24, "output_tokens": 11, "total_tokens": 35 } } ``` -------------------------------- ### Create Application Configuration File Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.md Create a TOML file in `config/apps/` for a new application, specifying only the parameters you wish to override from the default settings. Unspecified parameters will inherit values from the default configuration. ```toml # config/apps/my-new-app.toml # アプリケーション名 name = "my-new-app" description = "私の新しいRAGアプリケーション" # 回答生成の設定を上書き [answer_generation] # モデルをClaude 3 Sonnetに変更 modelId = "anthropic.claude-3-5-sonnet-20240620-v1:0" # システムプロンプトをカスタマイズ systemPrompt = ''' あなたは優秀なアシスタントです。提供された情報を元に、誠実に回答してください。 ''' # 推論パラメータを変更 temperature = 0.1 ``` -------------------------------- ### Distinguishing utils/ from services/ Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/utils/README.md Illustrates the difference between functions suitable for the `utils/` directory (generic, stateless, reusable) and those belonging in `services/` (domain-specific, stateful, external dependencies). ```python # ✅ utils/ に配置 def format_timestamp(timestamp: int) -> str: """タイムスタンプを人間が読める形式に変換""" # 汎用的、ステートレス、再利用可能 pass # ❌ utils/ に配置すべきでない def track_bedrock_usage(model_id: str, tokens: int): """Bedrockの使用量を追跡""" # Bedrock固有、状態を持つ → services/ へ pass ``` -------------------------------- ### Code Interpreter Request Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example JSON payload for the Code Interpreter API, including input text and file details for analysis. ```json { "inputs": { "input_text": "カテゴリごとの平均価格を計算し、横棒グラフで可視化してください。", "files": [ { "key": "excel_file", "files": [ { "filename": "sample_data1.xlsx", "content": "" }, { "filename": "sample_data2.xlsx", "content": "" } ] } ] } } ``` -------------------------------- ### Configuration Value Precedence Logic Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/config/README.md Illustrates the logic for determining configuration values, showing that environment variables have the highest priority, followed by application-specific settings, default settings, and finally code-defined defaults. ```python # config_manager.py def get(self, key: str, default=None): # 1. アプリ固有設定 if key in self.app_config: return self.app_config[key] # 2. デフォルト設定 if key in self.default_config: return self.default_config[key] # 3. フォールバック return default ``` -------------------------------- ### Copy Environment Configuration Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/README.md Use this command to copy the sample environment configuration to your custom environment directory. ```bash cp -r envs/sample envs/my-env ``` -------------------------------- ### BigQuery接続の作成 (gcloud CLI) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/docs/bq_connection_guide.md gcloud CLIを使用してBigQueryに接続を作成します。環境に合わせてプロジェクトID、リージョン、接続IDを置き換えてください。 ```bash bq mk --connection --location= --project_id= \ --connection_type=CLOUD_RESOURCE ``` -------------------------------- ### Deploy Azure Resources withazd CLI Source: https://context7.com/digital-go-jp/genai-ai-api/llms.txt Use the Azure Developer CLI (azd) to deploy resources on Azure. Log in and then initiate the deployment. ```bash # Deploy with Azure Developer CLI azd auth login azd up # Delete environment azd down ``` -------------------------------- ### Code Interpreter Response Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example JSON response from the Code Interpreter API, containing analysis output and generated artifacts like images. ```json { "outputs": "カテゴリごとの平均価格を計算し、横棒グラフで可視化しました。グラフを見ると、「電子機器」カテゴリが最も高い平均価格を示しています。", "artifacts": [ { "display_name": "cfile_691d8b5458288190886a3909acc28933.png", "content": "" } ] } ``` -------------------------------- ### Chat Completions API Response Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Example JSON response from the Chat Completions API, detailing the assistant's message and usage statistics. ```json { "choices": [ { "finish_reason": "stop", "index": 0, "message": { "content": "The capital of France is Paris.", "role": "assistant" } } ], "created": 1764584192, "id": "chatcmpl-...", "model": "gpt-4o-2024-11-20", "object": "chat.completion", "usage": { "completion_tokens": 8, "prompt_tokens": 25, "total_tokens": 33 } } ``` -------------------------------- ### DRY Principle in Configuration Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/config/README.md Illustrates the DRY principle by showing how to avoid repeating default settings in application-specific configuration files. Only changed values should be specified. ```toml # ❌ 悪い例: apps/qerag.toml modelId = "anthropic.claude-3-5-sonnet-20241022-v2:0" # デフォルトと同じ temperature = 0.1 # 変更箇所 maxTokens = 4096 # デフォルトと同じ # ✅ 良い例: apps/qerag.toml temperature = 0.1 # 変更箇所のみ ``` -------------------------------- ### Bootstrap AWS CDK Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.md Execute this command once for each AWS environment (account/region) before deploying the CDK for the first time. ```bash cdk bootstrap ``` -------------------------------- ### Lawsy-Custom-BQ API Response Example Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/README.md An example of the Markdown formatted response from the Lawsy-Custom-BQ API, detailing a legal definition, its basis, related concepts, and references. ```markdown # 質問: "デジタル社会形成基本法における「デジタル社会」の定義を教えてください" ## 定義の明確化 デジタル社会形成基本法第2条において、「デジタル社会」は次のように定義されています。 「インターネットその他の高度情報通信ネットワークを通じて自由かつ安全に多様な情報や知識を世界的規模で入手し、共有し、又は発信するとともに、人工知能、IoT(Internet of Things)その他のデジタル技術を活用して、多様な分野における創造的かつ活力ある発展が可能となる社会」 ## 法的根拠 🔗[[1]](https://elaws.e-gov.go.jp/document?lawid=503AC0000000035) デジタル社会形成基本法第2条第1号 ## 関連概念 この定義は以下の要素を含んでいます: - 高度情報通信ネットワークの活用 - 情報の自由で安全な流通 - 人工知能・IoT 等のデジタル技術の活用 - 多様な分野での創造的発展 ## 実務への影響 デジタル社会の実現に向けて、各省庁や地方自治体においてDX推進が求められています... (中略) ## 参考情報 🔗[デジタル社会形成基本法](https://elaws.e-gov.go.jp/document?lawid=503AC0000000035) 🔗[デジタル庁設置法](https://elaws.gov.jp/document?lawid=503AC0000000036) ``` -------------------------------- ### 接続サービスアカウントIDの取得 (gcloud CLI) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/docs/bq_connection_guide.md 作成したBigQuery接続の詳細を表示し、サービスアカウントIDを取得します。このIDはIAM権限付与に使用します。 ```bash bq show --connection --project_id= --location= ``` -------------------------------- ### Execute Full BQML Pipeline Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/docs/bqml_embedding_guide.md Run the complete pipeline for processing legal XML files, creating BigQuery tables, and building search indexes. Ensure the script is executable before running. ```bash chmod +x google-cloud/lawsy-custom-bq/preprocess/run_entire_pipeline.sh ./google-cloud/lawsy-custom-bq/preprocess/run_entire_pipeline.sh ``` -------------------------------- ### Example Categories for Generative AI Prompts Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/README.en.md These categories serve as examples provided to the generative AI for generating reports with appropriate sections. They cover various types of legal inquiries. ```text Definition Inquiry (定義確認型: "デジタル社会形成基本法における「デジタル社会」の定義を教えてください") Procedural Inquiry (手続き確認型: "行政手続きのデジタル化において、本人確認はどのような手順で行われますか?") Comparative Analysis (比較検討型: "個人情報保護法と行政機関個人情報保護法の適用範囲の違いを比較して") Interpretation & Application (解釈適用型: "AIを活用した行政サービスにおいて、個人情報保護法第27条の「利用目的の変更」はどのように解釈されますか?") Policy Research (政策研究型: "デジタル田園都市国家構想における地方自治体のDX推進について、法的課題と政策的な解決策を分析してください") Comprehensive Analysis (包括分析型: "日本のデジタル・ガバメント政策について、関連法制度を包括的に分析し、今後の展望を教えてください") ``` -------------------------------- ### Log in to Azure CLI Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Logs you into Azure CLI. Use `--use-device-code` for environments without a browser or `--tenant` to specify a tenant. ```bash az login ``` -------------------------------- ### GET /vllm/v1/models Source: https://context7.com/digital-go-jp/genai-ai-api/llms.txt Retrieves a list of available models that can be used with the API. ```APIDOC ## GET /vllm/v1/models ### Description Retrieves a list of available models that can be used with the API. ### Method GET ### Endpoint https://apim-xyz.azure-api.net/vllm/v1/models ### Parameters No parameters are required for this endpoint. ### Request Example ```bash curl -X GET "https://apim-xyz.azure-api.net/vllm/v1/models" \ -H "x-api-key: your-subscription-key" ``` ### Response #### Success Response (200) (Response structure not provided in the source text.) ``` -------------------------------- ### Create Application Configuration File (TOML) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.en.md Create a TOML configuration file in 'config/apps/' to override default settings for a new application. Only specify items that differ from the defaults. ```toml # config/apps/my-new-app.toml # Application name name = "my-new-app" description = "My new RAG application" # Override answer generation settings [answer_generation] # Change model to Claude 3 Sonnet modelId = "anthropic.claude-3-5-sonnet-20240620-v1:0" # Customize system prompt systemPrompt = ''' You are an excellent assistant. Please answer faithfully based on the provided information. ''' # Change inference parameters temperature = 0.1 ``` -------------------------------- ### Environment Separation for Configuration Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/config/README.md Shows how to separate configurations for different environments (dev/stg/prd) by using environment variables to switch configuration files. ```python # 環境変数で切り替え APP_PARAM_FILE = os.environ.get('APP_PARAM_FILE', 'qerag.toml') config = ConfigManager('answer_generation') ``` -------------------------------- ### Add Single Request Usage Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/TEST_README.md Example of adding usage data for a single request to the tracker. ```python tracker.add_usage( model_id="anthropic.claude-3-haiku-20240307-v1:0", usage={'inputTokens': 100, 'outputTokens': 50, 'totalTokens': 150} ) ``` -------------------------------- ### Deploy CDK Application (Bash) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.en.md Execute 'cdk deploy --all' with the environment specified using '-c env=' to deploy the application. This command applies WAF rules and deploys the CDK stack. ```bash # Deploy with environment specified (recommended) cdk deploy --all -c env=-dev # Development environment cdk deploy --all -c env=-stg # Staging environment cdk deploy --all -c env=-prd # Production environment ``` -------------------------------- ### IAM権限の付与 (gcloud CLI) Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/google-cloud/lawsy-custom-bq/docs/bq_connection_guide.md 取得したサービスアカウントIDにVertex AI ユーザーロールを付与します。これにより、BigQueryからVertex AIリソースへのアクセスが可能になります。 ```bash gcloud projects add-iam-policy-binding \ --member=serviceAccount: \ --role=roles/aiplatform.user ``` -------------------------------- ### Complex vLLM Response JSON Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/docs/APIM_POLICY_CUSTOMIZATION_GUIDE.md Example of the complex JSON response format returned by the vLLM backend. ```json { "id": "cmpl-xxx", "object": "text_completion", "choices": [{"text": "It's nice weather today.\n", "finish_reason": "stop"}], "usage": {"prompt_tokens": 22, "total_tokens": 32} } ``` -------------------------------- ### Deploy Azure Environment and Application Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/README.md Execute this command to deploy both the Azure environment and the application. This requires direct communication to Azure Functions/Azure OpenAI from the deployment terminal. ```bash azd up ``` -------------------------------- ### Complex vLLM Request JSON Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/azure/genai-azure/docs/APIM_POLICY_CUSTOMIZATION_GUIDE.md Example of the complex JSON request format expected by the vLLM backend. ```json { "model": "pfnet/plamo-2-translate", "max_tokens": 1024, "temperature": 0, "stop": "<|plamo:op|>", "prompt": "<|plamo:op|>dataset translation <|plamo:op|>input lang=Japanese 今日はいい天気です <|plamo:op|>output lang=English\n" } ``` -------------------------------- ### List Available Models Source: https://context7.com/digital-go-jp/genai-ai-api/llms.txt Retrieve a list of all available models by making a GET request to the Models API endpoint. ```bash curl -X GET "https://apim-xyz.azure-api.net/vllm/v1/models" \ -H "x-api-key: your-subscription-key" ``` -------------------------------- ### Bad Example: Sharing Global Variables Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/lib/constructs/rag-lambda/invokeModel/tests/README.md Illustrates a common pitfall of using global variables in tests, leading to stateful tests that affect each other. ```python # ❌ 悪い例: グローバル変数を共有 tracker = BedrockUsageTracker() def test_first(): tracker.track_model_usage(...) # 状態を変更 def test_second(): # test_first の影響を受ける pass ``` -------------------------------- ### RAG Query with Custom System Prompt (AWS) Source: https://context7.com/digital-go-jp/genai-ai-api/llms.txt Utilize a custom system prompt to guide the AI's response generation for specific queries. ```bash # Query with custom system prompt curl -X POST "https:///invoke" \ -H "Content-Type: application/json" \ -H "x-api-key: your-api-key" \ -d '{ "inputs": { "question": "予算申請の手順は?", "systemPromptForAnswerGeneration": "あなたは財務部門のエキスパートです。予算に関する質問に専門的に回答してください。" } }' ``` -------------------------------- ### Individual Application Configuration Source: https://github.com/digital-go-jp/genai-ai-api/blob/main/aws/query-expansion-rag/README.en.md TOML files defining detailed parameters for each specific RAG application. ```toml config/apps/*.toml ```