-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: adjust folder structure - do not rely on next.js api router. use middleware instead * fix: adjust folder structure - do not rely on next.js api router. use middleware instead - docs
- Loading branch information
Showing
4 changed files
with
172 additions
and
176 deletions.
There are no files selected for viewing
267 changes: 159 additions & 108 deletions
267
...ground/src/app/api/agents/start/graph.tsx → playground/src/apis/routes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.