Implementing a tool that doesn't require the assistant to interpretate the results #701
-
I am implementing a tool to generate charts: The class: module Langchain::Tool
class Chart < Base
#
# Generates charts from the data
#
# Gem requirements:
# gem "chartkick"
#
# Usage:
# chart = Langchain::Tool::Chart.new()
#
NAME = "chart"
ANNOTATIONS_PATH = Langchain.root.join("#{__dir__}/#{NAME}.json").to_path
# @return [Chart] Chart object
def initialize()
end
# Chart Tool: Returns the received data
#
# @param data [Array] Array of arrays "key, value"
# @return [Array] the data
def create_line_chart(data:)
data
end
end
end The json: [
{
"type": "function",
"function": {
"name": "chart__create_line_chart",
"description": "Chart Tool: Display a line chart of the data",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "string",
"description": "The data to display in the chart. In the format of an array of arrays [key, value]"
}
},
"required": ["data"]
}
}
}
] I want the assistant to generate the Then, a helper method captures this message and interprets the
It works more or less: The problem is that, following the pattern of function calling, I have to send the result of the function call back to the assistant for its interpretation (this happens automagically because I am using
It is hallucinating a chart attachment. I don't know how to implement this. I don't know if I need the function at all because it does not do much besides offering the function call frame for the assistant to build the proper message. Also, I don't know if I can skip (or if I should) the step of sending the function result back to the assistant for its interpretation. Just some rambling here asking for some ideas sparring |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@fguillen Are you expecting that the Chart tool would return an image that the LLM would then display back to the user?
You can always tell it in the instructions to stop doing that, basically you want to tell it in the instructions how to behave.
You can return you'd like from the Tool, e.g.: def create_line_chart(data:)
# Creating the line chart
return true # or return("Successfully created the line chart")
end |
Beta Was this translation helpful? Give feedback.
@fguillen Are you expecting that the Chart tool would return an image that the LLM would then display back to the user?
You can always tell it in the instructions to stop doing that, basically you want to tell it in the instructions how to behave.
You can return you'd like from the Tool, e.g.: