diff --git a/mem0/llms/litellm.py b/mem0/llms/litellm.py index d5896ff80b..74f06027a2 100644 --- a/mem0/llms/litellm.py +++ b/mem0/llms/litellm.py @@ -1,4 +1,5 @@ import json +import os from typing import Dict, List, Optional try: @@ -16,7 +17,8 @@ def __init__(self, config: Optional[BaseLlmConfig] = None): if not self.config.model: self.config.model = "gpt-4o-mini" - + if not self.config.api_key: + self.config.api_key = os.environ["OPENAI_API_KEY"] def _parse_response(self, response, tools): """ Process the response based on whether tools are used or not. @@ -75,6 +77,7 @@ def generate_response( "temperature": self.config.temperature, "max_tokens": self.config.max_tokens, "top_p": self.config.top_p, + "api_key": self.config.api_key, } if response_format: params["response_format"] = response_format