feat: add support for pattern variables
This commit is contained in:
parent
a921b77f5a
commit
d6552f5811
60
cli/flags.go
60
cli/flags.go
@ -13,31 +13,32 @@ import (
|
|||||||
|
|
||||||
// Flags create flags struct. the users flags go into this, this will be passed to the chat struct in cli
|
// Flags create flags struct. the users flags go into this, this will be passed to the chat struct in cli
|
||||||
type Flags struct {
|
type Flags struct {
|
||||||
Pattern string `short:"p" long:"pattern" description:"Choose a pattern" default:""`
|
Pattern string `short:"p" long:"pattern" description:"Choose a pattern" default:""`
|
||||||
Context string `short:"C" long:"context" description:"Choose a context" default:""`
|
PatternVariables map[string]string `short:"v" long:"variable" description:"Values for pattern variables"`
|
||||||
Session string `long:"session" description:"Choose a session"`
|
Context string `short:"C" long:"context" description:"Choose a context" default:""`
|
||||||
Setup bool `short:"S" long:"setup" description:"Run setup"`
|
Session string `long:"session" description:"Choose a session"`
|
||||||
SetupSkipUpdatePatterns bool `long:"setup-skip-update-patterns" description:"Skip update patterns at setup"`
|
Setup bool `short:"S" long:"setup" description:"Run setup"`
|
||||||
Temperature float64 `short:"t" long:"temperature" description:"Set temperature" default:"0.7"`
|
SetupSkipUpdatePatterns bool `long:"setup-skip-update-patterns" description:"Skip update patterns at setup"`
|
||||||
TopP float64 `short:"T" long:"topp" description:"Set top P" default:"0.9"`
|
Temperature float64 `short:"t" long:"temperature" description:"Set temperature" default:"0.7"`
|
||||||
Stream bool `short:"s" long:"stream" description:"Stream"`
|
TopP float64 `short:"T" long:"topp" description:"Set top P" default:"0.9"`
|
||||||
PresencePenalty float64 `short:"P" long:"presencepenalty" description:"Set presence penalty" default:"0.0"`
|
Stream bool `short:"s" long:"stream" description:"Stream"`
|
||||||
FrequencyPenalty float64 `short:"F" long:"frequencypenalty" description:"Set frequency penalty" default:"0.0"`
|
PresencePenalty float64 `short:"P" long:"presencepenalty" description:"Set presence penalty" default:"0.0"`
|
||||||
ListPatterns bool `short:"l" long:"listpatterns" description:"List all patterns"`
|
FrequencyPenalty float64 `short:"F" long:"frequencypenalty" description:"Set frequency penalty" default:"0.0"`
|
||||||
ListAllModels bool `short:"L" long:"listmodels" description:"List all available models"`
|
ListPatterns bool `short:"l" long:"listpatterns" description:"List all patterns"`
|
||||||
ListAllContexts bool `short:"x" long:"listcontexts" description:"List all contexts"`
|
ListAllModels bool `short:"L" long:"listmodels" description:"List all available models"`
|
||||||
ListAllSessions bool `short:"X" long:"listsessions" description:"List all sessions"`
|
ListAllContexts bool `short:"x" long:"listcontexts" description:"List all contexts"`
|
||||||
UpdatePatterns bool `short:"U" long:"updatepatterns" description:"Update patterns"`
|
ListAllSessions bool `short:"X" long:"listsessions" description:"List all sessions"`
|
||||||
Message string `hidden:"true" description:"Message to send to chat"`
|
UpdatePatterns bool `short:"U" long:"updatepatterns" description:"Update patterns"`
|
||||||
Copy bool `short:"c" long:"copy" description:"Copy to clipboard"`
|
Message string `hidden:"true" description:"Message to send to chat"`
|
||||||
Model string `short:"m" long:"model" description:"Choose model"`
|
Copy bool `short:"c" long:"copy" description:"Copy to clipboard"`
|
||||||
Output string `short:"o" long:"output" description:"Output to file" default:""`
|
Model string `short:"m" long:"model" description:"Choose model"`
|
||||||
LatestPatterns string `short:"n" long:"latest" description:"Number of latest patterns to list" default:"0"`
|
Output string `short:"o" long:"output" description:"Output to file" default:""`
|
||||||
ChangeDefaultModel bool `short:"d" long:"changeDefaultModel" description:"Change default pattern"`
|
LatestPatterns string `short:"n" long:"latest" description:"Number of latest patterns to list" default:"0"`
|
||||||
YouTube string `short:"y" long:"youtube" description:"YouTube video url to grab transcript, comments from it and send to chat"`
|
ChangeDefaultModel bool `short:"d" long:"changeDefaultModel" description:"Change default pattern"`
|
||||||
YouTubeTranscript bool `long:"transcript" description:"Grab transcript from YouTube video and send to chat"`
|
YouTube string `short:"y" long:"youtube" description:"YouTube video url to grab transcript, comments from it and send to chat"`
|
||||||
YouTubeComments bool `long:"comments" description:"Grab comments from YouTube video and send to chat"`
|
YouTubeTranscript bool `long:"transcript" description:"Grab transcript from YouTube video and send to chat"`
|
||||||
DryRun bool `long:"dry-run" description:"Show what would be sent to the model without actually sending it"`
|
YouTubeComments bool `long:"comments" description:"Grab comments from YouTube video and send to chat"`
|
||||||
|
DryRun bool `long:"dry-run" description:"Show what would be sent to the model without actually sending it"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Initialize flags. returns a Flags struct and an error
|
// Init Initialize flags. returns a Flags struct and an error
|
||||||
@ -98,10 +99,11 @@ func (o *Flags) BuildChatOptions() (ret *common.ChatOptions) {
|
|||||||
|
|
||||||
func (o *Flags) BuildChatRequest() (ret *common.ChatRequest) {
|
func (o *Flags) BuildChatRequest() (ret *common.ChatRequest) {
|
||||||
ret = &common.ChatRequest{
|
ret = &common.ChatRequest{
|
||||||
ContextName: o.Context,
|
ContextName: o.Context,
|
||||||
SessionName: o.Session,
|
SessionName: o.Session,
|
||||||
PatternName: o.Pattern,
|
PatternName: o.Pattern,
|
||||||
Message: o.Message,
|
PatternVariables: o.PatternVariables,
|
||||||
|
Message: o.Message,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,11 @@ type Message struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChatRequest struct {
|
type ChatRequest struct {
|
||||||
ContextName string
|
ContextName string
|
||||||
SessionName string
|
SessionName string
|
||||||
PatternName string
|
PatternName string
|
||||||
Message string
|
PatternVariables map[string]string
|
||||||
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatOptions struct {
|
type ChatOptions struct {
|
||||||
|
@ -82,7 +82,7 @@ func (o *Chatter) NewChat(request *common.ChatRequest) (ret *Chat, err error) {
|
|||||||
|
|
||||||
if request.PatternName != "" {
|
if request.PatternName != "" {
|
||||||
var pattern *db.Pattern
|
var pattern *db.Pattern
|
||||||
if pattern, err = o.db.Patterns.GetPattern(request.PatternName); err != nil {
|
if pattern, err = o.db.Patterns.GetPattern(request.PatternName, request.PatternVariables); err != nil {
|
||||||
err = fmt.Errorf("could not find pattern %s: %v", request.PatternName, err)
|
err = fmt.Errorf("could not find pattern %s: %v", request.PatternName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,25 @@ type Patterns struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPattern finds a pattern by name and returns the pattern as an entry or an error
|
// GetPattern finds a pattern by name and returns the pattern as an entry or an error
|
||||||
func (o *Patterns) GetPattern(name string) (ret *Pattern, err error) {
|
func (o *Patterns) GetPattern(name string, variables map[string]string) (ret *Pattern, err error) {
|
||||||
patternPath := filepath.Join(o.Dir, name, o.SystemPatternFile)
|
patternPath := filepath.Join(o.Dir, name, o.SystemPatternFile)
|
||||||
|
|
||||||
var pattern []byte
|
var pattern []byte
|
||||||
if pattern, err = os.ReadFile(patternPath); err != nil {
|
if pattern, err = os.ReadFile(patternPath); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patternStr := string(pattern)
|
||||||
|
|
||||||
|
if variables != nil && len(variables) > 0 {
|
||||||
|
for variableName, value := range variables {
|
||||||
|
patternStr = strings.ReplaceAll(patternStr, variableName, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = &Pattern{
|
ret = &Pattern{
|
||||||
Name: name,
|
Name: name,
|
||||||
Pattern: string(pattern),
|
Pattern: patternStr,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user