Spaces:
Sleeping
Sleeping
import os | |
from typing import List, Dict | |
from config import Config | |
from custom_openai_client import CustomOpenAI | |
class DeepseekClient(CustomOpenAI): | |
def __init__(self, api_key=None, **kwargs): | |
print(f"[DEBUG] Starting DeepseekClient") | |
try: | |
api_key = api_key or Config.get_deepseek_key() | |
print(f"[DEBUG] Using API key: {api_key[:4]}...") # 最初の4文字のみ表示 | |
super().__init__( | |
deepseek_api_key=api_key, | |
**kwargs | |
) | |
print(f"[DEBUG] API client initialized successfully") | |
except Exception as e: | |
print(f"[DEBUG] Initialization error: {str(e)}") | |
raise | |
def create(self, messages: List[Dict[str, str]], model: str = None, **kwargs) -> str: | |
print(f"[DEBUG] Starting DeepseekClient::create") | |
print(f"[DEBUG] Model: {model or 'deepseek-chat'}") | |
print(f"[DEBUG] Messages: {[{k: v for k, v in m.items()} for m in messages]}") | |
try: | |
result = self.deepseek_chat(messages=messages, model=model, **kwargs) | |
if result: | |
print(f"[DEBUG] API request successful") | |
print(f"[DEBUG] Response: {result[:100]}...") # Show first 100 chars of response | |
return result | |
else: | |
raise Exception("No response from DeepSeek API") | |
except Exception as e: | |
print(f"[DEBUG] Error in create: {str(e)}") | |
raise | |