Skip to content

チャットとプロンプティング

チャットは、会話の履歴とコンテキストを保持しながら、プロンプトを通じてLLMと対話する方法を提供します。 チャットを使用すると、LLMアプリケーションとマルチターン会話を行うことができ、各プロンプトで会話内の以前のメッセージを参照できます。

チャットの作成

LLMブループリントから新しいチャットを作成します。 チャットを作成する際は、以下を指定する必要があります。

  • name:チャットのわかりやすい名前。
  • llm_blueprint:チャットに関連付けるLLMブループリントIDまたはLLMBlueprintオブジェクト。
import datarobot as dr
blueprint = dr.genai.LLMBlueprint.get(blueprint_id)
chat = dr.genai.Chat.create(
    name="Customer Support Chat",
    llm_blueprint=blueprint_id
)
chat 

チャットへのプロンプトの送信

datarobot.ChatPrompt.submit()を使用して、プロンプトを送信し、回答を受け取ります。

chat = dr.genai.Chat.get(chat_id)
prompt = dr.genai.ChatPrompt.create(
    chat=chat.id,
    text="What is your return policy?"
)
prompt.result_text 

会話履歴を保持したまま、フォローアッププロンプトを送信します。

followup = dr.genai.ChatPrompt.create(
    chat=chat.id,
    text="How long does it take to process a return?"
)
print(f"Response: {followup.result_text}") 

チャット履歴の取得

datarobot.ChatPrompt.list()を使用して、チャット内のすべてのプロンプトを取得します。

chat = dr.genai.Chat.get(chat_id)
prompts = dr.genai.ChatPrompt.list(chat=chat.id)
for prompt in prompts:
    prompt.text
    prompt.result_text 

LLMブループリントでプロンプトをフィルターします。

blueprint = dr.genai.LLMBlueprint.get(blueprint_id)
blueprint_prompts = dr.genai.ChatPrompt.list(llm_blueprint=blueprint.id) 

プレイグラウンドでプロンプトをフィルターします。

playground = dr.genai.Playground.get(playground_id)
playground_prompts = dr.genai.ChatPrompt.list(playground=playground.id) 

チャットの管理

すべてのチャットをリストします。

all_chats = dr.genai.Chat.list()
print(f"Found {len(all_chats)} chat(s):")
for chat in all_chats:
    print(f"  - {chat.name} (ID: {chat.id})") 

LLMブループリントでフィルターします。

blueprint = dr.genai.LLMBlueprint.get(blueprint_id)
blueprint_chats = dr.genai.Chat.list(llm_blueprint=blueprint.id) 

チャット名を更新します。

chat = dr.genai.Chat.get(chat_id)
chat.update(name="Updated Chat Name") 

チャットを削除します。

chat.delete() 

チャット情報の取得

チャットの詳細を取得します。

chat = dr.genai.Chat.get(chat_id)
print(f"Name: {chat.name}")
print(f"LLM Blueprint: {chat.llm_blueprint_id}")
print(f"Is frozen: {chat.is_frozen}")
print(f"Prompts count: {chat.prompts_count}")
print(f"Warning: {chat.warning}")