Lounès Lounis
08/12/2024, 1:49 PMtransport=httpx.ASGITransport(app=Summarization.to_asgi(init=True))
it raises an exception:
TypeError: Service.to_asgi() got an unexpected keyword argument 'init'
Everything works as expected in 1.2.20
Is there anyone here who could help me fix this please ?Jian Shen Yap
08/13/2024, 2:54 AMJian Shen Yap
08/13/2024, 2:54 AMJian Shen Yap
08/14/2024, 1:27 PMinit argument anymoreLounès Lounis
08/14/2024, 1:49 PMJian Shen Yap
08/14/2024, 1:58 PMLounès Lounis
08/14/2024, 2:07 PM{
"error": "An unexpected error has occurred, please check the server log."
}
I have no stacktrace from my app, which runs with no error when i launch it using the containerized version with bentoml versions 1.2.20, 1.3.0, 1.3.1 and 1.3.2Jian Shen Yap
08/14/2024, 4:13 PMbentoml serve? maybe share us a reproducible example?Lounès Lounis
08/19/2024, 9:24 AMJian Shen Yap
08/19/2024, 12:18 PMLounès Lounis
08/19/2024, 3:59 PMfrom __future__ import annotations
import bentoml
from transformers import pipeline
EXAMPLE_INPUT = "anything to test"
@bentoml.service(
resources={"cpu": "2"},
traffic={"timeout": 10},
)
class Summarization:
def __init__(self) -> None:
# Load model into pipeline
self.pipeline = pipeline('summarization')
@bentoml.api
def summarize(self, text: str) -> str:
result = self.pipeline(text)
return result[0]['summary_text']
from starlette.testclient import TestClient
from service import Summarization, EXAMPLE_INPUT # Imported from the Summarization service.py file
def test_request():
# Initialize the ASGI app with the Summarization Service
app = Summarization.to_asgi()
# Create a test client to interact with the ASGI app
test_client = TestClient(app=app)
response = test_client.post("/summarize", json={"text": EXAMPLE_INPUT})
# Retrieve the text from the response for validation
summarized_text = response.text
# Assert that the HTTP response status code is 200, indicating success
assert response.status_code == 200
# Assert that the summarized text is not empty
assert summarized_text, "The summary should not be empty"