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

fix: adjust folder structure #269

Merged
merged 2 commits into from
Sep 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
Original file line number Diff line number Diff line change
@@ -1,108 +1,159 @@
import { LanguageMap } from "@/common/constant";

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",
},
},
"ja-JP": {
azure: {
male: "ja-JP-KeitaNeural",
female: "ja-JP-NanamiNeural",
},
},
"ko-KR": {
azure: {
male: "ko-KR-InJoonNeural",
female: "ko-KR-JiMinNeural",
},
},
};

// Get the graph properties based on the graph name, language, and voice type
// This is the place where you can customize the properties for different graphs to override default property.json
export const getGraphProperties = (graphName: string, language: string, voiceType: string) => {
let localizationOptions = {
"greeting": "ASTRA agent connected. How can i help you today?",
"checking_vision_text_items": "[\"Let me take a look...\",\"Let me check your camera...\",\"Please wait for a second...\"]",
}

if (language === "zh-CN") {
localizationOptions = {
"greeting": "Astra已连接,需要我为您提供什么帮助?",
"checking_vision_text_items": "[\"让我看看你的摄像头...\",\"让我看一下...\",\"我看一下,请稍候...\"]",
}
} else if (language === "ja-JP") {
localizationOptions = {
"greeting": "ASTRAエージェントに接続されました。今日は何をお手伝いしましょうか?",
"checking_vision_text_items": "[\"ちょっと見てみます...\",\"カメラをチェックします...\",\"少々お待ちください...\"]",
}
} else if (language === "ko-KR") {
localizationOptions = {
"greeting": "ASTRA 에이전트에 연결되었습니다. 오늘은 무엇을 도와드릴까요?",
"checking_vision_text_items": "[\"조금만 기다려 주세요...\",\"카메라를 확인해 보겠습니다...\",\"잠시만 기다려 주세요...\"]",
}
}

if (graphName == "camera.va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"openai_chatgpt": {
"model": "gpt-4o",
...localizationOptions
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
} else if (graphName == "va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"openai_chatgpt": {
"model": "gpt-4o-mini",
...localizationOptions
},
"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 {}
}
import { LanguageMap } from '@/common/constant';
import { NextRequest, NextResponse } from 'next/server';


const { AGENT_SERVER_URL } = process.env;

// Check if environment variables are available
if (!AGENT_SERVER_URL) {
throw "Environment variables AGENT_SERVER_URL are not available";
}


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",
},
},
"ja-JP": {
azure: {
male: "ja-JP-KeitaNeural",
female: "ja-JP-NanamiNeural",
},
},
"ko-KR": {
azure: {
male: "ko-KR-InJoonNeural",
female: "ko-KR-JiMinNeural",
},
},
};

// Get the graph properties based on the graph name, language, and voice type
// This is the place where you can customize the properties for different graphs to override default property.json
export const getGraphProperties = (graphName: string, language: string, voiceType: string) => {
let localizationOptions = {
"greeting": "ASTRA agent connected. How can i help you today?",
"checking_vision_text_items": "[\"Let me take a look...\",\"Let me check your camera...\",\"Please wait for a second...\"]",
}

if (language === "zh-CN") {
localizationOptions = {
"greeting": "Astra已连接,需要我为您提供什么帮助?",
"checking_vision_text_items": "[\"让我看看你的摄像头...\",\"让我看一下...\",\"我看一下,请稍候...\"]",
}
} else if (language === "ja-JP") {
localizationOptions = {
"greeting": "ASTRAエージェントに接続されました。今日は何をお手伝いしましょうか?",
"checking_vision_text_items": "[\"ちょっと見てみます...\",\"カメラをチェックします...\",\"少々お待ちください...\"]",
}
} else if (language === "ko-KR") {
localizationOptions = {
"greeting": "ASTRA 에이전트에 연결되었습니다. 오늘은 무엇을 도와드릴까요?",
"checking_vision_text_items": "[\"조금만 기다려 주세요...\",\"카메라를 확인해 보겠습니다...\",\"잠시만 기다려 주세요...\"]",
}
}

if (graphName == "camera.va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"openai_chatgpt": {
"model": "gpt-4o",
...localizationOptions
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
} else if (graphName == "va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"openai_chatgpt": {
"model": "gpt-4o-mini",
...localizationOptions
},
"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 {}
}

export async function startAgent(request: NextRequest) {
try{
const body = await request.json();
const {
request_id,
channel_name,
user_uid,
graph_name,
language,
voice_type,
} = body;

// Send a POST request to start the agent
const response = await fetch(`${AGENT_SERVER_URL}/start`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
request_id,
channel_name,
user_uid,
graph_name,
// Get the graph properties based on the graph name, language, and voice type
properties: getGraphProperties(graph_name, language, voice_type),
}),
});

const responseData = await response.json();

return NextResponse.json(responseData, { status: response.status });
} catch (error) {
if (error instanceof Response) {
const errorData = await error.json();
return NextResponse.json(errorData, { status: error.status });
} else {
return NextResponse.json({ code: "1", data: null, msg: "Internal Server Error" }, { status: 500 });
}
}
}
56 changes: 0 additions & 56 deletions playground/src/app/api/agents/start/route.tsx

This file was deleted.

11 changes: 6 additions & 5 deletions playground/src/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface GenAgoraDataConfig {
}

export const apiGenAgoraData = async (config: GenAgoraDataConfig) => {
// the request will be rewrite at next.config.mjs to send to $AGENT_SERVER_URL
// the request will be rewrite at middleware.tsx to send to $AGENT_SERVER_URL
const url = `/api/token/generate`
const { userId, channel } = config
const data = {
Expand All @@ -35,7 +35,7 @@ export const apiGenAgoraData = async (config: GenAgoraDataConfig) => {
}

export const apiStartService = async (config: StartRequestConfig): Promise<any> => {
// look at app/api/agents/start/route.tsx for the server-side implementation
// look at app/apis/route.tsx for the server-side implementation
const url = `/api/agents/start`
const { channel, userId, graphName, language, voiceType } = config
const data = {
Expand All @@ -58,7 +58,7 @@ export const apiStartService = async (config: StartRequestConfig): Promise<any>
}

export const apiStopService = async (channel: string) => {
// the request will be rewrite at next.config.mjs to send to $AGENT_SERVER_URL
// the request will be rewrite at middleware.tsx to send to $AGENT_SERVER_URL
const url = `/api/agents/stop`
const data = {
request_id: genUUID(),
Expand All @@ -76,6 +76,7 @@ export const apiStopService = async (channel: string) => {
}

export const apiGetDocumentList = async () => {
// the request will be rewrite at middleware.tsx to send to $AGENT_SERVER_URL
const url = `/api/vector/document/preset/list`
let resp: any = await fetch(url, {
method: "GET",
Expand All @@ -91,7 +92,7 @@ export const apiGetDocumentList = async () => {
}

export const apiUpdateDocument = async (options: { channel: string, collection: string, fileName: string }) => {
// the request will be rewrite at next.config.mjs to send to $AGENT_SERVER_URL
// the request will be rewrite at middleware.tsx to send to $AGENT_SERVER_URL
const url = `/api/vector/document/update`
const { channel, collection, fileName } = options
const data = {
Expand All @@ -114,7 +115,7 @@ export const apiUpdateDocument = async (options: { channel: string, collection:

// ping/pong
export const apiPing = async (channel: string) => {
// the request will be rewrite at next.config.mjs to send to $AGENT_SERVER_URL
// the request will be rewrite at middleware.tsx to send to $AGENT_SERVER_URL
const url = `/api/agents/ping`
const data = {
request_id: genUUID(),
Expand Down
Loading