Skip to content

Commit

Permalink
fix: treat config key "role" as optional (#255)
Browse files Browse the repository at this point in the history
Fixes: ef910e7 ("fix: handle non-existent role (#244)")

Signed-off-by: Marcello Sylvester Bauer <[email protected]>
  • Loading branch information
sylv-io authored May 6, 2024
1 parent dd0cb49 commit 9527de3
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,25 +370,27 @@ func (m *Mods) startCompletionCmd(content string) tea.Cmd {
})
}

roleSetup, ok := cfg.Roles[cfg.Role]
if !ok {
return modsError{
err: fmt.Errorf("role %q does not exist", cfg.Role),
reason: "Could not use role",
}
}
for _, msg := range roleSetup {
content, err := loadMsg(msg)
if err != nil {
if cfg.Role != "" {
roleSetup, ok := cfg.Roles[cfg.Role]
if !ok {
return modsError{
err: err,
err: fmt.Errorf("role %q does not exist", cfg.Role),
reason: "Could not use role",
}
}
m.messages = append(m.messages, openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleSystem,
Content: content,
})
for _, msg := range roleSetup {
content, err := loadMsg(msg)
if err != nil {
return modsError{
err: err,
reason: "Could not use role",
}
}
m.messages = append(m.messages, openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleSystem,
Content: content,
})
}
}

if prefix := cfg.Prefix; prefix != "" {
Expand Down

0 comments on commit 9527de3

Please sign in to comment.