Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt: Rename SetLimit to SetInputN #31

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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