Skip to content

Commit 9519d71

Browse files
authored
Fix/Loading .env from the current working directory (#695)
Co-authored-by: alcholiclg <ligongshengzju@foxmail.com>
1 parent 7e9d632 commit 9519d71

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

ms_agent/tools/search/search_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_rewrite_prompt(self) -> str:
8585
f'\n现在,基于以上所有原则和范例,为用户的原始输入"{self.user_prompt}"生成最终的搜索请求。'
8686
f'\n1. 将你构建的、最优的英文查询语句填入query参数。'
8787
f'\n2. num_results参数的值必须在1到25之间,请选择一个适合问题复杂程度的值,比如10。'
88-
f'\n3. 必须严格按照以下JSON格式模板返回结果: {self.get_args_template()}')
88+
f'\n3. 必须符合以下arguments格式: {self.get_args_template()}')
8989

9090
def create_request(self,
9191
search_request_d: Dict[str, Any]) -> ArxivSearchRequest:

ms_agent/tools/search_engine.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from typing import Any, Dict
33

4+
from dotenv import load_dotenv
45
from ms_agent.config.env import Env
56
from ms_agent.tools.exa import ExaSearch
67
from ms_agent.tools.search.arxiv import ArxivSearch
@@ -30,6 +31,11 @@ def load_base_config(file_path: str) -> Dict[str, Any]:
3031
import yaml
3132
with open(file_path, 'r') as file:
3233
config = yaml.safe_load(file)
34+
35+
# Load environment variables from .env file if it exists
36+
if not load_dotenv(os.path.join(os.getcwd(), '.env')):
37+
Env.load_env()
38+
3339
return process_dict(config)
3440

3541

@@ -69,8 +75,6 @@ def replace_env_vars(value: str) -> str:
6975
if not isinstance(value, str):
7076
return value
7177

72-
Env.load_env()
73-
7478
if value.startswith('$'):
7579
env_var = value[1:]
7680
return os.getenv(env_var, None)

projects/deep_research/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pip install -r requirements/research.txt
6060

6161
1. If you're using Exa or SerpApi, make sure your .env file includes the following configuration settings:
6262
```bash
63-
cp .env.example ../../.env
63+
cp .env.example .env
6464

6565
# Then, edit the `.env` file to include your API keys:
6666
EXA_API_KEY=xxx

0 commit comments

Comments
 (0)