Skip to content

Commit

Permalink
prompt: Rename SetLimit to SetInputN (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan authored Apr 1, 2024
1 parent 7e58417 commit 237104e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Prompt struct {
prompt string
t *template.Template
ex *Example
limit int
n int

d time.Duration
workers int
Expand All @@ -69,8 +69,8 @@ func (prompt *Prompt) SetExample(ex Example) *Prompt {
return prompt
}

func (prompt *Prompt) SetLimit(limit int) *Prompt {
prompt.limit = limit
func (prompt *Prompt) SetInputN(n int) *Prompt {
prompt.n = n
return prompt
}

Expand All @@ -89,16 +89,16 @@ func (prompt *Prompt) execute(input []string, prefix string) (prompts []string,
if length == 0 {
return
}
limit := prompt.limit
if limit == 0 {
limit = length
n := prompt.n
if n == 0 {
n = length
}
for n := 0; n < length; n = n + limit {
for i := 0; i < length; i = i + n {
var s []string
if n+limit < length {
s = input[n : n+limit]
if i+n < length {
s = input[i : i+n]
} else {
s = input[n:]
s = input[i:]
}
var b strings.Builder
if err = prompt.t.Execute(&b, struct {
Expand All @@ -107,7 +107,7 @@ func (prompt *Prompt) execute(input []string, prefix string) (prompts []string,
Input []string
Prefix string
Start int
}{prompt.prompt, prompt.ex, s, prefix, n}); err != nil {
}{prompt.prompt, prompt.ex, s, prefix, i}); err != nil {
return nil, err
}
prompts = append(prompts, b.String())
Expand Down
2 changes: 1 addition & 1 deletion prompt/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestPrompt(t *testing.T) {
[]string{"no example multiple inputs with fixed prefix\nInput:\"\"\"\ntest|test1\ntest|test2\n\"\"\"\nOutput:"},
},
{
New("test limit").SetExample(Example{[]string{"abc", "def"}, "example"}).SetLimit(2),
New("test limit").SetExample(Example{[]string{"abc", "def"}, "example"}).SetInputN(2),
[]string{"test1", "test2", "test3", "test4"},
"%d|",
[]string{
Expand Down

0 comments on commit 237104e

Please sign in to comment.