This commit is contained in:
parent
29e53034bb
commit
d42c22c5ce
|
|
@ -91,7 +91,7 @@ async def run_analysis(
|
|||
research_depth=request.research_depth,
|
||||
deep_think_llm=request.deep_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,
|
||||
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")
|
||||
|
||||
# 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(
|
||||
default="https://api.openai.com/v1",
|
||||
description="OpenAI API Base URL (optional)"
|
||||
|
|
|
|||
|
|
@ -79,7 +79,12 @@ class TradingService:
|
|||
|
||||
try:
|
||||
# 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:
|
||||
os.environ["ALPHA_VANTAGE_API_KEY"] = alpha_vantage_api_key
|
||||
|
||||
|
|
@ -136,10 +141,12 @@ class TradingService:
|
|||
}
|
||||
|
||||
finally:
|
||||
# Clean up environment variables after request
|
||||
# Clean up environment variables after request
|
||||
if original_openai_key is not None:
|
||||
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"]
|
||||
|
||||
if original_alpha_key is not None:
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ const formSchema = z.object({
|
|||
deep_thinking_agent: z.string().min(1, "請選擇深層思維模型"),
|
||||
|
||||
// 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("")),
|
||||
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"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>OpenAI API Key(必填)</FormLabel>
|
||||
<FormLabel>OpenAI API Key(若伺服器已設定則選填)</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" placeholder="sk-..." {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
您的 OpenAI API Key(用於 LLM 推理)
|
||||
您的 OpenAI API Key(若未填寫將使用伺服器環境變數)
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
|
|||
Loading…
Reference in New Issue