-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add max-model-len configuration and validation for context window (#82) #85
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72710e1
feat: add max-model-len configuration and validation for context wind…
mohitpalsingh 39bb7a7
refactor: remove redundant check for max model length in validateCont…
mohitpalsingh 9e95645
Merge branch 'main' into main
mohitpalsingh cba24c5
fix: correct indentation for test entry in simulator configuration tests
mohitpalsingh ae380e0
test: add additional test case for simulator configuration
mohitpalsingh 5bbb302
fix: static lint check errors
mohitpalsingh 72ab4ba
fix: update error message capitalization in validateContextWindow
mohitpalsingh 70b08d5
fix: update error message capitalization in validateContextWindow
mohitpalsingh e1b93cd
fix: refactored context window validation func with detailed error me…
mohitpalsingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,54 @@ var _ = Describe("Utils", func() { | |
Expect(finishReason).Should(Equal(stopFinishReason)) | ||
}) | ||
}) | ||
|
||
Context("validateContextWindow", func() { | ||
It("should pass when total tokens are within limit", func() { | ||
promptTokens := 100 | ||
maxCompletionTokens := int64(50) | ||
maxModelLen := 200 | ||
|
||
err := validateContextWindow(promptTokens, &maxCompletionTokens, maxModelLen) | ||
Expect(err).Should(BeNil()) | ||
}) | ||
|
||
It("should fail when total tokens exceed limit", func() { | ||
promptTokens := 150 | ||
maxCompletionTokens := int64(100) | ||
maxModelLen := 200 | ||
|
||
err := validateContextWindow(promptTokens, &maxCompletionTokens, maxModelLen) | ||
Expect(err).ShouldNot(BeNil()) | ||
Expect(err.Error()).Should(ContainSubstring("This model's maximum context length is 200 tokens")) | ||
Expect(err.Error()).Should(ContainSubstring("However, you requested 250 tokens")) | ||
Expect(err.Error()).Should(ContainSubstring("150 in the messages, 100 in the completion")) | ||
}) | ||
|
||
It("should pass when no max model length is configured", func() { | ||
promptTokens := 1000 | ||
maxCompletionTokens := int64(1000) | ||
maxModelLen := 0 | ||
|
||
|
||
err := validateContextWindow(promptTokens, &maxCompletionTokens, maxModelLen) | ||
Expect(err).Should(BeNil()) | ||
}) | ||
|
||
It("should handle nil max completion tokens", func() { | ||
promptTokens := 100 | ||
maxModelLen := 200 | ||
|
||
err := validateContextWindow(promptTokens, nil, maxModelLen) | ||
Expect(err).Should(BeNil()) | ||
}) | ||
|
||
It("should fail when only prompt tokens exceed limit", func() { | ||
promptTokens := 250 | ||
maxModelLen := 200 | ||
|
||
err := validateContextWindow(promptTokens, nil, maxModelLen) | ||
Expect(err).ShouldNot(BeNil()) | ||
Expect(err.Error()).Should(ContainSubstring("This model's maximum context length is 200 tokens")) | ||
Expect(err.Error()).Should(ContainSubstring("However, you requested 250 tokens")) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that maxModelLen is <= 0? You added a check in configuration validate()
if c.MaxModelLen < 1 { return errors.New("max model len cannot be less than 1") }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @irar2 , you're right. This is redundant. Removing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Can you please check now?