mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-29 11:35:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d15ef08214 |
@@ -69,6 +69,7 @@ services:
|
||||
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
- ./certbot/conf:/etc/letsencrypt:ro
|
||||
- ./certbot/www:/var/www/certbot:ro
|
||||
- ./auth:/etc/nginx/auth:ro
|
||||
depends_on:
|
||||
- eagle
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -7,7 +7,11 @@ object ApiKeys {
|
||||
private val apiKeyFilePath =
|
||||
"src/main/scala/net/eagle0/common/llm_integration/api_keys.txt"
|
||||
|
||||
// These must have valid values set in api_keys.txt
|
||||
// Environment variable names
|
||||
private val openAIEnvVar = "OPENAI_API_KEY"
|
||||
private val anthropicEnvVar = "ANTHROPIC_API_KEY"
|
||||
|
||||
// File key names
|
||||
private val openAIKeyName = "openai_api_key"
|
||||
private val anthropicKeyName = "anthropic_api_key"
|
||||
|
||||
@@ -23,25 +27,31 @@ object ApiKeys {
|
||||
)
|
||||
}.toMap
|
||||
}.getOrElse {
|
||||
throw new ApiKeyException(
|
||||
"Failed to read api_keys.txt. Make sure you have copied api_keys_template.txt to api_keys.txt and set the keys."
|
||||
)
|
||||
Map.empty // Return empty map if file doesn't exist; we'll check env vars
|
||||
}
|
||||
|
||||
private val dictionary = readDictionary()
|
||||
|
||||
private def getKey(key: String): String =
|
||||
dictionary.get(key) match {
|
||||
case None =>
|
||||
throw new ApiKeyException(s"$key not found")
|
||||
case Some(value) if value.startsWith("your_") =>
|
||||
throw new ApiKeyException(
|
||||
s"API key for $key is not set. Please set it in $apiKeyFilePath."
|
||||
)
|
||||
case Some(value) => value
|
||||
private def getKey(key: String, envVar: String): String =
|
||||
// First check environment variable
|
||||
Option(System.getenv(envVar)).filter(_.nonEmpty) match {
|
||||
case Some(value) => value
|
||||
case None =>
|
||||
// Fall back to file-based dictionary
|
||||
dictionary.get(key) match {
|
||||
case None =>
|
||||
throw new ApiKeyException(
|
||||
s"$key not found. Set $envVar environment variable or add to $apiKeyFilePath."
|
||||
)
|
||||
case Some(value) if value.startsWith("your_") =>
|
||||
throw new ApiKeyException(
|
||||
s"API key for $key is not set. Set $envVar environment variable or update $apiKeyFilePath."
|
||||
)
|
||||
case Some(value) => value
|
||||
}
|
||||
}
|
||||
|
||||
lazy val openAI: String = getKey(openAIKeyName)
|
||||
lazy val openAI: String = getKey(openAIKeyName, openAIEnvVar)
|
||||
|
||||
lazy val anthropic: String = getKey(anthropicKeyName)
|
||||
lazy val anthropic: String = getKey(anthropicKeyName, anthropicEnvVar)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user