Генерація тексту

Вступ до Generative AI у Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

Керування відповідями на відгуки про готель

Готель на узбережжі на заході сонця

1 Зображення згенероване за допомогою Google Gemini 2.5 Pro
Вступ до Generative AI у Snowflake

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)
Вступ до Generative AI у Snowflake

Друк підсумку

print(summarized_review)
Готель перевершив очікування: неймовірні краєвиди, відмінний персонал,
зручні ліжка та чудові ресторани на місці — ідеальний вибір, дуже
рекомендуємо.
Вступ до Generative AI у Snowflake

Витяг з бази даних

SQL-запит у cell1

Код Python у cell2

Вступ до Generative AI у Snowflake

Генерація відповіді

from snowflake.cortex import complete


prompt = f"Write a short response to this hotel review: {latest_review}."
# Pass the prompt response = complete(prompt=prompt,
Вступ до Generative AI у Snowflake

Генерація відповіді

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',
Вступ до Generative AI у Snowflake

Генерація відповіді

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,
Вступ до Generative AI у Snowflake

Генерація відповіді

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 } )
Вступ до Generative AI у Snowflake

Перегляд відповіді

print(response)
Дуже дякуємо, що поділилися чудовими враженнями від Hyatt Nice!
Ми раді чути, що ваше перебування було справді фантастичним.
  • Швидко, гнучко, автентично
Вступ до Generative AI у Snowflake

Генерація тексту за допомогою 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;
Вступ до Generative AI у Snowflake

Результат у нотатнику Snowflake

Вивід AI_COMPLETE() у нотатнику Snowflake

  • AI_COMPLETE() доступна «з коробки»
Вступ до Generative AI у Snowflake

Генерація тексту в 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}
    )
  • Використовуйте для ланцюжків багатокрокових робочих процесів
Вступ до Generative AI у Snowflake

Давайте потренуємось!

Вступ до Generative AI у Snowflake

Preparing Video For Download...