Skip to content

Commit

Permalink
Merge pull request #487 from TEN-framework/dev/dify
Browse files Browse the repository at this point in the history
Support dify extension and graph
  • Loading branch information
plutoless authored Dec 17, 2024
2 parents fa67be9 + 33db905 commit 7df4403
Show file tree
Hide file tree
Showing 26 changed files with 906 additions and 27 deletions.
212 changes: 212 additions & 0 deletions agents/examples/demo/property.json
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,218 @@
]
}
]
},
{
"name": "va_dify_azure",
"auto_start": true,
"nodes": [
{
"type": "extension",
"name": "agora_rtc",
"addon": "agora_rtc",
"extension_group": "default",
"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",
"name": "llm",
"addon": "dify_python",
"extension_group": "chatgpt",
"property": {
"api_key": "${env:DIFY_API_KEY}",
"base_url": "https://api.dify.ai/v1",
"greeting": "TEN Agent connected with Dify. How can I help you today?",
"user_id": "User"
}
},
{
"type": "extension",
"name": "tts",
"addon": "azure_tts",
"extension_group": "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",
"name": "interrupt_detector",
"addon": "interrupt_detector_python",
"extension_group": "default",
"property": {}
},
{
"type": "extension",
"name": "message_collector",
"addon": "message_collector",
"extension_group": "transcriber",
"property": {}
}
],
"connections": [
{
"extension_group": "default",
"extension": "agora_rtc",
"cmd": [
{
"name": "on_user_joined",
"dest": [
{
"extension_group": "chatgpt",
"extension": "llm"
}
]
},
{
"name": "on_user_left",
"dest": [
{
"extension_group": "chatgpt",
"extension": "llm"
}
]
},
{
"name": "on_connection_failure",
"dest": [
{
"extension_group": "chatgpt",
"extension": "llm"
}
]
}
],
"data": [
{
"name": "text_data",
"dest": [
{
"extension_group": "default",
"extension": "interrupt_detector"
},
{
"extension_group": "transcriber",
"extension": "message_collector"
}
]
}
]
},
{
"extension_group": "chatgpt",
"extension": "llm",
"cmd": [
{
"name": "flush",
"dest": [
{
"extension_group": "tts",
"extension": "tts"
}
]
}
],
"data": [
{
"name": "text_data",
"dest": [
{
"extension_group": "tts",
"extension": "tts"
},
{
"extension_group": "transcriber",
"extension": "message_collector"
}
]
}
]
},
{
"extension_group": "transcriber",
"extension": "message_collector",
"data": [
{
"name": "data",
"dest": [
{
"extension_group": "default",
"extension": "agora_rtc"
}
]
}
]
},
{
"extension_group": "tts",
"extension": "tts",
"cmd": [
{
"name": "flush",
"dest": [
{
"extension_group": "default",
"extension": "agora_rtc"
}
]
}
],
"audio_frame": [
{
"name": "pcm_frame",
"dest": [
{
"extension_group": "default",
"extension": "agora_rtc"
}
]
}
]
},
{
"extension_group": "default",
"extension": "interrupt_detector",
"cmd": [
{
"name": "flush",
"dest": [
{
"extension_group": "chatgpt",
"extension": "llm"
}
]
}
],
"data": [
{
"name": "text_data",
"dest": [
{
"extension_group": "chatgpt",
"extension": "llm"
}
]
}
]
}
]
}
],
"log_level": 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ async def on_stop(self, ten_env: AsyncTenEnv) -> None:
ten_env.log_debug("on_stop")

self.stopped = True
await self.queue.put(None)

async def on_deinit(self, ten_env: AsyncTenEnv) -> None:
await super().on_deinit(ten_env)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{}
{
"token": "${env:COZE_TOKEN}",
"bot_id": "${env:COZE_BOT_ID}",
"base_url": "https://api.coze.cn",
"prompt": "",
"greeting": "TEN Agent connected with Coze. How can I help you today?"
}
19 changes: 19 additions & 0 deletions agents/ten_packages/extension/dify_python/BUILD.gn
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.
#
import("//build/feature/ten_package.gni")

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

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

<!-- brief introduction for the extension -->

## Features

<!-- main features introduction -->

- xxx feature

## API

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

<!-- Additional API.md can be referred to if extra introduction needed -->

## Development

### Build

<!-- build dependencies and steps -->

### Unit test

<!-- how to do unit test for the extension -->

## Misc

<!-- others if applicable -->
6 changes: 6 additions & 0 deletions agents/ten_packages/extension/dify_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# 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/dify_python/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,
)
from .extension import DifyExtension


@register_addon_as_extension("dify_python")
class DifyExtensionAddon(Addon):

def on_create_instance(self, ten_env: TenEnv, name: str, context) -> None:
ten_env.log_info("DifyExtensionAddon on_create_instance")
ten_env.on_create_instance_done(DifyExtension(name), context)
Loading

0 comments on commit 7df4403

Please sign in to comment.