Özel araçlar oluşturma

LangChain ile Aracı Sistemler Tasarlama

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

Metrekare hesabı

Stüdyo dairenin dikdörtgen planı

LangChain ile Aracı Sistemler Tasarlama

Metrekare hesabı

Uzunluk ve genişliği sırasıyla "kenar a" ve "kenar b" olarak işaretlenmiş stüdyo daire dikdörtgen planı.

LangChain ile Aracı Sistemler Tasarlama

Bir matematik aracı oluşturma

LangChain'in dahili sorgu işleme süreci

"What is the area of a rectangle with 
sides 5 and 7?"

input = " 5, 7"

     

  • Doğal dil girişi

         
  • Sayısal değerleri metin olarak çıkarma

LangChain ile Aracı Sistemler Tasarlama

Bir matematik aracı oluşturma

Araç işlevinizi tanımlayın

@tool

def rectangle_area(input: str) -> float:
"""Calculates the area of a rectangle given the lengths of sides a and b."""
sides = input.split(',')
a = float(sides[0].strip()) b = float(sides[1].strip())
return a * b

 

  • @tool dekoratörünü kullanın
  • Fonksiyona ad verin
  • Bir docstring yazın
  • Girdiyi .split() ile ayırın
  • Boşlukları .strip() ile temizleyip float'a çevirin
  • a ve b'yi çarpıp sonucu döndürün
LangChain ile Aracı Sistemler Tasarlama

Araçlar ve sorgu kurulumu

# Define the tools that the agent can access
tools = [rectangle_area]

# Create a query using natural language query = "What is the area of a rectangle with sides 5 and 7?"
# Pass in the hypotenuse length tool and invoke the agent app = create_react_agent(model, tools)
LangChain ile Aracı Sistemler Tasarlama

Araçlar ve sorgu kurulumu

# Invoke the agent and print the response
response = app.invoke({"messages": [("human", query)]})
print(response['messages'][-1].content)
The area of the rectangle with sides 5 and 7 is 35 square units.
LangChain ile Aracı Sistemler Tasarlama

Hazır ve özel araçlar

    Araç simgesi

 

LangChain ile Aracı Sistemler Tasarlama

Hadi pratik yapalım!

LangChain ile Aracı Sistemler Tasarlama

Preparing Video For Download...