Skip to content

Commit f753669

Browse files
committed
fix
1 parent 176f1e1 commit f753669

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

aichat.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,12 @@ func (aiChat *AIChat) fold(prompt *Prompt, input string) error {
134134
if err != nil {
135135
return err
136136
}
137+
idx := firstAllowedTokens
138+
for idx > len(encoded) {
139+
idx = len(encoded)
140+
}
137141

138-
firstEncoded := encoded[:firstAllowedTokens]
142+
firstEncoded := encoded[:idx]
139143
firstInput := aiChat.encoder.Decode(firstEncoded)
140144
temperature := firstNonZeroFloat32(aiChat.options.temperature, prompt.Temperature)
141145
firstRequest := gogpt.ChatCompletionRequest{
@@ -154,15 +158,14 @@ func (aiChat *AIChat) fold(prompt *Prompt, input string) error {
154158
return fmt.Errorf("no choices returned")
155159
}
156160
output := response.Choices[0].Message.Content
157-
if firstAllowedTokens >= len(encoded) {
161+
if idx >= len(encoded) {
158162
fmt.Println(output)
159163
return nil
160164
}
161165
if aiChat.options.verbose {
162166
log.Printf("first output: %s", output)
163167
}
164168

165-
idx := firstAllowedTokens
166169
for idx < len(encoded) {
167170
outputTokens, err := aiChat.encoder.Encode(output)
168171
if err != nil {

0 commit comments

Comments
 (0)