Skip to content

Commit

Permalink
✨ refactor: update current_env variable if it is empty
Browse files Browse the repository at this point in the history
- update the current_env variable to an empty dictionary if it is empty
  • Loading branch information
sudoskys committed Apr 17, 2024
1 parent 529a181 commit 2789f02
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ config_dir/*.db
config_dir/*.pem
config_dir/*.secret/
/.pdm-python
/.montydb/
/.snapshot/
6 changes: 4 additions & 2 deletions llmkira/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# @Time : 2023/7/10 下午9:42
import os
import pathlib
from typing import Optional

from dotenv import load_dotenv
Expand All @@ -27,8 +28,9 @@ def check_client_dsn(dsn):

def check_client(self):
if self.dsn is None:
self.dsn = os.getenv("ELARA_DSN", "elara.db")
self.client = ElaraClientAsyncWrapper(self.dsn)
pathlib.Path().cwd().joinpath(".cache").mkdir(exist_ok=True)
self.dsn = pathlib.Path().cwd().joinpath(".cache") / "elara.db"
self.client = ElaraClientAsyncWrapper(str(self.dsn))
logger.debug(f"🍩 ElaraClientWrapper Loaded --dsn {self.dsn}")
return True

Expand Down
3 changes: 2 additions & 1 deletion llmkira/extra/plugins/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SearchTool(BaseTool):

silent: bool = False
function: Union[Tool, Type[BaseModel]] = Search
require_auth: bool = True
keywords: list = [
"怎么",
"How",
Expand Down Expand Up @@ -189,7 +190,7 @@ async def run(
"""

_set = Search.model_validate(arg)
_search_result = search_on_serper(
_search_result = await search_on_serper(
search_sentence=_set.keywords,
api_key=env.get("serper_api_key"),
)
Expand Down
2 changes: 2 additions & 0 deletions llmkira/kv_manager/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ async def set_env(
current_env = {}
if update:
current_env = await self.read_env()
if not current_env:
current_env = {}
if isinstance(env_value, str):
env_map = parse_env_string(env_value)
elif isinstance(env_value, dict):
Expand Down

0 comments on commit 2789f02

Please sign in to comment.