Skip to content

Commit

Permalink
refactor & optimize property.json (#242)
Browse files Browse the repository at this point in the history
* 1. prevent changing property.json anywhere
2. every worker start will have a new property.json, strip property.json with non-use graphs
3. except for channel name, token and asr_language, move all other
   properties settings to frontend

* 1. moved properties to frontend
2. frontend can now overwrite property values, while channelName,
   remoteStreamUid still takes highest priority
3. use process group to better kill worker

* fix: remove legacy graph mappings

* fix: use native strings.Join

* fix: add page description
  • Loading branch information
plutoless authored Aug 23, 2024
1 parent b73dac2 commit a9ea9d2
Show file tree
Hide file tree
Showing 15 changed files with 2,698 additions and 139 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ LOG_PATH=/tmp/astra
LOG_STDOUT=true
# Graph designer server port
GRAPH_DESIGNER_SERVER_PORT=49483
# The corresponding graph name based on the language
GRAPH_NAME_ZH=va.openai.azure
GRAPH_NAME_EN=va.openai.azure
# Server port
SERVER_PORT=8080
# Maximum number of workers
Expand Down
1 change: 0 additions & 1 deletion agents/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ xdump_config
.vscode
*.pyc
*.pyc.*
/property.json
2,538 changes: 2,538 additions & 0 deletions agents/property.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion playground/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import './global.css'

export const metadata: Metadata = {
title: "Astra.ai",
description: "Generated by create next app",
description: "A multimodal agent powered by TEN",
appleWebApp: {
capable: true,
statusBarStyle: "black",
Expand Down
42 changes: 42 additions & 0 deletions playground/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,45 @@ export const COLOR_LIST: ColorItem[] = [{
default: "#481C3F"
}]

export type VoiceTypeMap = {
[voiceType: string]: string;
};

export type VendorNameMap = {
[vendorName: string]: VoiceTypeMap;
};

export type LanguageMap = {
[language: string]: VendorNameMap;
};

export const voiceNameMap: LanguageMap = {
"zh-CN": {
azure: {
male: "zh-CN-YunxiNeural",
female: "zh-CN-XiaoxiaoNeural",
},
elevenlabs: {
male: "pNInz6obpgDQGcFmaJgB", // Adam
female: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
polly: {
male: "Zhiyu",
female: "Zhiyu",
},
},
"en-US": {
azure: {
male: "en-US-BrianNeural",
female: "en-US-JaneNeural",
},
elevenlabs: {
male: "pNInz6obpgDQGcFmaJgB", // Adam
female: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
polly: {
male: "Matthew",
female: "Ruth",
},
},
};
46 changes: 46 additions & 0 deletions playground/src/common/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { voiceNameMap } from "./constant"

export const getGraphWithLanguage = (graphName: string, language: string) => {
if (graphName == "camera.va.openai.azure") {
if (language == "zh-CN") {
return `${graphName}.cn`
}
return `${graphName}.en`
}
return graphName
}

export const getGraphProperties = (graphName: string, language: string, voiceType: string) => {
if (graphName == "camera.va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"openai_chatgpt": {
"model": "gpt-4o"
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
} else if (graphName == "va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
} else if (graphName == "va.qwen.rag") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
}
return {}
}
1 change: 1 addition & 0 deletions playground/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./utils"
export * from "./storage"
export * from "./request"
export * from "./mock"
export * from "./graph"
9 changes: 4 additions & 5 deletions playground/src/common/request.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AnyObject } from "antd/es/_util/type"
import { REQUEST_URL } from "./constant"
import { genUUID } from "./utils"

interface StartRequestConfig {
channel: string
userId: number,
language: string
voiceType: string
graphName: string
properties: AnyObject
}

interface GenAgoraDataConfig {
Expand Down Expand Up @@ -35,15 +35,14 @@ export const apiGenAgoraData = async (config: GenAgoraDataConfig) => {

export const apiStartService = async (config: StartRequestConfig): Promise<any> => {
const url = `${REQUEST_URL}/start`
const { language, channel, userId, voiceType, graphName } = config
const { channel, userId, graphName, properties } = config
const data = {
request_id: genUUID(),
agora_asr_language: language,
channel_name: channel,
openai_proxy_url: "",
remote_stream_id: userId,
voice_type: voiceType,
graph_name: graphName,
properties,
}
let resp: any = await fetch(url, {
method: "POST",
Expand Down
2 changes: 1 addition & 1 deletion playground/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ export const genUUID = () => {

export const isMobile = () => {
return /Mobile|iPhone|iPad|Android|Windows Phone/i.test(navigator.userAgent)
}
}
10 changes: 6 additions & 4 deletions playground/src/platform/mobile/description/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { setAgentConnected } from "@/store/reducers/global"
import {
DESCRIPTION, useAppDispatch, useAppSelector, apiPing, genUUID,
apiStartService, apiStopService, REQUEST_URL
apiStartService, apiStopService, REQUEST_URL,
voiceNameMap,
getGraphWithLanguage,
getGraphProperties
} from "@/common"
import { message } from "antd"
import { useEffect, useState } from "react"
Expand Down Expand Up @@ -48,9 +51,8 @@ const Description = () => {
const res = await apiStartService({
channel,
userId,
language,
voiceType,
graphName,
graphName: getGraphWithLanguage(graphName, language),
properties: getGraphProperties(graphName, language, voiceType)
})
const { code, msg } = res || {}
if (code != 0) {
Expand Down
10 changes: 6 additions & 4 deletions playground/src/platform/pc/description/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { setAgentConnected } from "@/store/reducers/global"
import {
DESCRIPTION, useAppDispatch, useAppSelector, apiPing, genUUID,
apiStartService, apiStopService, REQUEST_URL
apiStartService, apiStopService, REQUEST_URL,
voiceNameMap,
getGraphWithLanguage,
getGraphProperties
} from "@/common"
import { Select, Button, message, Upload } from "antd"
import { useEffect, useState, MouseEventHandler } from "react"
Expand Down Expand Up @@ -48,9 +51,8 @@ const Description = () => {
const res = await apiStartService({
channel,
userId,
language,
voiceType,
graphName
graphName: getGraphWithLanguage(graphName, language),
properties: getGraphProperties(graphName, language, voiceType)
})
const { code, msg } = res || {}
if (code != 0) {
Expand Down
59 changes: 0 additions & 59 deletions server/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"log/slog"
"os"
)

type Prop struct {
Expand Down Expand Up @@ -34,9 +33,6 @@ const (
PropertyJsonFile = "./agents/property.json"
// Token expire time
tokenExpirationInSeconds = uint32(86400)
// Voice type
voiceTypeMale = "male"
voiceTypeFemale = "female"
)

var (
Expand Down Expand Up @@ -138,17 +134,8 @@ var (
},
}

// The corresponding graph name based on the language
graphNameMap = map[string]string{
languageChinese: "va.openai.azure",
languageEnglish: "va.openai.azure",
}

// Retrieve parameters from the request and map them to the property.json file
startPropMap = map[string][]Prop{
"AgoraAsrLanguage": {
{ExtensionName: extensionNameAgoraRTC, Property: "agora_asr_language"},
},
"ChannelName": {
{ExtensionName: extensionNameAgoraRTC, Property: "channel"},
},
Expand All @@ -158,54 +145,8 @@ var (
"Token": {
{ExtensionName: extensionNameAgoraRTC, Property: "token"},
},
"VoiceType": {
{ExtensionName: extensionNameAzureTTS, Property: "azure_synthesis_voice_name"},
{ExtensionName: extensionNameElevenlabsTTS, Property: "voice_id"},
},
"WorkerHttpServerPort": {
{ExtensionName: extensionNameHttpServer, Property: "listen_port"},
},
}

// Map the voice name to the voice type
voiceNameMap = map[string]map[string]map[string]string{
languageChinese: {
extensionNameAzureTTS: {
voiceTypeMale: "zh-CN-YunxiNeural",
voiceTypeFemale: "zh-CN-XiaoxiaoNeural",
},
extensionNameElevenlabsTTS: {
voiceTypeMale: "pNInz6obpgDQGcFmaJgB", // Adam
voiceTypeFemale: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
extensionNamePollyTTS: {
voiceTypeMale: "Zhiyu",
voiceTypeFemale: "Zhiyu",
},
},
languageEnglish: {
extensionNameAzureTTS: {
voiceTypeMale: "en-US-BrianNeural",
voiceTypeFemale: "en-US-JaneNeural",
},
extensionNameElevenlabsTTS: {
voiceTypeMale: "pNInz6obpgDQGcFmaJgB", // Adam
voiceTypeFemale: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
extensionNamePollyTTS: {
voiceTypeMale: "Matthew",
voiceTypeFemale: "Ruth",
},
},
}
)

func SetGraphNameMap() {
if graphNameZH := os.Getenv("GRAPH_NAME_ZH"); graphNameZH != "" {
graphNameMap[languageChinese] = graphNameZH
}

if graphNameEN := os.Getenv("GRAPH_NAME_EN"); graphNameEN != "" {
graphNameMap[languageEnglish] = graphNameEN
}
}
Loading

0 comments on commit a9ea9d2

Please sign in to comment.