テキスト生成

Snowflake による Generative AI 入門

James Cha-Earley

Senior Developer Advocate, Snowflake

ホテル口コミへの返信管理

夕暮れの海岸沿いのホテル

1 画像は Google Gemini 2.5 Pro で生成
Snowflake による Generative AI 入門

summarize()

long_review = """
This hotel was nothing short of amazing. The best views; the best location;
and the best staff. It's clean; conveniently located to other restaurants
on the strip; although we ate at the restaurants on site and each was so good
there's really no reason to leave. Ohhh the views. The beach was free of seaweed; 
amazingly clean and plenty of space; it wasn't crowded at all. 
Stay here; you will not regret it. Did I mention how comfortable the beds were. 
Yes save yourself trouble and stay here. It's really perfect.
"""

from snowflake.cortex import summarize summarized_review = summarize(text=long_review)
Snowflake による Generative AI 入門

要約の表示

print(summarized_review)
The hotel exceeded expectations with stunning views, exceptional staff,
comfortable beds, and top-notch on-site dining, making it a perfect and 
highly recommended stay.
Snowflake による Generative AI 入門

データベースからの抽出

セル1の SQL クエリ

セル2の Python コード

Snowflake による Generative AI 入門

返信の生成

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# プロンプトを渡す response = complete(prompt=prompt,
Snowflake による Generative AI 入門

返信の生成

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# 使用モデルを指定 response = complete(prompt=prompt, model='llama3.1-8b',
Snowflake による Generative AI 入門

返信の生成

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# temperature を設定 — 出力の予測性を調整 response = complete(prompt=prompt, model='llama3.1-8b', options={ 'temperature':0.3,
Snowflake による Generative AI 入門

返信の生成

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# max_tokens でトークン数を制限 response = complete(prompt=prompt, model='llama3.1-8b', options={ 'temperature':0.3, 'max_tokens':150 } )
Snowflake による Generative AI 入門

返信の確認

print(response)
Thank you so much for sharing your wonderful experience at the Hyatt Nice! 
We're thrilled to hear that you had a fantastic stay with us.
  • 高速・柔軟・自然
Snowflake による Generative AI 入門

AI_COMPLETE() による生成

SELECT
  DESCRIPTION,
  AI_COMPLETE(

'llama3.1-8b',
PROMPT('Write a short response to this hotel review: {0}.', DESCRIPTION),
{'temperature': 0.3, 'max_tokens': 150}
) AS completion FROM HOTELS.REVIEWS ORDER BY date DESC LIMIT 1;
Snowflake による Generative AI 入門

Snowflake ノートブックでの出力

Snowflake ノートブックでの AI_COMPLETE() の出力

  • AI_COMPLETE() はすぐに利用可能
Snowflake による Generative AI 入門

Snowflake でのテキスト生成

-- SQL セルで記述
AI_COMPLETE(
  'llama3.1-8b',
  PROMPT('Write a short response 
          to this hotel review: {0}.', 
          DESCRIPTION),
  {'temperature': 0.3, 
   'max_tokens': 150}
    )
  • 複数行を一括生成
# Python セルで記述
complete(
    model='llama3.1-8b', 
    prompt = f"""Write a short response
        to this hotel review: 
        {latest_review}.""",
    options={'temperature':0.3,
             'max_tokens':150}
    )
  • 複数工程のワークフロー連結に活用
Snowflake による Generative AI 入門

Vamos praticar!

Snowflake による Generative AI 入門

Preparing Video For Download...