envrionrment var setup for the api key
Browse files- src/know_lang_bot/config.py +11 -2
src/know_lang_bot/config.py
CHANGED
@@ -4,6 +4,7 @@ from pydantic import Field, field_validator, ValidationInfo
|
|
4 |
from pathlib import Path
|
5 |
import fnmatch
|
6 |
from know_lang_bot.core.types import ModelProvider
|
|
|
7 |
|
8 |
class PathPatterns(BaseSettings):
|
9 |
include: List[str] = Field(
|
@@ -112,8 +113,15 @@ class LLMConfig(BaseSettings):
|
|
112 |
@classmethod
|
113 |
def validate_api_key(cls, v: Optional[str], info: ValidationInfo) -> Optional[str]:
|
114 |
"""Validate API key is present when required"""
|
115 |
-
if info.data['model_provider'] in [ModelProvider.OPENAI, ModelProvider.ANTHROPIC]
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
return v
|
118 |
|
119 |
class DBConfig(BaseSettings):
|
@@ -156,6 +164,7 @@ class AppConfig(BaseSettings):
|
|
156 |
)
|
157 |
|
158 |
llm: LLMConfig = Field(default_factory=LLMConfig)
|
|
|
159 |
db: DBConfig = Field(default_factory=DBConfig)
|
160 |
parser: ParserConfig = Field(default_factory=ParserConfig)
|
161 |
chat: ChatConfig = Field(default_factory=ChatConfig)
|
|
|
4 |
from pathlib import Path
|
5 |
import fnmatch
|
6 |
from know_lang_bot.core.types import ModelProvider
|
7 |
+
import os
|
8 |
|
9 |
class PathPatterns(BaseSettings):
|
10 |
include: List[str] = Field(
|
|
|
113 |
@classmethod
|
114 |
def validate_api_key(cls, v: Optional[str], info: ValidationInfo) -> Optional[str]:
|
115 |
"""Validate API key is present when required"""
|
116 |
+
if info.data['model_provider'] in [ModelProvider.OPENAI, ModelProvider.ANTHROPIC]:
|
117 |
+
if not v:
|
118 |
+
raise ValueError(f"API key required for {info.data['model_provider']}")
|
119 |
+
elif info.data['model_provider'] == ModelProvider.ANTHROPIC:
|
120 |
+
os.environ["ANTHROPIC_API_KEY"] = v
|
121 |
+
elif info.data['model_provider'] == ModelProvider.OPENAI:
|
122 |
+
import openai
|
123 |
+
openai.api_key = v
|
124 |
+
|
125 |
return v
|
126 |
|
127 |
class DBConfig(BaseSettings):
|
|
|
164 |
)
|
165 |
|
166 |
llm: LLMConfig = Field(default_factory=LLMConfig)
|
167 |
+
evaluator: LLMConfig = Field(default_factory=LLMConfig)
|
168 |
db: DBConfig = Field(default_factory=DBConfig)
|
169 |
parser: ParserConfig = Field(default_factory=ParserConfig)
|
170 |
chat: ChatConfig = Field(default_factory=ChatConfig)
|