-
Notifications
You must be signed in to change notification settings - Fork 250
Merge Openai api version route to main #1021
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e139ad9
Add OPENAI_API_VERSION constant to routes
vmpuri 3d702af
Add seed, temperature, max_tokens and system_fingerprint paramters t…
vmpuri d1a0da8
Merge branch 'main' into openai_api_version_route
vmpuri 716485c
Merge branch 'main' into openai_api_version_route
vmpuri 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
See https://platform.openai.com/docs/api-reference/chat for the full specification and details. | ||
""" | ||
|
||
OPENAI_API_DEFAULT_MAX_TOKENS = 16 | ||
|
||
# Message classes and associated objects - see the types of Messages under "Create Chat Completion >>> Request body >>> messages" | ||
|
||
|
||
|
@@ -105,20 +107,20 @@ class CompletionRequest: | |
logit_bias: Optional[Dict[str, float]] = None # unimplemented | ||
logprobs: Optional[bool] = None # unimplemented | ||
top_logprobs: Optional[int] = None # unimplemented | ||
max_tokens: Optional[int] = None # unimplemented | ||
max_tokens: Optional[int] = None | ||
n: int = 1 | ||
presence_penalty: float = 0 # unimplemented | ||
response_format: Optional[ResponseFormat] = None # unimplemented | ||
seed: Optional[int] = None # unimplemented | ||
seed: Optional[int] = None | ||
service_tier: Optional[str] = None # unimplemented | ||
stop: Optional[List[str]] = None # unimplemented | ||
stream: bool = False | ||
stream_options: Optional[StreamOptions] = None # unimplemented | ||
temperature: Optional[float] = 1.0 # unimplemented | ||
temperature: Optional[float] = 1.0 | ||
top_p: Optional[float] = 1.0 # unimplemented | ||
tools: Optional[List[Any]] = None # unimplemented | ||
tool_choice: Optional[Union[str, Any]] = None # unimplemented | ||
parallel_tool_calls: Optional[bool] = None # unimplemented | ||
tools: Optional[List[Any]] = None # unimplemented - Assistant features | ||
tool_choice: Optional[Union[str, Any]] = None # unimplemented - Assistant features | ||
parallel_tool_calls: Optional[bool] = None # unimplemented - Assistant features | ||
user: Optional[str] = None # unimplemented | ||
|
||
|
||
|
@@ -229,9 +231,8 @@ def __init__(self, *args, **kwargs): | |
else self.model.config.max_seq_length | ||
) | ||
# The System fingerprint is a unique identifier for the model and its configuration. | ||
# Currently, this is not implemented in a | ||
self.system_fingerprint = ( | ||
self.builder_args.device + type(self.builder_args.precision).__name__ | ||
f"{self.builder_args.device}_{self.builder_args.precision}" | ||
) | ||
|
||
def chunked_completion(self, completion_request: CompletionRequest): | ||
|
@@ -270,7 +271,13 @@ def chunked_completion(self, completion_request: CompletionRequest): | |
) | ||
generator_args = GeneratorArgs( | ||
completion_request.messages[-1].get("content"), | ||
max_new_tokens=( | ||
int(completion_request.max_tokens) | ||
if completion_request.max_tokens | ||
else OPENAI_API_DEFAULT_MAX_TOKENS | ||
), | ||
encoded_prompt=encoded, | ||
temperature=float(completion_request.temperature), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous re: typecasting for dataclasses. |
||
chat_mode=False, | ||
) | ||
|
||
|
@@ -295,6 +302,7 @@ def callback(x, *, done_generating=False): | |
sequential_prefill=generator_args.sequential_prefill, | ||
start_pos=self.start_pos, | ||
max_seq_length=self.max_seq_length, | ||
seed=int(completion_request.seed), | ||
): | ||
if y is None: | ||
continue | ||
|
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
Oops, something went wrong.
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.
why cast?
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.
The request object was being populated from JSON, which automatically means the value for every field is str despite the dataclass type hints.
These casts were to get things working, but yes - this is a bad solution and we should have better type enforcement here (and possibly repo-wide)
Based on what I can find, we can resolve this by casting the types at the object's init time for each field (kinda tedious) or by using something like pydantic (yet another package to manage).
Should we attack this in another issue/PR or try to resolve it here?
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.
Casting at init time makes sense, since downstream users shouldn't need to think about it
We can make it a separate PR or push the casting to init just for max_tokens and temperature
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.
Created #1025 to track this, will merge this PR for now.