Skip to content

Commit

Permalink
Refactor DifyClient to fix initialization and recursion issues
Browse files Browse the repository at this point in the history
- Modify __init__ method to properly set api_key and base_url
- Remove dependency on __getattr__ during initialization
- Ensure sdk is created after api_key and base_url are set
- Maintain backwards compatibility with config file loading
- Improve error handling for missing API key
- Retain conversation management functionality
  • Loading branch information
zlz3907 committed Oct 14, 2024
1 parent 33e954c commit 15b3ebf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="dify-api-python",
version="0.1.4",
version="0.1.5",
author="zlz3907",
author_email="zlz3907@gmail.com",
description="A Python client for the Dify API",
Expand Down
6 changes: 4 additions & 2 deletions src/dify_api_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class DifyClient:
def __init__(self, api_key=None, base_url=None, config_path=None):
if config_path or (not api_key and not base_url):
self._load_config(config_path)
else:
self.api_key = api_key
self.base_url = base_url or 'https://api.dify.ai/v1'

if not hasattr(self, 'api_key') or not self.api_key:
if not self.api_key:
raise ValueError("API_KEY is not set. Please provide it as a parameter or in the configuration file.")

self.base_url = base_url or getattr(self, 'base_url', 'https://api.dify.ai/v1')
self.sdk = DifySDK(self.api_key, self.base_url)
self.user_conversations = {}

Expand Down

0 comments on commit 15b3ebf

Please sign in to comment.