1
This commit is contained in:
@@ -4,6 +4,11 @@ use platform_llm::{
|
||||
DEFAULT_ARK_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_REQUEST_TIMEOUT_MS,
|
||||
DEFAULT_RETRY_BACKOFF_MS, LlmProvider,
|
||||
};
|
||||
use platform_speech::{
|
||||
DEFAULT_ASR_RESOURCE_ID, DEFAULT_ASR_WS_URL,
|
||||
DEFAULT_REQUEST_TIMEOUT_MS as DEFAULT_SPEECH_REQUEST_TIMEOUT_MS,
|
||||
DEFAULT_TTS_BIDIRECTION_WS_URL, DEFAULT_TTS_RESOURCE_ID, DEFAULT_TTS_SSE_URL,
|
||||
};
|
||||
|
||||
const DEFAULT_INTERNAL_API_SECRET: &str = "genarrative-dev-internal-bridge";
|
||||
const DEFAULT_AUTH_STORE_PATH: &str = "server-rs/.data/auth-store.json";
|
||||
@@ -92,6 +97,18 @@ pub struct AppConfig {
|
||||
pub apimart_base_url: String,
|
||||
pub apimart_api_key: Option<String>,
|
||||
pub apimart_image_request_timeout_ms: u64,
|
||||
pub vector_engine_base_url: String,
|
||||
pub vector_engine_api_key: Option<String>,
|
||||
pub vector_engine_audio_request_timeout_ms: u64,
|
||||
pub volcengine_speech_api_key: Option<String>,
|
||||
pub volcengine_speech_app_id: Option<String>,
|
||||
pub volcengine_speech_access_key: Option<String>,
|
||||
pub volcengine_speech_asr_resource_id: String,
|
||||
pub volcengine_speech_tts_resource_id: String,
|
||||
pub volcengine_speech_asr_ws_url: String,
|
||||
pub volcengine_speech_tts_bidirection_ws_url: String,
|
||||
pub volcengine_speech_tts_sse_url: String,
|
||||
pub volcengine_speech_request_timeout_ms: u64,
|
||||
pub draft_asset_generation_max_concurrent_requests: usize,
|
||||
pub ark_character_video_base_url: String,
|
||||
pub ark_character_video_api_key: Option<String>,
|
||||
@@ -187,6 +204,18 @@ impl Default for AppConfig {
|
||||
apimart_base_url: String::new(),
|
||||
apimart_api_key: None,
|
||||
apimart_image_request_timeout_ms: 180_000,
|
||||
vector_engine_base_url: String::new(),
|
||||
vector_engine_api_key: None,
|
||||
vector_engine_audio_request_timeout_ms: 180_000,
|
||||
volcengine_speech_api_key: None,
|
||||
volcengine_speech_app_id: None,
|
||||
volcengine_speech_access_key: None,
|
||||
volcengine_speech_asr_resource_id: DEFAULT_ASR_RESOURCE_ID.to_string(),
|
||||
volcengine_speech_tts_resource_id: DEFAULT_TTS_RESOURCE_ID.to_string(),
|
||||
volcengine_speech_asr_ws_url: DEFAULT_ASR_WS_URL.to_string(),
|
||||
volcengine_speech_tts_bidirection_ws_url: DEFAULT_TTS_BIDIRECTION_WS_URL.to_string(),
|
||||
volcengine_speech_tts_sse_url: DEFAULT_TTS_SSE_URL.to_string(),
|
||||
volcengine_speech_request_timeout_ms: DEFAULT_SPEECH_REQUEST_TIMEOUT_MS,
|
||||
draft_asset_generation_max_concurrent_requests: 4,
|
||||
ark_character_video_base_url: String::new(),
|
||||
ark_character_video_api_key: None,
|
||||
@@ -544,6 +573,54 @@ impl AppConfig {
|
||||
config.apimart_image_request_timeout_ms = apimart_image_request_timeout_ms;
|
||||
}
|
||||
|
||||
if let Some(vector_engine_base_url) = read_first_non_empty_env(&["VECTOR_ENGINE_BASE_URL"])
|
||||
{
|
||||
config.vector_engine_base_url = vector_engine_base_url;
|
||||
}
|
||||
|
||||
config.vector_engine_api_key = read_first_non_empty_env(&["VECTOR_ENGINE_API_KEY"]);
|
||||
|
||||
if let Some(vector_engine_audio_request_timeout_ms) =
|
||||
read_first_positive_u64_env(&["VECTOR_ENGINE_AUDIO_REQUEST_TIMEOUT_MS"])
|
||||
{
|
||||
config.vector_engine_audio_request_timeout_ms = vector_engine_audio_request_timeout_ms;
|
||||
}
|
||||
|
||||
config.volcengine_speech_api_key =
|
||||
read_first_non_empty_env(&["VOLCENGINE_SPEECH_API_KEY", "VOLCENGINE_API_KEY"]);
|
||||
config.volcengine_speech_app_id =
|
||||
read_first_non_empty_env(&["VOLCENGINE_SPEECH_APP_ID", "VOLCENGINE_ACCESS_KEY_ID"]);
|
||||
config.volcengine_speech_access_key = read_first_non_empty_env(&[
|
||||
"VOLCENGINE_SPEECH_ACCESS_KEY",
|
||||
"VOLCENGINE_SECRET_ACCESS_KEY",
|
||||
]);
|
||||
if let Some(asr_resource_id) =
|
||||
read_first_non_empty_env(&["VOLCENGINE_SPEECH_ASR_RESOURCE_ID"])
|
||||
{
|
||||
config.volcengine_speech_asr_resource_id = asr_resource_id;
|
||||
}
|
||||
if let Some(tts_resource_id) =
|
||||
read_first_non_empty_env(&["VOLCENGINE_SPEECH_TTS_RESOURCE_ID"])
|
||||
{
|
||||
config.volcengine_speech_tts_resource_id = tts_resource_id;
|
||||
}
|
||||
if let Some(asr_ws_url) = read_first_non_empty_env(&["VOLCENGINE_SPEECH_ASR_WS_URL"]) {
|
||||
config.volcengine_speech_asr_ws_url = asr_ws_url;
|
||||
}
|
||||
if let Some(tts_bidirection_ws_url) =
|
||||
read_first_non_empty_env(&["VOLCENGINE_SPEECH_TTS_BIDIRECTION_WS_URL"])
|
||||
{
|
||||
config.volcengine_speech_tts_bidirection_ws_url = tts_bidirection_ws_url;
|
||||
}
|
||||
if let Some(tts_sse_url) = read_first_non_empty_env(&["VOLCENGINE_SPEECH_TTS_SSE_URL"]) {
|
||||
config.volcengine_speech_tts_sse_url = tts_sse_url;
|
||||
}
|
||||
if let Some(request_timeout_ms) =
|
||||
read_first_positive_u64_env(&["VOLCENGINE_SPEECH_REQUEST_TIMEOUT_MS"])
|
||||
{
|
||||
config.volcengine_speech_request_timeout_ms = request_timeout_ms;
|
||||
}
|
||||
|
||||
if let Some(max_concurrent_requests) = read_first_usize_env(&[
|
||||
"GENARRATIVE_DRAFT_ASSET_GENERATION_MAX_CONCURRENT_REQUESTS",
|
||||
"DRAFT_ASSET_GENERATION_MAX_CONCURRENT_REQUESTS",
|
||||
@@ -831,6 +908,7 @@ mod tests {
|
||||
assert!(config.llm_model.is_empty());
|
||||
assert!(config.llm_base_url.is_empty());
|
||||
assert!(config.apimart_base_url.is_empty());
|
||||
assert!(config.vector_engine_base_url.is_empty());
|
||||
assert!(config.ark_character_video_base_url.is_empty());
|
||||
assert!(config.ark_character_video_model.is_empty());
|
||||
assert!(config.dashscope_scene_image_model.is_empty());
|
||||
@@ -859,6 +937,7 @@ mod tests {
|
||||
std::env::remove_var("GENARRATIVE_LLM_BASE_URL");
|
||||
std::env::remove_var("GENARRATIVE_LLM_MODEL");
|
||||
std::env::remove_var("APIMART_BASE_URL");
|
||||
std::env::remove_var("VECTOR_ENGINE_BASE_URL");
|
||||
std::env::remove_var("DASHSCOPE_SCENE_IMAGE_MODEL");
|
||||
std::env::remove_var("DASHSCOPE_REFERENCE_IMAGE_MODEL");
|
||||
std::env::remove_var("DASHSCOPE_COVER_IMAGE_MODEL");
|
||||
@@ -871,6 +950,7 @@ mod tests {
|
||||
);
|
||||
std::env::set_var("GENARRATIVE_LLM_MODEL", "internal-text-model");
|
||||
std::env::set_var("APIMART_BASE_URL", "https://image.internal.example/v1");
|
||||
std::env::set_var("VECTOR_ENGINE_BASE_URL", "https://audio.internal.example");
|
||||
std::env::set_var("DASHSCOPE_SCENE_IMAGE_MODEL", "scene-model");
|
||||
std::env::set_var("DASHSCOPE_REFERENCE_IMAGE_MODEL", "reference-model");
|
||||
std::env::set_var("DASHSCOPE_COVER_IMAGE_MODEL", "cover-model");
|
||||
@@ -886,6 +966,10 @@ mod tests {
|
||||
assert_eq!(config.llm_base_url, "https://llm.internal.example/v1");
|
||||
assert_eq!(config.llm_model, "internal-text-model");
|
||||
assert_eq!(config.apimart_base_url, "https://image.internal.example/v1");
|
||||
assert_eq!(
|
||||
config.vector_engine_base_url,
|
||||
"https://audio.internal.example"
|
||||
);
|
||||
assert_eq!(config.dashscope_scene_image_model, "scene-model");
|
||||
assert_eq!(config.dashscope_reference_image_model, "reference-model");
|
||||
assert_eq!(config.dashscope_cover_image_model, "cover-model");
|
||||
@@ -900,6 +984,7 @@ mod tests {
|
||||
std::env::remove_var("GENARRATIVE_LLM_BASE_URL");
|
||||
std::env::remove_var("GENARRATIVE_LLM_MODEL");
|
||||
std::env::remove_var("APIMART_BASE_URL");
|
||||
std::env::remove_var("VECTOR_ENGINE_BASE_URL");
|
||||
std::env::remove_var("DASHSCOPE_SCENE_IMAGE_MODEL");
|
||||
std::env::remove_var("DASHSCOPE_REFERENCE_IMAGE_MODEL");
|
||||
std::env::remove_var("DASHSCOPE_COVER_IMAGE_MODEL");
|
||||
|
||||
Reference in New Issue
Block a user