Fix: removed code that deletes tool calls
This commit is contained in:
20
bot.go
20
bot.go
@@ -1144,12 +1144,10 @@ func findCall(msg, toolCall string) bool {
|
|||||||
// Store tool call info in the assistant message
|
// Store tool call info in the assistant message
|
||||||
// Convert Args map to JSON string for storage
|
// Convert Args map to JSON string for storage
|
||||||
argsJSON, _ := json.Marshal(lastToolCall.Args)
|
argsJSON, _ := json.Marshal(lastToolCall.Args)
|
||||||
chatBody.Messages[lastMsgIdx].ToolCalls = []models.ToolCall{
|
chatBody.Messages[lastMsgIdx].ToolCall = &models.ToolCall{
|
||||||
{
|
ID: lastToolCall.ID,
|
||||||
ID: lastToolCall.ID,
|
Name: lastToolCall.Name,
|
||||||
Name: lastToolCall.Name,
|
Args: string(argsJSON),
|
||||||
Args: string(argsJSON),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
// call a func
|
// call a func
|
||||||
_, ok := fnMap[fc.Name]
|
_, ok := fnMap[fc.Name]
|
||||||
@@ -1210,15 +1208,15 @@ func chatToTextSlice(messages []models.RoleMsg, showSys bool) []string {
|
|||||||
for i := range messages {
|
for i := range messages {
|
||||||
icon := fmt.Sprintf("[-:-:b](%d) <%s>:[-:-:-]", i, messages[i].Role)
|
icon := fmt.Sprintf("[-:-:b](%d) <%s>:[-:-:-]", i, messages[i].Role)
|
||||||
// Handle tool call indicators (assistant messages with tool call but empty content)
|
// Handle tool call indicators (assistant messages with tool call but empty content)
|
||||||
if messages[i].Role == cfg.AssistantRole && len(messages[i].ToolCalls) > 0 {
|
if messages[i].Role == cfg.AssistantRole && messages[i].ToolCall != nil && messages[i].ToolCall.ID != "" {
|
||||||
// This is a tool call indicator - show collapsed
|
// This is a tool call indicator - show collapsed
|
||||||
if toolCollapsed {
|
if toolCollapsed {
|
||||||
toolName := messages[i].ToolCalls[0].Name
|
toolName := messages[i].ToolCall.Name
|
||||||
resp[i] = fmt.Sprintf("%s\n[yellow::i][tool call: %s (press Ctrl+T to expand)][-:-:-]", icon, toolName)
|
resp[i] = fmt.Sprintf("%s\n[yellow::i][tool call: %s (press Ctrl+T to expand)][-:-:-]\n", icon, toolName)
|
||||||
} else {
|
} else {
|
||||||
// Show full tool call info
|
// Show full tool call info
|
||||||
toolName := messages[i].ToolCalls[0].Name
|
toolName := messages[i].ToolCall.Name
|
||||||
resp[i] = fmt.Sprintf("%s\n[yellow::i][tool call: %s][-:-:-]\nargs: %s", icon, toolName, messages[i].ToolCalls[0].Args)
|
resp[i] = fmt.Sprintf("%s\n%s\n[yellow::i][tool call: %s][-:-:-]\nargs: %s\nid: %s\n", icon, messages[i].GetText(), toolName, messages[i].ToolCall.Args, messages[i].ToolCall.ID)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
52
llm.go
52
llm.go
@@ -282,24 +282,15 @@ func (op LCPChat) FormMsg(msg, role string, resume bool) (io.Reader, error) {
|
|||||||
"content_len", len(newMsg.Content), "message_count_after_add", len(chatBody.Messages))
|
"content_len", len(newMsg.Content), "message_count_after_add", len(chatBody.Messages))
|
||||||
}
|
}
|
||||||
filteredMessages, _ := filterMessagesForCurrentCharacter(chatBody.Messages)
|
filteredMessages, _ := filterMessagesForCurrentCharacter(chatBody.Messages)
|
||||||
// Filter out tool call indicators (assistant messages with ToolCallID but empty content)
|
|
||||||
var filteredForLLM []models.RoleMsg
|
|
||||||
for i := range filteredMessages {
|
|
||||||
isToolCallIndicator := filteredMessages[i].Role != "system" && filteredMessages[i].ToolCallID != "" && filteredMessages[i].Content == "" && len(filteredMessages[i].ToolCalls) > 0
|
|
||||||
if isToolCallIndicator {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
filteredForLLM = append(filteredForLLM, filteredMessages[i])
|
|
||||||
}
|
|
||||||
// openai /v1/chat does not support custom roles; needs to be user, assistant, system
|
// openai /v1/chat does not support custom roles; needs to be user, assistant, system
|
||||||
// Add persona suffix to the last user message to indicate who the assistant should reply as
|
// Add persona suffix to the last user message to indicate who the assistant should reply as
|
||||||
bodyCopy := &models.ChatBody{
|
bodyCopy := &models.ChatBody{
|
||||||
Messages: make([]models.RoleMsg, len(filteredForLLM)),
|
Messages: make([]models.RoleMsg, len(filteredMessages)),
|
||||||
Model: chatBody.Model,
|
Model: chatBody.Model,
|
||||||
Stream: chatBody.Stream,
|
Stream: chatBody.Stream,
|
||||||
}
|
}
|
||||||
for i := range filteredForLLM {
|
for i := range filteredMessages {
|
||||||
strippedMsg := *stripThinkingFromMsg(&filteredForLLM[i])
|
strippedMsg := *stripThinkingFromMsg(&filteredMessages[i])
|
||||||
switch strippedMsg.Role {
|
switch strippedMsg.Role {
|
||||||
case cfg.UserRole:
|
case cfg.UserRole:
|
||||||
bodyCopy.Messages[i] = strippedMsg
|
bodyCopy.Messages[i] = strippedMsg
|
||||||
@@ -314,7 +305,7 @@ func (op LCPChat) FormMsg(msg, role string, resume bool) (io.Reader, error) {
|
|||||||
bodyCopy.Messages[i] = strippedMsg
|
bodyCopy.Messages[i] = strippedMsg
|
||||||
}
|
}
|
||||||
// Clear ToolCalls - they're stored in chat history for display but not sent to LLM
|
// Clear ToolCalls - they're stored in chat history for display but not sent to LLM
|
||||||
bodyCopy.Messages[i].ToolCalls = nil
|
// bodyCopy.Messages[i].ToolCall = nil
|
||||||
}
|
}
|
||||||
// Clean null/empty messages to prevent API issues
|
// Clean null/empty messages to prevent API issues
|
||||||
bodyCopy.Messages = consolidateAssistantMessages(bodyCopy.Messages)
|
bodyCopy.Messages = consolidateAssistantMessages(bodyCopy.Messages)
|
||||||
@@ -441,23 +432,14 @@ func (ds DeepSeekerChat) FormMsg(msg, role string, resume bool) (io.Reader, erro
|
|||||||
}
|
}
|
||||||
// Create copy of chat body with standardized user role
|
// Create copy of chat body with standardized user role
|
||||||
filteredMessages, _ := filterMessagesForCurrentCharacter(chatBody.Messages)
|
filteredMessages, _ := filterMessagesForCurrentCharacter(chatBody.Messages)
|
||||||
// Filter out tool call indicators (assistant messages with ToolCallID but empty content)
|
|
||||||
var filteredForLLM []models.RoleMsg
|
|
||||||
for i := range filteredMessages {
|
|
||||||
isToolCallIndicator := filteredMessages[i].Role != "system" && filteredMessages[i].ToolCallID != "" && filteredMessages[i].Content == "" && len(filteredMessages[i].ToolCalls) > 0
|
|
||||||
if isToolCallIndicator {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
filteredForLLM = append(filteredForLLM, filteredMessages[i])
|
|
||||||
}
|
|
||||||
// Add persona suffix to the last user message to indicate who the assistant should reply as
|
// Add persona suffix to the last user message to indicate who the assistant should reply as
|
||||||
bodyCopy := &models.ChatBody{
|
bodyCopy := &models.ChatBody{
|
||||||
Messages: make([]models.RoleMsg, len(filteredForLLM)),
|
Messages: make([]models.RoleMsg, len(filteredMessages)),
|
||||||
Model: chatBody.Model,
|
Model: chatBody.Model,
|
||||||
Stream: chatBody.Stream,
|
Stream: chatBody.Stream,
|
||||||
}
|
}
|
||||||
for i := range filteredForLLM {
|
for i := range filteredMessages {
|
||||||
strippedMsg := *stripThinkingFromMsg(&filteredForLLM[i])
|
strippedMsg := *stripThinkingFromMsg(&filteredMessages[i])
|
||||||
switch strippedMsg.Role {
|
switch strippedMsg.Role {
|
||||||
case cfg.UserRole:
|
case cfg.UserRole:
|
||||||
if i == 1 {
|
if i == 1 {
|
||||||
@@ -476,7 +458,7 @@ func (ds DeepSeekerChat) FormMsg(msg, role string, resume bool) (io.Reader, erro
|
|||||||
bodyCopy.Messages[i] = strippedMsg
|
bodyCopy.Messages[i] = strippedMsg
|
||||||
}
|
}
|
||||||
// Clear ToolCalls - they're stored in chat history for display but not sent to LLM
|
// Clear ToolCalls - they're stored in chat history for display but not sent to LLM
|
||||||
bodyCopy.Messages[i].ToolCalls = nil
|
// bodyCopy.Messages[i].ToolCall = nil
|
||||||
}
|
}
|
||||||
// Clean null/empty messages to prevent API issues
|
// Clean null/empty messages to prevent API issues
|
||||||
bodyCopy.Messages = consolidateAssistantMessages(bodyCopy.Messages)
|
bodyCopy.Messages = consolidateAssistantMessages(bodyCopy.Messages)
|
||||||
@@ -627,23 +609,14 @@ func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, erro
|
|||||||
}
|
}
|
||||||
// Create copy of chat body with standardized user role
|
// Create copy of chat body with standardized user role
|
||||||
filteredMessages, _ := filterMessagesForCurrentCharacter(chatBody.Messages)
|
filteredMessages, _ := filterMessagesForCurrentCharacter(chatBody.Messages)
|
||||||
// Filter out tool call indicators (assistant messages with ToolCallID but empty content)
|
|
||||||
var filteredForLLM []models.RoleMsg
|
|
||||||
for i := range filteredMessages {
|
|
||||||
isToolCallIndicator := filteredMessages[i].Role != "system" && filteredMessages[i].ToolCallID != "" && filteredMessages[i].Content == "" && len(filteredMessages[i].ToolCalls) > 0
|
|
||||||
if isToolCallIndicator {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
filteredForLLM = append(filteredForLLM, filteredMessages[i])
|
|
||||||
}
|
|
||||||
// Add persona suffix to the last user message to indicate who the assistant should reply as
|
// Add persona suffix to the last user message to indicate who the assistant should reply as
|
||||||
bodyCopy := &models.ChatBody{
|
bodyCopy := &models.ChatBody{
|
||||||
Messages: make([]models.RoleMsg, len(filteredForLLM)),
|
Messages: make([]models.RoleMsg, len(filteredMessages)),
|
||||||
Model: chatBody.Model,
|
Model: chatBody.Model,
|
||||||
Stream: chatBody.Stream,
|
Stream: chatBody.Stream,
|
||||||
}
|
}
|
||||||
for i := range filteredForLLM {
|
for i := range filteredMessages {
|
||||||
strippedMsg := *stripThinkingFromMsg(&filteredForLLM[i])
|
strippedMsg := *stripThinkingFromMsg(&filteredMessages[i])
|
||||||
switch strippedMsg.Role {
|
switch strippedMsg.Role {
|
||||||
case cfg.UserRole:
|
case cfg.UserRole:
|
||||||
bodyCopy.Messages[i] = strippedMsg
|
bodyCopy.Messages[i] = strippedMsg
|
||||||
@@ -658,7 +631,8 @@ func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, erro
|
|||||||
bodyCopy.Messages[i] = strippedMsg
|
bodyCopy.Messages[i] = strippedMsg
|
||||||
}
|
}
|
||||||
// Clear ToolCalls - they're stored in chat history for display but not sent to LLM
|
// Clear ToolCalls - they're stored in chat history for display but not sent to LLM
|
||||||
bodyCopy.Messages[i].ToolCalls = nil
|
// literally deletes data that we need
|
||||||
|
// bodyCopy.Messages[i].ToolCall = nil
|
||||||
}
|
}
|
||||||
// Clean null/empty messages to prevent API issues
|
// Clean null/empty messages to prevent API issues
|
||||||
bodyCopy.Messages = consolidateAssistantMessages(bodyCopy.Messages)
|
bodyCopy.Messages = consolidateAssistantMessages(bodyCopy.Messages)
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ type RoleMsg struct {
|
|||||||
Content string `json:"-"`
|
Content string `json:"-"`
|
||||||
ContentParts []any `json:"-"`
|
ContentParts []any `json:"-"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"` // For tool response messages
|
ToolCallID string `json:"tool_call_id,omitempty"` // For tool response messages
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // For assistant messages with tool calls
|
ToolCall *ToolCall `json:"tool_call,omitempty"` // For assistant messages with tool calls
|
||||||
IsShellCommand bool `json:"is_shell_command,omitempty"` // True for shell command outputs (always shown)
|
IsShellCommand bool `json:"is_shell_command,omitempty"` // True for shell command outputs (always shown)
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
Stats *ResponseStats `json:"stats"`
|
Stats *ResponseStats `json:"stats"`
|
||||||
@@ -119,7 +119,7 @@ func (m RoleMsg) MarshalJSON() ([]byte, error) {
|
|||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content []any `json:"content"`
|
Content []any `json:"content"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
ToolCall *ToolCall `json:"tool_call,omitempty"`
|
||||||
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
Stats *ResponseStats `json:"stats,omitempty"`
|
Stats *ResponseStats `json:"stats,omitempty"`
|
||||||
@@ -127,7 +127,7 @@ func (m RoleMsg) MarshalJSON() ([]byte, error) {
|
|||||||
Role: m.Role,
|
Role: m.Role,
|
||||||
Content: m.ContentParts,
|
Content: m.ContentParts,
|
||||||
ToolCallID: m.ToolCallID,
|
ToolCallID: m.ToolCallID,
|
||||||
ToolCalls: m.ToolCalls,
|
ToolCall: m.ToolCall,
|
||||||
IsShellCommand: m.IsShellCommand,
|
IsShellCommand: m.IsShellCommand,
|
||||||
KnownTo: m.KnownTo,
|
KnownTo: m.KnownTo,
|
||||||
Stats: m.Stats,
|
Stats: m.Stats,
|
||||||
@@ -139,7 +139,7 @@ func (m RoleMsg) MarshalJSON() ([]byte, error) {
|
|||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
ToolCall *ToolCall `json:"tool_call,omitempty"`
|
||||||
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
Stats *ResponseStats `json:"stats,omitempty"`
|
Stats *ResponseStats `json:"stats,omitempty"`
|
||||||
@@ -147,7 +147,7 @@ func (m RoleMsg) MarshalJSON() ([]byte, error) {
|
|||||||
Role: m.Role,
|
Role: m.Role,
|
||||||
Content: m.Content,
|
Content: m.Content,
|
||||||
ToolCallID: m.ToolCallID,
|
ToolCallID: m.ToolCallID,
|
||||||
ToolCalls: m.ToolCalls,
|
ToolCall: m.ToolCall,
|
||||||
IsShellCommand: m.IsShellCommand,
|
IsShellCommand: m.IsShellCommand,
|
||||||
KnownTo: m.KnownTo,
|
KnownTo: m.KnownTo,
|
||||||
Stats: m.Stats,
|
Stats: m.Stats,
|
||||||
@@ -163,7 +163,7 @@ func (m *RoleMsg) UnmarshalJSON(data []byte) error {
|
|||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content []any `json:"content"`
|
Content []any `json:"content"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
ToolCall *ToolCall `json:"tool_call,omitempty"`
|
||||||
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
Stats *ResponseStats `json:"stats,omitempty"`
|
Stats *ResponseStats `json:"stats,omitempty"`
|
||||||
@@ -172,7 +172,7 @@ func (m *RoleMsg) UnmarshalJSON(data []byte) error {
|
|||||||
m.Role = structured.Role
|
m.Role = structured.Role
|
||||||
m.ContentParts = structured.Content
|
m.ContentParts = structured.Content
|
||||||
m.ToolCallID = structured.ToolCallID
|
m.ToolCallID = structured.ToolCallID
|
||||||
m.ToolCalls = structured.ToolCalls
|
m.ToolCall = structured.ToolCall
|
||||||
m.IsShellCommand = structured.IsShellCommand
|
m.IsShellCommand = structured.IsShellCommand
|
||||||
m.KnownTo = structured.KnownTo
|
m.KnownTo = structured.KnownTo
|
||||||
m.Stats = structured.Stats
|
m.Stats = structured.Stats
|
||||||
@@ -185,7 +185,7 @@ func (m *RoleMsg) UnmarshalJSON(data []byte) error {
|
|||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
ToolCall *ToolCall `json:"tool_call,omitempty"`
|
||||||
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
IsShellCommand bool `json:"is_shell_command,omitempty"`
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
Stats *ResponseStats `json:"stats,omitempty"`
|
Stats *ResponseStats `json:"stats,omitempty"`
|
||||||
@@ -196,7 +196,7 @@ func (m *RoleMsg) UnmarshalJSON(data []byte) error {
|
|||||||
m.Role = simple.Role
|
m.Role = simple.Role
|
||||||
m.Content = simple.Content
|
m.Content = simple.Content
|
||||||
m.ToolCallID = simple.ToolCallID
|
m.ToolCallID = simple.ToolCallID
|
||||||
m.ToolCalls = simple.ToolCalls
|
m.ToolCall = simple.ToolCall
|
||||||
m.IsShellCommand = simple.IsShellCommand
|
m.IsShellCommand = simple.IsShellCommand
|
||||||
m.KnownTo = simple.KnownTo
|
m.KnownTo = simple.KnownTo
|
||||||
m.Stats = simple.Stats
|
m.Stats = simple.Stats
|
||||||
|
|||||||
Reference in New Issue
Block a user