Skip to content

Commit d52c958

Browse files
committed
Update tests to expect Output as the generation return value
1 parent a6b231f commit d52c958

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

tests/backends/test_llguidance.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,35 +158,35 @@ def test_llguidance_backend(model, tensor_library_name, json_schema, regex, cfg_
158158
assert isinstance(processor, LLGuidanceLogitsProcessor)
159159
generator = outlines.Generator(model, backend="llguidance", processor=processor)
160160
response = generator("Hello, how are you?")
161-
assert response[0] == "{"
161+
assert response.content[0] == "{"
162162

163163
# regex
164164
processor = backend.get_regex_logits_processor(regex)
165165
assert isinstance(processor, LLGuidanceLogitsProcessor)
166166
generator = outlines.Generator(model, backend="llguidance", processor=processor)
167167
response = generator("Hello, how are you?")
168-
assert len(response) == 3
169-
assert int(response)
168+
assert len(response.content) == 3
169+
assert int(response.content)
170170

171171
# cfg lark
172172
processor = backend.get_cfg_logits_processor(cfg_lark)
173173
assert isinstance(processor, LLGuidanceLogitsProcessor)
174174
generator = outlines.Generator(model, backend="llguidance", processor=processor)
175175
response = generator("Hello, how are you?")
176176
assert (
177-
"+" in response
178-
or "-" in response
179-
or "*" in response
180-
or "/" in response
181-
or float(response.strip())
177+
"+" in response.content
178+
or "-" in response.content
179+
or "*" in response.content
180+
or "/" in response.content
181+
or float(response.content.strip())
182182
)
183183

184184
# cfg ebnf
185185
processor = backend.get_cfg_logits_processor(cfg_ebnf)
186186
assert isinstance(processor, LLGuidanceLogitsProcessor)
187187
generator = outlines.Generator(model, backend="llguidance", processor=processor)
188188
response = generator("Hello, how are you?")
189-
assert response == "yes" or response == "no"
189+
assert response.content == "yes" or response.content == "no"
190190

191191
# batch + multiple generations
192192
processor = backend.get_json_schema_logits_processor(json_schema)
@@ -196,7 +196,7 @@ def test_llguidance_backend(model, tensor_library_name, json_schema, regex, cfg_
196196
response = generator.batch(["Create a character", "Hello, how are you?"], max_new_tokens=200)
197197
assert len(response) == 2
198198
for r in response:
199-
assert r[0] == "{"
199+
assert r.content[0] == "{"
200200
else:
201201
response = generator("Create a character", max_tokens=20)
202-
assert response[0] == "{"
202+
assert response.content[0] == "{"

tests/backends/test_outlines_core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ def test_outlines_core_backend(model, tensor_library_name, json_schema, regex, c
149149
assert isinstance(processor, OutlinesCoreLogitsProcessor)
150150
generator = outlines.Generator(model, backend="outlines_core", processor=processor)
151151
response = generator("Hello, how are you?")
152-
assert "name" in response
152+
assert "name" in response.content
153153

154154
# regex
155155
processor = backend.get_regex_logits_processor(regex)
156156
assert isinstance(processor, OutlinesCoreLogitsProcessor)
157157
generator = outlines.Generator(model, backend="outlines_core", processor=processor)
158158
response = generator("Hello, how are you?")
159-
assert len(response) == 3
160-
assert int(response)
159+
assert len(response.content) == 3
160+
assert int(response.content)
161161

162162
# cfg
163163
with pytest.raises(
@@ -174,9 +174,9 @@ def test_outlines_core_backend(model, tensor_library_name, json_schema, regex, c
174174
response = generator.batch(["Create a character", "Hello, how are you?"], max_new_tokens=200)
175175
assert len(response) == 2
176176
for r in response:
177-
assert r[0] == "{"
178-
assert "name" in r
177+
assert r.content[0] == "{"
178+
assert "name" in r.content
179179
else:
180180
response = generator("Create a character", max_tokens=20)
181-
assert response[0] == "{"
182-
assert "name" in response
181+
assert response.content[0] == "{"
182+
assert "name" in response.content

tests/backends/test_xgrammar.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,23 @@ def test_xgrammar_backend(model, tensor_library_name, json_schema, regex, cfg):
125125
assert isinstance(processor, XGrammarLogitsProcessor)
126126
generator = outlines.Generator(model, backend="xgrammar", processor=processor)
127127
response = generator("Hello, how are you?")
128-
assert response[0] == "{"
129-
assert "name" in response
128+
assert response.content[0] == "{"
129+
assert "name" in response.content
130130

131131
# regex
132132
processor = backend.get_regex_logits_processor(regex)
133133
assert isinstance(processor, XGrammarLogitsProcessor)
134134
generator = outlines.Generator(model, backend="xgrammar", processor=processor)
135135
response = generator("Hello, how are you?")
136-
assert len(response) == 3
137-
assert int(response)
136+
assert len(response.content) == 3
137+
assert int(response.content)
138138

139139
# cfg
140140
processor = backend.get_cfg_logits_processor(cfg)
141141
assert isinstance(processor, XGrammarLogitsProcessor)
142142
generator = outlines.Generator(model, backend="xgrammar", processor=processor)
143143
response = generator("Hello, how are you?")
144-
assert response == "yes" or response == "no"
144+
assert response.content == "yes" or response.content == "no"
145145

146146
# batch + multiple generations
147147
processor = backend.get_json_schema_logits_processor(json_schema)
@@ -151,12 +151,12 @@ def test_xgrammar_backend(model, tensor_library_name, json_schema, regex, cfg):
151151
response = generator.batch(["Create a character", "Hello, how are you?"], max_new_tokens=200)
152152
assert len(response) == 2
153153
for r in response:
154-
assert r[0] == "{"
155-
assert "name" in r
154+
assert r.content[0] == "{"
155+
assert "name" in r.content
156156
else:
157157
response = generator("Create a character", max_tokens=20)
158-
assert response[0] == "{"
159-
assert "name" in response
158+
assert response.content[0] == "{"
159+
assert "name" in response.content
160160

161161

162162
def test_xgrammar_backend_invalid_model():

tests/test_applications.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from outlines import from_transformers
88
from outlines.applications import Application
9+
from outlines.outputs import Output
910
from outlines.templates import Template
1011

1112

@@ -51,7 +52,7 @@ def test_application_template_call(model):
5152
application = Application(template, output_type)
5253
result = application(model, {"value": "example"}, max_new_tokens=10)
5354

54-
assert isinstance(result, str)
55+
assert isinstance(result, Output)
5556

5657

5758
def test_application_callable_call(model):
@@ -62,7 +63,7 @@ def template(value):
6263
application = Application(template, output_type)
6364
result = application(model, {"value": "example"}, max_new_tokens=10)
6465

65-
assert isinstance(result, str)
66+
assert isinstance(result, Output)
6667

6768

6869
def test_application_template_error(model):

0 commit comments

Comments
 (0)