mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-17 04:14:29 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import base64
|
|
import sys
|
|
from types import ModuleType, SimpleNamespace
|
|
|
|
from docsgpt.tts.elevenlabs import ElevenlabsTTS
|
|
|
|
|
|
def test_elevenlabs_text_to_speech_monkeypatched_client(monkeypatch):
|
|
monkeypatch.setattr(
|
|
"docsgpt.tts.elevenlabs.settings",
|
|
SimpleNamespace(ELEVENLABS_API_KEY="api-key"),
|
|
)
|
|
|
|
created = {}
|
|
|
|
class DummyClient:
|
|
def __init__(self, api_key):
|
|
created["api_key"] = api_key
|
|
self.convert_calls = []
|
|
|
|
class TextToSpeech:
|
|
def __init__(self, outer):
|
|
self._outer = outer
|
|
|
|
def convert(self, *, voice_id, model_id, text, output_format):
|
|
self._outer.convert_calls.append(
|
|
{
|
|
"voice_id": voice_id,
|
|
"model_id": model_id,
|
|
"text": text,
|
|
"output_format": output_format,
|
|
}
|
|
)
|
|
yield b"chunk-one"
|
|
yield b"chunk-two"
|
|
|
|
self.text_to_speech = TextToSpeech(self)
|
|
|
|
client_module = ModuleType("elevenlabs.client")
|
|
client_module.ElevenLabs = DummyClient
|
|
package_module = ModuleType("elevenlabs")
|
|
package_module.client = client_module
|
|
|
|
monkeypatch.setitem(sys.modules, "elevenlabs", package_module)
|
|
monkeypatch.setitem(sys.modules, "elevenlabs.client", client_module)
|
|
|
|
tts = ElevenlabsTTS()
|
|
audio_base64, lang = tts.text_to_speech("Speak")
|
|
|
|
assert created["api_key"] == "api-key"
|
|
assert tts.client.convert_calls == [
|
|
{
|
|
"voice_id": "nPczCjzI2devNBz1zQrb",
|
|
"model_id": "eleven_multilingual_v2",
|
|
"text": "Speak",
|
|
"output_format": "mp3_44100_128",
|
|
}
|
|
]
|
|
assert lang == "en"
|
|
assert base64.b64decode(audio_base64.encode()) == b"chunk-onechunk-two"
|
|
|