0
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?

watsonx.ai & watsonx.governanceで3rd partyのLLMによるRAGを評価②

Posted at

以下で、3rd ParthのLLMによるRAGのための検証データを作成しました。
https://qiita.com/yono1o12/items/01fc190c1facc65b9b76

次に、3rd PartyのLLMに対して、プロンプトテンプレートをWatsonx.governance上でモデル本体から切り離して(detached)登録・評価できるようにします。これにより、プロンプトの品質やリスクを、LLM本体とは独立してチェック・改善できるようになります。detachはwatsonx.ai/Watson Studioで以下を実行すればOKです。尚、以下はOpenShift上にインストールされたwatsonx.aiで実施していますが、SaaSのwatsonx.aiもCloudPakforDataConfig()の以外は同じ手順で可能なはずです。

!pip install --upgrade ibm-aigov-facts-client | tail -n 1
AZURE_OPENAI_ENDPOINT = "<INPUT YOUR AZURE_OPENAI_ENDPOINT>"
AZURE_OPENAI_DEPLOYMENT_NAME = "<INPUT YOUR AZURE_OPENAI_DEPLOYMENT_NAME>"
CPD_URL = "<INPUT YOUR CPD_URL>"
CPD_USERNAME = "<INPUT YOUR CPD_USERNAME>"
CPD_API_KEY = "<INPUT YOUR CPD_API_KEY>"
import os

PROJECT_ID = os.environ.get('PROJECT_ID')
print(PROJECT_ID)
from ibm_aigov_facts_client import (
    AIGovFactsClient, CloudPakforDataConfig,
    DetachedPromptTemplate, PromptTemplate
)
from ibm_aigov_facts_client.utils.enums import Task

creds = CloudPakforDataConfig(
    service_url=CPD_URL,
    username=CPD_USERNAME,
    api_key=CPD_API_KEY
)
facts_client = AIGovFactsClient(
    cloud_pak_for_data_configs=creds,
    container_id=PROJECT_ID,
    container_type="project",
    disable_tracing=True
)
PROMPT_TEMPLATE = """# System:
Answer the question based on the context.

# Context:
{context}

# Question
{question}

# Answer:
""".strip()
detached_information = DetachedPromptTemplate(
    prompt_id="detached-aoai-prompt",
    model_id=f"azure/{AZURE_OPENAI_DEPLOYMENT_NAME}",
    model_provider="Azure OpenAI",
    model_name="GPT-3.5-turbo",
    model_url=AZURE_OPENAI_ENDPOINT,
    prompt_url="prompt_url",
    prompt_additional_info={"model_owner": "Microsoft", "model_version": "gpt-3.5-turbo-1106"}
)
prompt_name = "Detached prompt for Azure OpenAI GPT-3.5-turbo TEST2"
prompt_description = "A detached prompt for RAG using Azure OpenAI's GPT-3.5-turbo model TEST2"

# define parameters for PromptTemplate
prompt_template = PromptTemplate(
    input=PROMPT_TEMPLATE,
    prompt_variables={"context": "", "question": ""},
)
pta_details = facts_client.assets.create_detached_prompt(
    model_id=f"azure/{AZURE_OPENAI_DEPLOYMENT_NAME}",
    task_id="retrieval_augmented_generation",
    name=prompt_name,
    description=prompt_description,
    prompt_details=prompt_template,
    detached_information=detached_information
)
project_pta_id = pta_details.to_dict()["asset_id"]
print(f"Detached Prompt template ID: '{project_pta_id}'")

watsonx.aiのプロジェクトで切り離されたプロンプトテンプレートが作成されていればOkです。

image.png

0
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
0
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?