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

Dev/coze demo #426

Merged
merged 22 commits into from
Dec 4, 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: 2 additions & 0 deletions agents/bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

cd "$(dirname "${BASH_SOURCE[0]}")/.."

#export TEN_ENABLE_PYTHON_DEBUG=true
#export TEN_PYTHON_DEBUG_PORT=5678
export PYTHONPATH=$(pwd)/ten_packages/system/ten_ai_base/interface:$PYTHONPATH
export LD_LIBRARY_PATH=$(pwd)/ten_packages/system/agora_rtc_sdk/lib:$(pwd)/ten_packages/extension/agora_rtm/lib:$(pwd)/ten_packages/system/azure_speech_sdk/lib

Expand Down
195 changes: 195 additions & 0 deletions agents/examples/experimental/property.json
Original file line number Diff line number Diff line change
Expand Up @@ -3797,6 +3797,201 @@
]
}
]
},
{
"name": "va_coze_azure",
"auto_start": false,
"nodes": [
{
"type": "extension",
"extension_group": "default",
"addon": "agora_rtc",
"name": "agora_rtc",
"property": {
"app_id": "${env:AGORA_APP_ID}",
"token": "<agora_token>",
"channel": "ten_agent_test",
"stream_id": 1234,
"remote_stream_id": 123,
"subscribe_audio": true,
"publish_audio": true,
"publish_data": true,
"enable_agora_asr": true,
"agora_asr_vendor_name": "microsoft",
"agora_asr_language": "en-US",
"agora_asr_vendor_key": "${env:AZURE_STT_KEY}",
"agora_asr_vendor_region": "${env:AZURE_STT_REGION}",
"agora_asr_session_control_file_path": "session_control.conf"
}
},
{
"type": "extension",
"extension_group": "default",
"addon": "interrupt_detector",
"name": "interrupt_detector"
},
{
"type": "extension",
"extension_group": "glue",
"addon": "coze_python_async",
"name": "coze_python_async",
"property": {
"token": "<coze_token>",
"bot_id": "<coze_bot_id>",
"base_url": "https://api.coze.cn",
"prompt": "",
"greeting": "TEN Agent connected. How can I help you today?"
}
},
{
"type": "extension",
"extension_group": "tts",
"addon": "azure_tts",
"name": "azure_tts",
"property": {
"azure_subscription_key": "${env:AZURE_TTS_KEY}",
"azure_subscription_region": "${env:AZURE_TTS_REGION}",
"azure_synthesis_voice_name": "en-US-AndrewMultilingualNeural"
}
},
{
"type": "extension",
"extension_group": "transcriber",
"addon": "message_collector",
"name": "message_collector"
}
],
"connections": [
{
"extension_group": "default",
"extension": "agora_rtc",
"data": [
{
"name": "text_data",
"dest": [
{
"extension_group": "default",
"extension": "interrupt_detector"
},
{
"extension_group": "glue",
"extension": "coze_python_async"
},
{
"extension_group": "transcriber",
"extension": "message_collector"
}
]
}
],
"cmd": [
{
"name": "on_user_joined",
"dest": [
{
"extension_group": "glue",
"extension": "coze_python_async"
}
]
},
{
"name": "on_user_left",
"dest": [
{
"extension_group": "glue",
"extension": "coze_python_async"
}
]
}
]
},
{
"extension_group": "glue",
"extension": "coze_python_async",
"data": [
{
"name": "text_data",
"dest": [
{
"extension_group": "tts",
"extension": "azure_tts"
},
{
"extension_group": "transcriber",
"extension": "message_collector"
}
]
}
],
"cmd": [
{
"name": "flush",
"dest": [
{
"extension_group": "tts",
"extension": "azure_tts"
}
]
}
]
},
{
"extension_group": "tts",
"extension": "azure_tts",
"audio_frame": [
{
"name": "pcm_frame",
"dest": [
{
"extension_group": "default",
"extension": "agora_rtc"
}
]
}
],
"cmd": [
{
"name": "flush",
"dest": [
{
"extension_group": "default",
"extension": "agora_rtc"
}
]
}
]
},
{
"extension_group": "transcriber",
"extension": "message_collector",
"data": [
{
"name": "data",
"dest": [
{
"extension_group": "default",
"extension": "agora_rtc"
}
]
}
]
},
{
"extension_group": "default",
"extension": "interrupt_detector",
"cmd": [
{
"name": "flush",
"dest": [
{
"extension_group": "glue",
"extension": "coze_python_async"
}
]
}
]
}
]
}
]
}
Expand Down
20 changes: 20 additions & 0 deletions agents/ten_packages/extension/coze_python_async/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0.
# See the LICENSE file for more information.
#
import("//build/feature/ten_package.gni")

ten_package("coze_python_async") {
package_kind = "extension"

resources = [
"__init__.py",
"addon.py",
"extension.py",
"log.py",
"manifest.json",
"property.json",
"tests",
]
}
37 changes: 37 additions & 0 deletions agents/ten_packages/extension/coze_python_async/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# coze_python_async

This is a python extension for coze service. The schema of coze service is attached in `schema.yml`.

An example of OpenAI wrapper is also attached in `examples/openai_wrapper.py`.

## Features

The extension will record history with count of `max_history`.

- `api_url` (must have): the url for the coze service.
- `token` (must have): use Bearer token to support default auth

The extension support flush that will close the existing http session.

## API

Refer to `api` definition in [manifest.json] and default values in [property.json](property.json).

- In:
- `text_data` [data]: the asr result
- `flush` [cmd]: the flush signal
- Out:
- `flush` [cmd]: the flush signal

## Examples

You can run example using following command, and the wrapper service will listen 8000 by default.

```
> export API_TOKEN="xxx" && export OPENAI_API_KEY="xxx" && python3 openai_wrapper.py

INFO: Started server process [162886]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```
7 changes: 7 additions & 0 deletions agents/ten_packages/extension/coze_python_async/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0.
# See the LICENSE file for more information.
#
from . import addon

19 changes: 19 additions & 0 deletions agents/ten_packages/extension/coze_python_async/addon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0.
# See the LICENSE file for more information.
#
from ten import (
Addon,
register_addon_as_extension,
TenEnv,
)


@register_addon_as_extension("coze_python_async")
class AsyncCozeExtensionAddon(Addon):

def on_create_instance(self, ten_env: TenEnv, name: str, context) -> None:
from .extension import AsyncCozeExtension
ten_env.log_info("AsyncCozeExtensionAddon on_create_instance")
ten_env.on_create_instance_done(AsyncCozeExtension(name), context)
Loading
Loading