Skip to content

Commit

Permalink
Evaluate function names in chat templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Feb 16, 2024
1 parent 496374a commit 2510451
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/openai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@ func ChatEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx)
}
r := config.Roles[role]
contentExists := i.Content != nil && i.StringContent != ""

// First attempt to populate content via a chat message specific template
if config.TemplateConfig.ChatMessage != "" {
chatMessageData := model.ChatMessageTemplateData{
SystemPrompt: config.SystemPrompt,
Role: r,
RoleName: role,
Content: i.StringContent,
FunctionName: i.Name,
MessageIndex: messageIndex,
}
templatedChatMessage, err := o.Loader.EvaluateTemplateForChatMessage(config.TemplateConfig.ChatMessage, chatMessageData)
Expand Down
4 changes: 4 additions & 0 deletions api/schema/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type ContentURL struct {
type Message struct {
// The message role
Role string `json:"role,omitempty" yaml:"role"`

// The message name (used for tools calls)
Name string `json:"name,omitempty" yaml:"name"`

// The message content
Content interface{} `json:"content" yaml:"content"`

Expand Down
1 change: 1 addition & 0 deletions pkg/model/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ChatMessageTemplateData struct {
SystemPrompt string
Role string
RoleName string
FunctionName string
Content string
MessageIndex int
}
Expand Down

0 comments on commit 2510451

Please sign in to comment.