Always show tool calls, toggle whether results are hidden

This commit is contained in:
Matt Low 2024-06-21 06:05:00 +00:00
parent c30e652103
commit 31df055430

View File

@ -160,30 +160,34 @@ func (m *Model) renderMessage(i int) string {
toolString = "tool_calls:\n" + string(bytes) toolString = "tool_calls:\n" + string(bytes)
} }
case api.MessageRoleToolResult: case api.MessageRoleToolResult:
if !m.showToolResults {
break
}
type renderedResult struct { type renderedResult struct {
ToolName string `yaml:"tool"` ToolName string `yaml:"tool"`
Result any Result any `yaml:"result,omitempty"`
} }
var toolResults []renderedResult var toolResults []renderedResult
for _, result := range msg.ToolResults { for _, result := range msg.ToolResults {
var jsonResult interface{} if m.showToolResults {
err := json.Unmarshal([]byte(result.Result), &jsonResult) var jsonResult interface{}
if err != nil { err := json.Unmarshal([]byte(result.Result), &jsonResult)
// If parsing as JSON fails, treat Result as a plain string if err != nil {
toolResults = append(toolResults, renderedResult{ // If parsing as JSON fails, treat Result as a plain string
ToolName: result.ToolName, toolResults = append(toolResults, renderedResult{
Result: result.Result, ToolName: result.ToolName,
}) Result: result.Result,
})
} else {
// If parsing as JSON succeeds, marshal the parsed JSON into YAML
toolResults = append(toolResults, renderedResult{
ToolName: result.ToolName,
Result: &jsonResult,
})
}
} else { } else {
// If parsing as JSON succeeds, marshal the parsed JSON into YAML // Only show the tool name when results are hidden
toolResults = append(toolResults, renderedResult{ toolResults = append(toolResults, renderedResult{
ToolName: result.ToolName, ToolName: result.ToolName,
Result: &jsonResult, Result: "(hidden, press ctrl+t to view)",
}) })
} }
} }
@ -226,17 +230,6 @@ func (m *Model) conversationMessagesView() string {
for i, message := range m.messages { for i, message := range m.messages {
m.messageOffsets[i] = lineCnt m.messageOffsets[i] = lineCnt
switch message.Role {
case api.MessageRoleToolCall:
if !m.showToolResults && message.Content == "" {
continue
}
case api.MessageRoleToolResult:
if !m.showToolResults {
continue
}
}
heading := m.renderMessageHeading(i, &message) heading := m.renderMessageHeading(i, &message)
sb.WriteString(heading) sb.WriteString(heading)
sb.WriteString("\n") sb.WriteString("\n")