ChatResponse.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.lingyue.ai.dto;
  2. import lombok.Data;
  3. import java.util.List;
  4. /**
  5. * DeepSeek Chat API 响应
  6. *
  7. * @author lingyue
  8. * @since 2026-01-15
  9. */
  10. @Data
  11. public class ChatResponse {
  12. /**
  13. * 响应ID
  14. */
  15. private String id;
  16. /**
  17. * 对象类型
  18. */
  19. private String object;
  20. /**
  21. * 创建时间戳
  22. */
  23. private Long created;
  24. /**
  25. * 使用的模型
  26. */
  27. private String model;
  28. /**
  29. * 选择列表
  30. */
  31. private List<Choice> choices;
  32. /**
  33. * Token 使用统计
  34. */
  35. private Usage usage;
  36. /**
  37. * 获取第一个回复内容
  38. */
  39. public String getFirstContent() {
  40. if (choices != null && !choices.isEmpty()) {
  41. Choice choice = choices.get(0);
  42. if (choice.getMessage() != null) {
  43. return choice.getMessage().getContent();
  44. }
  45. }
  46. return null;
  47. }
  48. @Data
  49. public static class Choice {
  50. private Integer index;
  51. private ChatMessage message;
  52. private String finish_reason;
  53. }
  54. @Data
  55. public static class Usage {
  56. private Integer prompt_tokens;
  57. private Integer completion_tokens;
  58. private Integer total_tokens;
  59. }
  60. }