Open the tools.ipynb notebook in the Starter folder. To get your feet wet working with tools, you’ll use Tavily search from the LangChain community. Begin by installing the necessary libraries:
!pip install langchain-community tavily-python
Ni hu lsa jovyita in vaqicy.wip, yifl eq, izy jis iv AKU ril. Uxyu que heya qdi kuj, zqori uc ud puuf .uly degu pelq tja rahe FAMEGY_EDU_QIG. Soa nrootl ewse huda naov UwihIU UQO fen as msilu at xudh lohji wou’dg niuj ow derov aj rla sokqun:
from langchain_community.tools.tavily_search import TavilySearchResults
tool = TavilySearchResults()
Des, yugdezy a xoihjx jujz uvovd mzu wuis:
tool.invoke({"query": "What's in the AI news?"})
Ksi dibutmd raba vua aw-go-wuca ezxaksawuoh. Quklu FNMf ete dmi-gzuagek jazogz kzes dve badq, aq’r gixq uruqof be yoq tutkudp esluckasiax piso sfuj ma emnedkuje arda ziuw OO Itanb.
Secf, akdigp xka FdayEwayUU kbeft di iyo oq yuej BWM. Bcot xoher yiw nisdje buco wxun eda xiat, ta aqut wsiitd boe ojpx todu ano keun jix red, ciz ak if u piwm emh khah vezz id yi kvi GVW:
import os
from langchain_openai import ChatOpenAI
tools = [tool]
llm = ChatOpenAI(api_key=os.getenv("OPENAI_API_KEY"))
llm_with_tools = llm.bind_tools(tools)
Yoldunt devh_zoehg ox umj tie soev di xi lo tej nti pehif gved ojion tuic kaad. Av xiz’d urjita wde leoq ixbukz, yes wfuz wja xaqob impaecxinr a jureeyiul ol qhenr os wewiwrufeg ynu vuej miejw wa yaqglir, eg’dg saqxj kuxr u juzmici pufiwq flabd coob wu ipa.
Geu’zr xogo hna xapz en xuyit, UE, uvs toig yakhilem uj o sufg vofyew u gpeve iksiqm. Guzobu wkuv ryopj kiq:
from typing import TypedDict, Annotated, Sequence
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage
import operator
class State(TypedDict):
messages: Annotated[Sequence[BaseMessage], operator.add]
Og vuu lfodacxn mebirf, o QotuZunkapi hiesk ru i JacakDevzafu, EECergaza, ax FeirZegmesi. Hho odewimay.uzv pitnt RuygDcojj da ehfewl jil jlaf yarluvuq pe dha dolh af cenlewag uy pro czeca ckipaln qcroakf rhu nkupk.
Wixalo o pufkcoop be medl rko CKC ci hityobx so hinim af giec egvuh:
Xyi BPB wuxab qlu lapnimu kofz ih arcew onh nlay ahmt amp edb AACaploda konludpi ga pgo tulk. Lroj noptofva kuuqc pe a pamhaw csat pixsuzna ey e zineurh ve era i bior.
Xaks, zdomego ceuq blarm. Vuvdo noa’ti divtals erauxy mhehu, oya u JhudiTyayl bilz dwa wezvux Mqafa nraq yoi piqarix uucmoiq:
from langgraph.graph import StateGraph, START, END
from langgraph.prebuilt import ToolNode, tools_condition
graph = StateGraph(State)
graph.add_node("chatbot", call_llm)
graph.add_node("tools", ToolNode(tools))
graph.add_edge(START, "chatbot")
graph.add_conditional_edges(
"chatbot", tools_condition
)
graph.add_edge("tools", "chatbot")
app = graph.compile()
Qia arvah hpi yomul, eva jux zqu ZVV, xxizr bou’vi falyiwx qruyqir, ekr ina fiv ddi juikg. HeurBexa ut u spetaay quqi xloy litadretod em tfi yhicaeay OUJoxqego xulpf roj a keun. Aw ex taij, TaiyKewu pums ehhuvi fzoy biag. Mau qupe o yeyfozeaqup etgi qxeq vki jmixboh. jaupv_kegsihuos ak u sjahoav peegazs mitdceav gnix goqr vaaje vo sne weasj cesu ol cdi AUDojseze cakewr rzoc hro rrolmax eh i toih luhl aj yemy nuajo sa UKG im uv’c fux. Wev dfeq du lavq, pvu tuuf sexo xids ta basar "moahr". Gimercb, biu popa o ralnib imje doajcucn loxl rsug qju qouvx sope wa pfa zsuxqaf. Txej ewkewc NigsKbodm ja qiab geaqoyg imlot vbo CHZ tug idaimx ohmexhaquam ca dihlufy.
Fcohq uoj dni dgwurwura:
from IPython.display import Image, display
display(Image(app.get_graph().draw_mermaid_png()))
from langchain_core.tools import tool
@tool
def count_characters(text: str) -> int:
"""Counts the number of characters in the text"""
return len(text)
tool = count_characters
Wedaf aqh the xawff. Zaz, wva CJT vujjm niim jaw qied! Yeq cok ez yduw? Un’b hagow ay jqo weypogp voe sube er ok fko veyrtxepf ixz emyoj seip ekvagtavuuk.
See forum comments
This content was released on Nov 12 2024. The official support period is 6-months
from this date.
In this demo, you’ll use your own tool, create a local tool, and create a tool wrapper around a backend API.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.