การสร้างการตอบสนองของแชทบอต

การออกแบบระบบ Agentic ด้วย 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.
การออกแบบระบบ Agentic ด้วย LangChain

การสตรีมการตอบสนองของ LLM

# Define a function to execute the chatbot based on user input
def stream_graph_updates(user_input: str):


# Start streaming events from the graph with the user's input for event in graph.stream({"messages": [("user", user_input)]}):
# Retrieve and print the chatbot node responses for value in event.values(): print("Agent:", value["messages"])
# Define the user query and run the chatbot user_query = "Who is Mary Shelley?" stream_graph_updates(user_query)
การออกแบบระบบ Agentic ด้วย 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-...')]
การออกแบบระบบ Agentic ด้วย LangChain

LLM กับ hallucination

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-...)

   

ตัวอย่างของ hallucination

 

  • ลูกชายที่มีชื่อเสียงของ Judith Love Cohen คือ Jack Black ไม่ใช่ "Adam Cohen"
การออกแบบระบบ Agentic ด้วย LangChain

สร้างไดอะแกรม LangGraph

# Import modules for chatbot diagram
from IPython.display import 
Image, display


# Try generating and displaying # the graph diagram try: display(Image(graph.get_graph() .draw_mermaid_png()))
# Return an exception if necessary except Exception: print("Additional dependencies required.")

ไดอะแกรม LangGraph ของแชทบอตพื้นฐาน

การออกแบบระบบ Agentic ด้วย LangChain

มาฝึกกันเถอะ!

การออกแบบระบบ Agentic ด้วย LangChain

Preparing Video For Download...