Skip to content

Commit

Permalink
Merge pull request #93 from Aleph-Alpha/add-raw-completion-parameter
Browse files Browse the repository at this point in the history
Add raw_completion to completion request
  • Loading branch information
volkerstampa authored Feb 17, 2023
2 parents 0c7b89a + 32a991d commit fd03271
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aleph_alpha_client/aleph_alpha_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def complete(
contextual_control_threshold: Optional[float] = None,
control_log_additive: Optional[bool] = True,
repetition_penalties_include_completion: bool = True,
raw_completion: bool = False,
):
"""Generates samples from a prompt.
Expand Down Expand Up @@ -425,6 +426,12 @@ def complete(
repetition_penalties_include_completion (bool, optional, default True)
Flag deciding whether presence penalty or frequency penalty are updated from the completion
raw_completion (bool, default False)
Setting this parameter to true forces the raw completion of the model to be returned.
For some models, we may optimize the completion that was generated by the model and
return the optimized completion in the completion field of the CompletionResponse.
The raw completion, if returned, will contain the un-optimized completion.
"""

payload = {
Expand Down Expand Up @@ -461,6 +468,7 @@ def complete(
"contextual_control_threshold": contextual_control_threshold,
"control_log_additive": control_log_additive,
"repetition_penalties_include_completion": repetition_penalties_include_completion,
"raw_completion": raw_completion,
}

if hosting is not None:
Expand Down
7 changes: 7 additions & 0 deletions aleph_alpha_client/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ class CompletionRequest(NamedTuple):
repetition_penalties_include_completion (bool, optional, default True)
Flag deciding whether presence penalty or frequency penalty are updated from the completion
raw_completion (bool, default False)
Setting this parameter to true forces the raw completion of the model to be returned.
For some models, we may optimize the completion that was generated by the model and
return the optimized completion in the completion field of the CompletionResponse.
The raw completion, if returned, will contain the un-optimized completion.
Examples:
>>> prompt = Prompt.from_text("Provide a short description of AI:")
>>> request = CompletionRequest(prompt=prompt, maximum_tokens=20)
Expand Down Expand Up @@ -204,6 +210,7 @@ class CompletionRequest(NamedTuple):
contextual_control_threshold: Optional[float] = None
control_log_additive: Optional[bool] = True
repetition_penalties_include_completion: bool = True
raw_completion: bool = False

def to_json(self) -> Dict[str, Any]:
payload = {k: v for k, v in self._asdict().items() if v is not None}
Expand Down

0 comments on commit fd03271

Please sign in to comment.