Skip to content

Commit 90bea7c

Browse files
authored
Fix import statement for dashscope
Environment variables (such as os.environ["DASHSCOPE_API_KEY"]) must be set before the dashscope SDK is imported and initialized. If dashscope has been imported or initialized before setting the environment variable, the SDK may have cached the environment variable and setting it later will not take effect.
1 parent ef8ea38 commit 90bea7c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

hello_agents/memory/embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ def __init__(self, model_name: str = "text-embedding-v3", api_key: Optional[str]
168168

169169
def _init_client(self):
170170
try:
171-
import dashscope # noqa: F401
172171
if self.api_key:
173172
# 将统一命名的 API Key 注入到 SDK 期望的位置
174173
os.environ["DASHSCOPE_API_KEY"] = self.api_key
174+
import dashscope # noqa: F401
175175
except ImportError:
176176
raise ImportError("请安装 dashscope: pip install dashscope")
177177

0 commit comments

Comments
 (0)