import { Injectable } from '@angular/core';
import axios from 'axios';

@Injectable({
  providedIn: 'root' // 全局提供
})
export class DeepSeekService {
  private readonly API_KEY = 'your-api-key';
  private readonly API_URL = 'https://api.deepseek.com/v1/chat/completions';

  async getAIResponse(messages: Array<{ role: string; content: string }>): Promise<string> {
    try {
      const response = await axios.post(
        this.API_URL,
        { model: 'deepseek-chat', messages },
        { headers: { Authorization: `Bearer ${this.API_KEY}` } }
      );
      return response.data.choices[0]?.message?.content || '无法生成回答';
    } catch (error) {
      console.error('API 调用失败:', error);
      return '服务暂时不可用';
    }
  }
}