This commit is contained in:
parent
29e53034bb
commit
d42c22c5ce
|
|
@ -91,7 +91,7 @@ async def run_analysis(
|
||||||
research_depth=request.research_depth,
|
research_depth=request.research_depth,
|
||||||
deep_think_llm=request.deep_think_llm,
|
deep_think_llm=request.deep_think_llm,
|
||||||
quick_think_llm=request.quick_think_llm,
|
quick_think_llm=request.quick_think_llm,
|
||||||
openai_api_key=request.openai_api_key,
|
openai_api_key=request.openai_api_key or "", # Pass empty string if None, service handles it
|
||||||
openai_base_url=request.openai_base_url,
|
openai_base_url=request.openai_base_url,
|
||||||
alpha_vantage_api_key=request.alpha_vantage_api_key,
|
alpha_vantage_api_key=request.alpha_vantage_api_key,
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class AnalysisRequest(BaseModel):
|
||||||
quick_think_llm: Optional[str] = Field(default="gpt-4o-mini", description="Quick thinking LLM model")
|
quick_think_llm: Optional[str] = Field(default="gpt-4o-mini", description="Quick thinking LLM model")
|
||||||
|
|
||||||
# API Configuration
|
# API Configuration
|
||||||
openai_api_key: str = Field(..., description="OpenAI API Key (required)", min_length=10)
|
openai_api_key: Optional[str] = Field(None, description="OpenAI API Key (optional if set on server)", min_length=0)
|
||||||
openai_base_url: Optional[str] = Field(
|
openai_base_url: Optional[str] = Field(
|
||||||
default="https://api.openai.com/v1",
|
default="https://api.openai.com/v1",
|
||||||
description="OpenAI API Base URL (optional)"
|
description="OpenAI API Base URL (optional)"
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,12 @@ class TradingService:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Set API keys for this request
|
# Set API keys for this request
|
||||||
os.environ["OPENAI_API_KEY"] = openai_api_key
|
if openai_api_key:
|
||||||
|
os.environ["OPENAI_API_KEY"] = openai_api_key
|
||||||
|
elif not os.environ.get("OPENAI_API_KEY"):
|
||||||
|
# If no key provided and no env var, this will fail later, but let's log it
|
||||||
|
logger.warning("No OpenAI API key provided in request or environment")
|
||||||
|
|
||||||
if alpha_vantage_api_key:
|
if alpha_vantage_api_key:
|
||||||
os.environ["ALPHA_VANTAGE_API_KEY"] = alpha_vantage_api_key
|
os.environ["ALPHA_VANTAGE_API_KEY"] = alpha_vantage_api_key
|
||||||
|
|
||||||
|
|
@ -136,10 +141,12 @@ class TradingService:
|
||||||
}
|
}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
# Clean up environment variables after request
|
||||||
# Clean up environment variables after request
|
# Clean up environment variables after request
|
||||||
if original_openai_key is not None:
|
if original_openai_key is not None:
|
||||||
os.environ["OPENAI_API_KEY"] = original_openai_key
|
os.environ["OPENAI_API_KEY"] = original_openai_key
|
||||||
elif "OPENAI_API_KEY" in os.environ:
|
elif openai_api_key and "OPENAI_API_KEY" in os.environ:
|
||||||
|
# Only delete if we set it (and there was no original key)
|
||||||
del os.environ["OPENAI_API_KEY"]
|
del os.environ["OPENAI_API_KEY"]
|
||||||
|
|
||||||
if original_alpha_key is not None:
|
if original_alpha_key is not None:
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ const formSchema = z.object({
|
||||||
deep_thinking_agent: z.string().min(1, "請選擇深層思維模型"),
|
deep_thinking_agent: z.string().min(1, "請選擇深層思維模型"),
|
||||||
|
|
||||||
// API Configuration
|
// API Configuration
|
||||||
openai_api_key: z.string().min(20, "請輸入有效的 OpenAI API Key"),
|
openai_api_key: z.string().optional().or(z.literal("")),
|
||||||
openai_base_url: z.string().url("請輸入有效的 URL").optional().or(z.literal("")),
|
openai_base_url: z.string().url("請輸入有效的 URL").optional().or(z.literal("")),
|
||||||
alpha_vantage_api_key: z.string().optional().or(z.literal("")),
|
alpha_vantage_api_key: z.string().optional().or(z.literal("")),
|
||||||
});
|
});
|
||||||
|
|
@ -294,12 +294,12 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
|
||||||
name="openai_api_key"
|
name="openai_api_key"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>OpenAI API Key(必填)</FormLabel>
|
<FormLabel>OpenAI API Key(若伺服器已設定則選填)</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input type="password" placeholder="sk-..." {...field} />
|
<Input type="password" placeholder="sk-..." {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
您的 OpenAI API Key(用於 LLM 推理)
|
您的 OpenAI API Key(若未填寫將使用伺服器環境變數)
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue