File size: 1,496 Bytes
6c4292b
46e66e9
6c4292b
2cf6258
6c4292b
2cf6258
af01c91
46e66e9
2cf6258
 
 
 
 
 
 
 
 
 
 
46e66e9
 
 
 
2cf6258
46e66e9
 
 
 
 
 
2cf6258
 
 
46e66e9
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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