The BookAssistant is designed to interact with users, retrieve book information using various tools, and present structured responses. It leverages a language model (ChatAnthropic), Vector database, and a LangChain state graph to efficiently manage interactions and data flow.
Untitled.video.-.Made.with.Clipchamp.2.mp4
The BookAssistant
class initializes several components:
- Language Model: Uses ChatAnthropic.
- Tools: Defines tools (
googleAPI_retrieval
,present_book_info
,search_db
) for retrieving and presenting book information.
-
State Graph: Constructs a state graph to manage state transitions and tool interactions.
- Nodes and Edges:
- Adds nodes for an assistant (handling user interactions) and tools (containing tools and error handling).
- Establishes conditional edges and entry points (assistant) within the graph.
- Nodes and Edges:
-
googleAPI_retrieval
: This class acts as a wrapper for retrieving data from the Google Books API. The fetched data is stored in both JSON format and a Chroma database, facilitating efficient extraction and search operations. -
present_book_info
: This function extracts data from the JSON file and renders it in the chat interface using a token, enhancing data presentation reliability and reducing model token usage. -
search_db
: Enables vector similarity search on retrieved data, enhancing search capabilities based on content similarity.