You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: generate response length based on a histogram when max_tokens is defined in the request (#169)
* when request contains max tokens, calculate length on the response based on a histogram - intial implementation
Signed-off-by: Maya Barnea <[email protected]>
* - in case max_tokens is defined in the request, finish reason will not be randomly selected, instead it will be stop when response length is maxTokens, otherwise - stop
- fix utils_tests
Signed-off-by: Maya Barnea <[email protected]>
* rename variables + fix problem by PR comment
Signed-off-by: Maya Barnea <[email protected]>
* add more explanations to getResponseLengthByHistogram
Signed-off-by: Maya Barnea <[email protected]>
* fix misspelling
Signed-off-by: Maya Barnea <[email protected]>
* fixes in comments
Signed-off-by: Maya Barnea <[email protected]>
---------
Signed-off-by: Maya Barnea <[email protected]>
// if response should be create with maximum number of tokens - finish reason will be 'length'
176
+
finishReason=LengthFinishReason
177
+
}
159
178
}
160
179
161
180
text:=GetRandomText(numOfTokens)
162
181
returntext, finishReason
163
182
}
164
183
184
+
// getResponseLengthByHistogram calculates the number of tokens to be returned in a response based on the max tokens value and the pre-defined buckets.
185
+
// The response length is distributed according to the probabilities, defined in respLenBucketsProbabilities.
186
+
// The histogram contains equally sized buckets and the last special bucket, which contains only the maxTokens value.
187
+
// The last element of respLenBucketsProbabilities defines the probability of a reposnse with maxToken tokens.
188
+
// Other values define probabilities for the equally sized buckets.
189
+
// If maxToken is small (smaller than number of buckets) - the response length is randomly selected from the range [1, maxTokens]
190
+
funcgetResponseLengthByHistogram(maxTokensint) int {
191
+
ifmaxTokens<=1 {
192
+
returnmaxTokens
193
+
}
194
+
// maxTokens is small - no need to use the histogram of probabilities, just select a random value in the range [1, maxTokens]
0 commit comments