
Tool Calling
Tool Calling 관련
To interact with Ollama in R, you will utilize the ellmer
library. This library streamlines the use of large language models (LLMs) by offering an interface that enables seamless access to and interaction with a variety of LLM providers.
To enhance the LLM’s usage, we need to provide context to it. You can do this by tool calling. Tool calling allows an LLM to access external resources in order to enhance its functionality.
For this project, we are implementing Retrieval-Augmented Generation (RAG), which combines retrieving relevant information from a vector database and generating responses using an LLM. This approach improves the chatbot's ability to provide accurate and contextually relevant answers.
Now, define a function that links to the LLM to provide context using the tool()
function from the ellmer
library.
# load ellmer library
library(ellmer)
# function that links to llm to provide context
tool_context <- tool(
question,
"obtains the right context for a given question",
sentence = type_string()
)
The tool()
function takes the question function that returns the relevant documents that we’ll use as context as the first argument. We’ll use the documents to help the LLM answer questions accordingly.
The text, "obtains the right context for a given question", is a description of what the tool will be doing.
Finally, the sentence = type_string()
defines what type of object the question()
function expects.