mirror of
https://github.com/ollama/ollama.git
synced 2025-11-11 20:17:33 +01:00
Add Tool Call ID (#12956)
* routes/types: add tool call id --------- Co-authored-by: ParthSareen <parth.sareen@ollama.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
@@ -1812,6 +1813,15 @@ func (s *Server) PsHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, api.ProcessResponse{Models: models})
|
||||
}
|
||||
|
||||
func toolCallId() string {
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
b := make([]byte, 8)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return "call_" + strings.ToLower(string(b))
|
||||
}
|
||||
|
||||
func (s *Server) ChatHandler(c *gin.Context) {
|
||||
checkpointStart := time.Now()
|
||||
|
||||
@@ -2130,6 +2140,9 @@ func (s *Server) ChatHandler(c *gin.Context) {
|
||||
|
||||
res.Message.Content = content
|
||||
res.Message.Thinking = thinking
|
||||
for i := range toolCalls {
|
||||
toolCalls[i].ID = toolCallId()
|
||||
}
|
||||
res.Message.ToolCalls = toolCalls
|
||||
|
||||
tb.WriteString(thinking)
|
||||
@@ -2174,6 +2187,9 @@ func (s *Server) ChatHandler(c *gin.Context) {
|
||||
if len(content) > 0 {
|
||||
res.Message.Content = content
|
||||
} else if len(toolCalls) > 0 {
|
||||
for i := range toolCalls {
|
||||
toolCalls[i].ID = toolCallId()
|
||||
}
|
||||
res.Message.ToolCalls = toolCalls
|
||||
res.Message.Content = ""
|
||||
} else if res.Message.Thinking != "" {
|
||||
|
||||
Reference in New Issue
Block a user