Skip to content

Commit

Permalink
feat: add grammar tests and typo tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
drbh committed Feb 10, 2024
1 parent 8445775 commit cadb0a9
Show file tree
Hide file tree
Showing 11 changed files with 1,172 additions and 6 deletions.
4 changes: 4 additions & 0 deletions clients/python/text_generation/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def generate(
watermark: bool = False,
decoder_input_details: bool = False,
top_n_tokens: Optional[int] = None,
grammar: str = ""
) -> Response:
"""
Given a prompt, generate the following text
Expand Down Expand Up @@ -138,6 +139,7 @@ def generate(
watermark=watermark,
decoder_input_details=decoder_input_details,
top_n_tokens=top_n_tokens,
grammar=grammar
)
request = Request(inputs=prompt, stream=False, parameters=parameters)

Expand Down Expand Up @@ -326,6 +328,7 @@ async def generate(
watermark: bool = False,
decoder_input_details: bool = False,
top_n_tokens: Optional[int] = None,
grammar: str = ""
) -> Response:
"""
Given a prompt, generate the following text asynchronously
Expand Down Expand Up @@ -388,6 +391,7 @@ async def generate(
typical_p=typical_p,
watermark=watermark,
top_n_tokens=top_n_tokens,
grammar=grammar,
)
request = Request(inputs=prompt, stream=False, parameters=parameters)

Expand Down
4 changes: 3 additions & 1 deletion clients/python/text_generation/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Parameters(BaseModel):
decoder_input_details: bool = False
# Return the N most likely tokens at each step
top_n_tokens: Optional[int] = None
# grammar to use for generation
grammar: Optional[str] = None

@validator("best_of")
def valid_best_of(cls, field_value, values):
Expand Down Expand Up @@ -157,7 +159,7 @@ class Token(BaseModel):
# Token text
text: str
# Logprob
logprob: float
logprob: Optional[float] = None
# Is the token a special token
# Can be used to ignore tokens when concatenating
special: bool
Expand Down
2 changes: 1 addition & 1 deletion docs/source/basic_tutorials/launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,4 @@ Options:
-V, --version
Print version
```
```
11 changes: 9 additions & 2 deletions integration-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,18 @@ def docker_launcher(
@pytest.fixture(scope="module")
def generate_load():
async def generate_load_inner(
client: AsyncClient, prompt: str, max_new_tokens: int, n: int
client: AsyncClient,
prompt: str,
max_new_tokens: int,
n: int,
**kwargs,
) -> List[Response]:
futures = [
client.generate(
prompt, max_new_tokens=max_new_tokens, decoder_input_details=True
prompt,
max_new_tokens=max_new_tokens,
decoder_input_details=True,
**kwargs,
)
for _ in range(n)
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"details": {
"best_of_sequences": null,
"finish_reason": "length",
"generated_tokens": 10,
"prefill": [
{
"id": 1,
"logprob": null,
"text": "<s>"
},
{
"id": 4321,
"logprob": -13.90625,
"text": "Test"
},
{
"id": 2009,
"logprob": -12.328125,
"text": "request"
}
],
"seed": null,
"tokens": [
{
"id": 13,
"logprob": -2.0566406,
"special": false,
"text": "\n"
},
{
"id": 13,
"logprob": -1.5253906,
"special": false,
"text": "\n"
},
{
"id": 29902,
"logprob": -2.7578125,
"special": false,
"text": "I"
},
{
"id": 4966,
"logprob": -1.9033203,
"special": false,
"text": " hope"
},
{
"id": 445,
"logprob": -0.5019531,
"special": false,
"text": " this"
},
{
"id": 6911,
"logprob": -0.21264648,
"special": false,
"text": " helps"
},
{
"id": 29991,
"logprob": -0.5991211,
"special": false,
"text": "!"
},
{
"id": 2803,
"logprob": -0.37475586,
"special": false,
"text": " Let"
},
{
"id": 592,
"logprob": -0.018463135,
"special": false,
"text": " me"
},
{
"id": 1073,
"logprob": -0.0008597374,
"special": false,
"text": " know"
}
],
"top_tokens": null
},
"generated_text": "\n\nI hope this helps! Let me know"
}
Loading

0 comments on commit cadb0a9

Please sign in to comment.