Enable index tracking for tools - openai api support (#7888)

This commit is contained in:
Parth Sareen 2024-11-29 20:00:09 -08:00 committed by GitHub
parent 39e29ae5dd
commit 5f8051180e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 89 additions and 4 deletions

View file

@ -1469,7 +1469,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
go func() {
defer close(ch)
var sb strings.Builder
var hasToolCalls bool
var toolCallIndex int = 0
if err := r.Completion(c.Request.Context(), llm.CompletionRequest{
Prompt: prompt,
Images: images,
@ -1509,16 +1509,19 @@ func (s *Server) ChatHandler(c *gin.Context) {
sb.WriteString(r.Content)
if toolCalls, ok := m.parseToolCalls(sb.String()); ok {
res.Message.ToolCalls = toolCalls
for i := range toolCalls {
toolCalls[i].Function.Index = toolCallIndex
toolCallIndex++
}
res.Message.Content = ""
sb.Reset()
hasToolCalls = true
ch <- res
return
}
if r.Done {
// Send any remaining content if no tool calls were detected
if !hasToolCalls {
if toolCallIndex == 0 {
res.Message.Content = sb.String()
}
ch <- res