feat: use -r, --raw: Use defaults of model (don't send temperature etc.) and use the user role instead of the system role.
This commit is contained in:
parent
329c843567
commit
147da29c1a
@ -23,7 +23,7 @@ type Flags struct {
|
||||
TopP float64 `short:"T" long:"topp" description:"Set top P" default:"0.9"`
|
||||
Stream bool `short:"s" long:"stream" description:"Stream"`
|
||||
PresencePenalty float64 `short:"P" long:"presencepenalty" description:"Set presence penalty" default:"0.0"`
|
||||
UserInsteadOfSystemRole bool `short:"u" long:"user-instead-of-system" description:"Use the user role instead of the system role for the pattern"`
|
||||
Raw bool `short:"r" long:"raw" description:"Use the defaults of the model without sending chat options (like temperature etc.) and use the user role instead of the system role for patterns."`
|
||||
FrequencyPenalty float64 `short:"F" long:"frequencypenalty" description:"Set frequency penalty" default:"0.0"`
|
||||
ListPatterns bool `short:"l" long:"listpatterns" description:"List all patterns"`
|
||||
ListAllModels bool `short:"L" long:"listmodels" description:"List all available models"`
|
||||
@ -94,7 +94,7 @@ func (o *Flags) BuildChatOptions() (ret *common.ChatOptions) {
|
||||
TopP: o.TopP,
|
||||
PresencePenalty: o.PresencePenalty,
|
||||
FrequencyPenalty: o.FrequencyPenalty,
|
||||
UserInsteadOfSystemRole: o.UserInsteadOfSystemRole,
|
||||
Raw: o.Raw,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func TestBuildChatOptions(t *testing.T) {
|
||||
TopP: 0.9,
|
||||
PresencePenalty: 0.1,
|
||||
FrequencyPenalty: 0.2,
|
||||
UserInsteadOfSystemRole: false,
|
||||
Raw: false,
|
||||
}
|
||||
options := flags.BuildChatOptions()
|
||||
assert.Equal(t, expectedOptions, options)
|
||||
|
@ -21,7 +21,7 @@ type ChatOptions struct {
|
||||
TopP float64
|
||||
PresencePenalty float64
|
||||
FrequencyPenalty float64
|
||||
UserInsteadOfSystemRole bool
|
||||
Raw bool
|
||||
}
|
||||
|
||||
// NormalizeMessages remove empty messages and ensure messages order user-assist-user
|
||||
|
@ -26,7 +26,7 @@ func (o *Chatter) Send(request *common.ChatRequest, opts *common.ChatOptions) (m
|
||||
}
|
||||
|
||||
var session *db.Session
|
||||
if session, err = chatRequest.BuildChatSession(opts.UserInsteadOfSystemRole); err != nil {
|
||||
if session, err = chatRequest.BuildChatSession(opts.Raw); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ func (o *Fabric) CreateOutputFile(message string, fileName string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (o *Chat) BuildChatSession(userInsteadOfSystemRole bool) (ret *db.Session, err error) {
|
||||
func (o *Chat) BuildChatSession(raw bool) (ret *db.Session, err error) {
|
||||
// new messages will be appended to the session and used to send the message
|
||||
if o.Session != nil {
|
||||
ret = o.Session
|
||||
@ -248,7 +248,8 @@ func (o *Chat) BuildChatSession(userInsteadOfSystemRole bool) (ret *db.Session,
|
||||
systemMessage := strings.TrimSpace(o.Context) + strings.TrimSpace(o.Pattern)
|
||||
userMessage := strings.TrimSpace(o.Message)
|
||||
|
||||
if userInsteadOfSystemRole {
|
||||
if raw {
|
||||
// use the user role instead of the system role in raw mode
|
||||
message := systemMessage + userMessage
|
||||
if message != "" {
|
||||
ret.Append(&common.Message{Role: goopenai.ChatMessageRoleUser, Content: message})
|
||||
|
7
vendors/openai/openai.go
vendored
7
vendors/openai/openai.go
vendored
@ -114,6 +114,12 @@ func (o *Client) buildChatCompletionRequest(
|
||||
return goopenai.ChatCompletionMessage{Role: message.Role, Content: message.Content}
|
||||
})
|
||||
|
||||
if opts.Raw {
|
||||
ret = goopenai.ChatCompletionRequest{
|
||||
Model: opts.Model,
|
||||
Messages: messages,
|
||||
}
|
||||
} else {
|
||||
ret = goopenai.ChatCompletionRequest{
|
||||
Model: opts.Model,
|
||||
Temperature: float32(opts.Temperature),
|
||||
@ -122,5 +128,6 @@ func (o *Client) buildChatCompletionRequest(
|
||||
FrequencyPenalty: float32(opts.FrequencyPenalty),
|
||||
Messages: messages,
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user