Enha: catching tool call id
This commit is contained in:
7
bot.go
7
bot.go
@@ -629,6 +629,13 @@ func findCall(msg, toolCall string, tv *tview.TextView) {
|
|||||||
}
|
}
|
||||||
lastToolCall.Args = openAIToolMap
|
lastToolCall.Args = openAIToolMap
|
||||||
fc = lastToolCall
|
fc = lastToolCall
|
||||||
|
// Ensure lastToolCallID is set if it's available in the tool call
|
||||||
|
if lastToolCallID == "" && len(openAIToolMap) > 0 {
|
||||||
|
// Attempt to extract ID from the parsed tool call if not already set
|
||||||
|
if id, exists := openAIToolMap["id"]; exists {
|
||||||
|
lastToolCallID = id
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
jsStr := toolCallRE.FindString(msg)
|
jsStr := toolCallRE.FindString(msg)
|
||||||
if jsStr == "" {
|
if jsStr == "" {
|
||||||
|
|||||||
17
llm.go
17
llm.go
@@ -186,11 +186,21 @@ func (op LCPChat) ParseChunk(data []byte) (*models.TextChunk, error) {
|
|||||||
logger.Error("failed to decode", "error", err, "line", string(data))
|
logger.Error("failed to decode", "error", err, "line", string(data))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle multiple choices safely
|
||||||
|
if len(llmchunk.Choices) == 0 {
|
||||||
|
logger.Warn("LCPChat ParseChunk: no choices in response", "data", string(data))
|
||||||
|
return &models.TextChunk{Finished: true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
resp := &models.TextChunk{
|
resp := &models.TextChunk{
|
||||||
Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content,
|
Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content,
|
||||||
}
|
}
|
||||||
if len(llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls) > 0 {
|
|
||||||
toolCall := llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0]
|
// Check for tool calls in all choices, not just the last one
|
||||||
|
for _, choice := range llmchunk.Choices {
|
||||||
|
if len(choice.Delta.ToolCalls) > 0 {
|
||||||
|
toolCall := choice.Delta.ToolCalls[0]
|
||||||
resp.ToolChunk = toolCall.Function.Arguments
|
resp.ToolChunk = toolCall.Function.Arguments
|
||||||
fname := toolCall.Function.Name
|
fname := toolCall.Function.Name
|
||||||
if fname != "" {
|
if fname != "" {
|
||||||
@@ -198,7 +208,10 @@ func (op LCPChat) ParseChunk(data []byte) (*models.TextChunk, error) {
|
|||||||
}
|
}
|
||||||
// Capture the tool call ID if available
|
// Capture the tool call ID if available
|
||||||
resp.ToolID = toolCall.ID
|
resp.ToolID = toolCall.ID
|
||||||
|
break // Process only the first tool call
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" {
|
if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" {
|
||||||
if resp.Chunk != "" {
|
if resp.Chunk != "" {
|
||||||
logger.Error("text inside of finish llmchunk", "chunk", llmchunk)
|
logger.Error("text inside of finish llmchunk", "chunk", llmchunk)
|
||||||
|
|||||||
Reference in New Issue
Block a user