Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove on_init/on_deinit #160

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "astra",
"image": "ghcr.io/rte-design/astra_agents_build",
"image": "ghcr.io/rte-design/astra_agents_build:0.3.5",
"customizations": {
"vscode": {
"extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,6 @@ def process_text_queue(self, rte: RteEnv):

@register_addon_as_extension("elevenlabs_tts_python")
class ElevenlabsTTSExtensionAddon(Addon):
def on_init(self, rte: RteEnv, manifest, property) -> None:
logger.info("on_init")
rte.on_init_done(manifest, property)
return

def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None:
logger.info("on_create_instance")
rte.on_create_instance_done(ElevenlabsTTSExtension(addon_name), context)

def on_deinit(self, rte: RteEnv) -> None:
logger.info("on_deinit")
rte.on_deinit_done()
return
Original file line number Diff line number Diff line change
Expand Up @@ -369,28 +369,9 @@ def chat_completions_stream_worker(start_time, input_text, memory):
)
thread.start()
logger.info(f"OpenAIChatGPTExtension on_data end")
# try:
# rte_data = Data.create("text_data")
# rte_data.set_property_string("text", "hello, world, who are you!")
# except Exception as e:
# logger.info(f"on_data new_data error, ", e)
# return

# rte.send_data(rte_data)


@register_addon_as_extension("openai_chatgpt_python")
class OpenAIChatGPTExtensionAddon(Addon):
def on_init(self, rte: RteEnv, manifest, property) -> None:
logger.info("OpenAIChatGPTExtensionAddon on_init")
rte.on_init_done(manifest, property)
return

def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None:
logger.info("on_create_instance")
rte.on_create_instance_done(OpenAIChatGPTExtension(addon_name), context)

def on_deinit(self, rte: RteEnv) -> None:
logger.info("OpenAIChatGPTExtensionAddon on_deinit")
rte.on_deinit_done()
return
24 changes: 5 additions & 19 deletions agents/addon/extension/polly_tts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def on_start(self, rte: Rte) -> None:

polly_config = PollyConfig.default_config()

for optional_param in [PROPERTY_REGION, PROPERTY_ENGINE, PROPERTY_VOICE,
PROPERTY_SAMPLE_RATE, PROPERTY_LANG_CODE,
for optional_param in [PROPERTY_REGION, PROPERTY_ENGINE, PROPERTY_VOICE,
PROPERTY_SAMPLE_RATE, PROPERTY_LANG_CODE,
PROPERTY_ACCESS_KEY, PROPERTY_SECRET_KEY ]:
try:
value = rte.get_property_string(optional_param).strip()
Expand All @@ -80,22 +80,18 @@ def on_stop(self, rte: Rte) -> None:
self.thread.join()
rte.on_stop_done()

def on_deinit(self, rte: Rte) -> None:
logger.info("PollyTTSExtension on_deinit")
rte.on_deinit_done()

def need_interrupt(self, ts: datetime.time) -> bool:
return (self.outdateTs - ts).total_seconds() > 1


def __get_frame(self, data: bytes) -> PcmFrame:
sample_rate = int(self.polly.config.sample_rate)

f = PcmFrame.create("pcm_frame")
f.set_sample_rate(sample_rate)
f.set_bytes_per_sample(2)
f.set_number_of_channels(1)

f.set_data_fmt(RTE_PCM_FRAME_DATA_FMT.RTE_PCM_FRAME_DATA_FMT_INTERLEAVE)
f.set_samples_per_channel(sample_rate // 100)
f.alloc_buf(self.frame_size)
Expand Down Expand Up @@ -142,7 +138,7 @@ def on_data(self, rte: Rte, data: Data) -> None:
if len(inputText) == 0:
logger.info("ignore empty text")
return

is_end = data.get_property_bool("end_of_segment")

logger.info("on data %s %d", inputText, is_end)
Expand All @@ -168,16 +164,6 @@ def on_cmd(self, rte: Rte, cmd: Cmd) -> None:

@register_addon_as_extension("polly_tts")
class PollyTTSExtensionAddon(Addon):
def on_init(self, rte: Rte, manifest, property) -> None:
logger.info("PollyTTSExtensionAddon on_init")
rte.on_init_done(manifest, property)
return

def on_create_instance(self, rte: Rte, addon_name: str, context) -> None:
logger.info("on_create_instance")
rte.on_create_instance_done(PollyTTSExtension(addon_name), context)

def on_deinit(self, rte: Rte) -> None:
logger.info("PollyTTSExtensionAddon on_deinit")
rte.on_deinit_done()
return
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ services:
OPENAI_PROXY_URL: ${OPENAI_PROXY_URL}
QWEN_API_KEY: ${QWEN_API_KEY}
astra_playground:
image: agoraio/astra_playground:latest
image: ghcr.io/rte-design/astra_playground:v0.2.0-15-g38e1738
container_name: astra_playground
restart: always
ports:
- "3000:3000"
astra_graph_designer:
image: agoraio/astra_graph_designer:latest
image: agoraio/astra_graph_designer:0.1.0
container_name: astra_graph_designer
restart: always
ports:
Expand Down