• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account settings Log out
  • Favorite
  • Project
  • All
Loading...
  • Log in
  • Sign up
yjyoon / whisper_server_speaches star
  • Project homeH
  • CodeC
  • IssueI
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB
  • Files
  • Commit
  • Branches
whisper_server_speachestestsmodel_manager_test.py
Download as .zip file
File name
Commit message
Commit date
.github/workflows
feat: switch to ghcr.io
01-10
configuration
feat: add instrumentation
2024-12-17
docs
rename to `speaches`
01-12
examples
rename to `speaches`
01-12
scripts
chore: misc changes
2024-10-03
src/speaches
rename to `speaches`
01-12
tests
rename to `speaches`
01-12
.dockerignore
chore: update .dockerignore
2024-11-01
.envrc
init
2024-05-20
.gitattributes
chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.7.2
2024-11-02
.gitignore
chore: update .gitignore
2024-07-03
.pre-commit-config.yaml
chore(deps): update pre-commit hook python-jsonschema/check-jsonschema to v0.31.0
01-12
Dockerfile
chore(deps): update ghcr.io/astral-sh/uv docker tag to v0.5.18
01-12
LICENSE
init
2024-05-20
README.md
rename to `speaches`
01-12
Taskfile.yaml
rename to `speaches`
01-12
audio.wav
chore: update volume names and mount points
01-10
compose.cpu.yaml
rename to `speaches`
01-12
compose.cuda-cdi.yaml
rename to `speaches`
01-12
compose.cuda.yaml
rename to `speaches`
01-12
compose.observability.yaml
chore(deps): update otel/opentelemetry-collector-contrib docker tag to v0.117.0
01-12
compose.yaml
rename to `speaches`
01-12
flake.lock
deps: update flake
2024-11-01
flake.nix
chore(deps): add loki and tempo package to flake
2024-12-17
mkdocs.yml
rename to `speaches`
01-12
pyproject.toml
rename to `speaches`
01-12
renovate.json
feat: renovate handle pre-commit
2024-11-01
uv.lock
rename to `speaches`
01-12
File name
Commit message
Commit date
__init__.py
feat: add /v1/models and /v1/model routes #14
2024-06-03
api_model_test.py
chore: auto-fix ruff errors
2024-10-01
api_timestamp_granularities_test.py
rename to `speaches`
01-12
conftest.py
rename to `speaches`
01-12
model_manager_test.py
rename to `speaches`
01-12
openai_timestamp_granularities_test.py
rename to `speaches`
01-12
speech_test.py
rename to `speaches`
01-12
sse_test.py
rename to `speaches`
01-12
Fedir Zadniprovskyi 01-12 7396159 rename to `speaches` UNIX
Raw Open in browser Change history
import asyncio import anyio import pytest from speaches.config import Config, WhisperConfig from tests.conftest import DEFAULT_WHISPER_MODEL, AclientFactory MODEL = DEFAULT_WHISPER_MODEL # just to make the test more readable @pytest.mark.asyncio async def test_model_unloaded_after_ttl(aclient_factory: AclientFactory) -> None: ttl = 5 config = Config(whisper=WhisperConfig(model=MODEL, ttl=ttl), enable_ui=False) async with aclient_factory(config) as aclient: res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 await aclient.post(f"/api/ps/{MODEL}") res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(ttl + 1) # wait for the model to be unloaded res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 @pytest.mark.asyncio async def test_ttl_resets_after_usage(aclient_factory: AclientFactory) -> None: ttl = 5 config = Config(whisper=WhisperConfig(model=MODEL, ttl=ttl), enable_ui=False) async with aclient_factory(config) as aclient: await aclient.post(f"/api/ps/{MODEL}") res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(ttl - 2) # sleep for less than the ttl. The model should not be unloaded res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() res = ( await aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": MODEL}, ) ).json() res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(ttl - 2) # sleep for less than the ttl. The model should not be unloaded res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 await asyncio.sleep(3) # sleep for a bit more. The model should be unloaded res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 # test the model can be used again after being unloaded # this just ensures the model can be loaded again after being unloaded res = ( await aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": MODEL}, ) ).json() @pytest.mark.asyncio async def test_model_cant_be_unloaded_when_used(aclient_factory: AclientFactory) -> None: ttl = 0 config = Config(whisper=WhisperConfig(model=MODEL, ttl=ttl), enable_ui=False) async with aclient_factory(config) as aclient: async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() task = asyncio.create_task( aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": MODEL} ) ) await asyncio.sleep(0.1) # wait for the server to start processing the request res = await aclient.delete(f"/api/ps/{MODEL}") assert res.status_code == 409 await task res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0 @pytest.mark.asyncio async def test_model_cant_be_loaded_twice(aclient_factory: AclientFactory) -> None: ttl = -1 config = Config(whisper=WhisperConfig(model=MODEL, ttl=ttl), enable_ui=False) async with aclient_factory(config) as aclient: res = await aclient.post(f"/api/ps/{MODEL}") assert res.status_code == 201 res = await aclient.post(f"/api/ps/{MODEL}") assert res.status_code == 409 res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 1 @pytest.mark.asyncio async def test_model_is_unloaded_after_request_when_ttl_is_zero(aclient_factory: AclientFactory) -> None: ttl = 0 config = Config(whisper=WhisperConfig(model=MODEL, ttl=ttl), enable_ui=False) async with aclient_factory(config) as aclient: async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() res = await aclient.post( "/v1/audio/transcriptions", files={"file": ("audio.wav", data, "audio/wav")}, data={"model": "Systran/faster-whisper-tiny.en"}, ) res = (await aclient.get("/api/ps")).json() assert len(res["models"]) == 0

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
Sign in with github login with Google Sign in with Google
Reset password | Sign up