Skip to content

Commit 132cb28

Browse files
committed
small changes but service still not working
1 parent 14f5991 commit 132cb28

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from contextlib import asynccontextmanager
2020

2121
# Imports required by the service's model
22-
# TODO: 1. ADD REQUIRED IMPORTS (ALSO IN THE REQUIREMENTS.TXT)
2322
from outlines import generate, models
2423
import torch
2524
import json
@@ -32,6 +31,9 @@
3231
device = "mps"
3332
else:
3433
device = "cpu"
34+
print(f"Using device: {device}")
35+
model = models.transformers("Qwen/Qwen2.5-3B-Instruct", device=device)
36+
3537

3638
class MyService(Service):
3739
"""
@@ -79,19 +81,19 @@ def __init__(self):
7981
docs_url="https://docs.swiss-ai-center.ch/reference/core-concepts/service/",
8082
)
8183
self._logger = get_logger(settings)
82-
self._model = models.transformers("Qwen/Qwen2.5-3B-Instruct", device=device)
84+
self._model = model
8385

84-
# TODO: 5. CHANGE THE PROCESS METHOD (CORE OF THE SERVICE)
8586
def process(self, data):
8687
json_schema = data["format"].data.decode("utf-8")
8788
prompt = data["prompt"].data.decode("utf-8")
88-
89+
8990
# Use Outlines library to format LLM outputs
90-
91+
9192
generator = generate.json(self._model, json_schema)
9293
result = generator(prompt)
93-
94-
result = json.dumps(result)
94+
95+
# json to bytes
96+
result = json.dumps(result).encode("utf-8")
9597

9698
# NOTE that the result must be a dictionary with the keys being the field names set in the data_out_fields
9799
return {
@@ -149,7 +151,6 @@ async def announce():
149151
await service_service.graceful_shutdown(my_service, engine_url)
150152

151153

152-
# TODO: 6. CHANGE THE API DESCRIPTION AND SUMMARY
153154
api_description = """
154155
Uses Outlines library to format LLM outputs.
155156
"""

0 commit comments

Comments
 (0)