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,17 +160,14 @@ func (m *Model) renderMessage(i int) string {
toolString = "tool_calls:\n" + string(bytes)
}
case api.MessageRoleToolResult:
if !m.showToolResults {
break
}
type renderedResult struct {
ToolName string `yaml:"tool"`
Result any
Result any `yaml:"result,omitempty"`
}
var toolResults []renderedResult
for _, result := range msg.ToolResults {
if m.showToolResults {
var jsonResult interface{}
err := json.Unmarshal([]byte(result.Result), &jsonResult)
if err != nil {
@ -186,6 +183,13 @@ func (m *Model) renderMessage(i int) string {
Result: &jsonResult,
})
}
} else {
// Only show the tool name when results are hidden
toolResults = append(toolResults, renderedResult{
ToolName: result.ToolName,
Result: "(hidden, press ctrl+t to view)",
})
}
}
bytes, err := yaml.Marshal(toolResults)
@ -226,17 +230,6 @@ func (m *Model) conversationMessagesView() string {
for i, message := range m.messages {
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)
sb.WriteString(heading)
sb.WriteString("\n")