文字生成

Snowflake 生成式 AI 入門

James Cha-Earley

Senior Developer Advocate, Snowflake

管理飯店評論回覆

黃昏海岸的飯店

1 由 Google Gemini 2.5 Pro 產生的影像
Snowflake 生成式 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 生成式 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 生成式 AI 入門

從資料庫擷取

儲存格 1 的 SQL 查詢

儲存格 2 的 Python 程式碼

Snowflake 生成式 AI 入門

產生回覆

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# Pass the prompt response = complete(prompt=prompt,
Snowflake 生成式 AI 入門

產生回覆

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# Specify the model response = complete(prompt=prompt, model='llama3.1-8b',
Snowflake 生成式 AI 入門

產生回覆

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# Set the temperature - control predictability of output response = complete(prompt=prompt, model='llama3.1-8b', options={ 'temperature':0.3,
Snowflake 生成式 AI 入門

產生回覆

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# Limit the number of tokens with max_tokens response = complete(prompt=prompt, model='llama3.1-8b', options={ 'temperature':0.3, 'max_tokens':150 } )
Snowflake 生成式 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 生成式 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 生成式 AI 入門

Snowflake 筆記本中的輸出

Snowflake 筆記本中的 AI_COMPLETE() 輸出

  • AI_COMPLETE() 開箱即用
Snowflake 生成式 AI 入門

在 Snowflake 中的文字生成

-- Coding in SQL cells
AI_COMPLETE(
  'llama3.1-8b',
  PROMPT('Write a short response 
          to this hotel review: {0}.', 
          DESCRIPTION),
  {'temperature': 0.3, 
   'max_tokens': 150}
    )
  • 為多筆列批次生成文字
# Coding in Python cells
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 生成式 AI 入門

一起來練習吧!

Snowflake 生成式 AI 入門

Preparing Video For Download...