Генерування відповідей чатбота

Проєктування агентних систем з LangChain

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

Стрімінг подій графа

   

  • Транслюйте події в реальному часі

  • Кожна подія — це крок робочого процесу

  • Відстежуйте відповіді та виклики інструментів

  • Відстежуйте прогрес чатбота

User: Where is the Congo?

Agent: Let me check some details for you...
Agent: AIMessage([Tool Call to Google Maps] Searching for information on "the Congo")
Agent: The Democratic Republic of Congo is a country in Central Africa.
Проєктування агентних систем з LangChain

Стрімінг відповідей LLM

# Визначте функцію для запуску чатбота за введенням користувача
def stream_graph_updates(user_input: str):


# Почніть транслювати події з графа з введенням користувача for event in graph.stream({"messages": [("user", user_input)]}):
# Отримайте та виведіть відповіді вузлів чатбота for value in event.values(): print("Agent:", value["messages"])
# Задайте запит користувача та запустіть чатбота user_query = "Who is Mary Shelley?" stream_graph_updates(user_query)
Проєктування агентних систем з LangChain

Стрімінг відповідей LLM

   Agent: [AIMessage(content='Mary Shelley (1797-1851) was an English 
   novelist...

...best known for her groundbreaking work in the Gothic genre, particularly for her novel "Frankenstein; or, The Modern Prometheus," published in 1818. This novel is often considered one of the earliest examples of science fiction and explores themes of creation, responsibility, and the nature of humanity through the story of Victor Frankenstein, a scientist who creates a sentient creature in an unorthodox experiment...',
response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-mini-...')]
Проєктування агентних систем з LangChain

LLM і галюцинації

Agent: [AIMessage(content='Judith 
Love Cohen was an American aerospace 
engineer, and worked on various 
space missions, including the Apollo 
program... Cohen was also the mother 
of actor and writer Adam Cohen, 
who has spoken about her influence on 
his life and career. 
additional_kwargs={}, 
response_metadata={'finish_reason': 
'stop', 'model_name': 
'gpt-4o-mini-...)

   

Приклад галюцинації

 

  • Відомий син Judith Love Cohen — Jack Black, а не «Adam Cohen».
Проєктування агентних систем з LangChain

Згенеруйте діаграму LangGraph

# Імпортуйте модулі для діаграми чатбота
from IPython.display import 
Image, display


# Спробуйте згенерувати й показати # діаграму графа try: display(Image(graph.get_graph() .draw_mermaid_png()))
# За потреби поверніть виняток except Exception: print("Additional dependencies required.")

Базова діаграма чатбота LangGraph.

Проєктування агентних систем з LangChain

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

Проєктування агентних систем з LangChain

Preparing Video For Download...