IDoubaoService.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. namespace OASystem.API.OAMethodLib.DoubaoAPI
  2. {
  3. public enum ReasoningEffort
  4. {
  5. Minimal,
  6. Low,
  7. Medium,
  8. High
  9. }
  10. public class DouBaoChatMessage
  11. {
  12. public DouBaoRole Role { get; set; }
  13. public string Content { get; set; }
  14. }
  15. public enum DouBaoRole
  16. {
  17. system,
  18. user,
  19. assistant
  20. }
  21. public class CompleteChatOptions
  22. {
  23. public thinkingOptions ThinkingOptions { get; set; } = new thinkingOptions()
  24. {
  25. IsThinking = false,
  26. ReasoningEffort = ReasoningEffort.Minimal
  27. };
  28. }
  29. public class thinkingOptions
  30. {
  31. public bool IsThinking { get; set; } = false;
  32. public ReasoningEffort ReasoningEffort { get; set; } = ReasoningEffort.Minimal;
  33. }
  34. public class DoubaoResponse
  35. {
  36. public string id { get; set; }
  37. public string @object { get; set; }
  38. public long created { get; set; }
  39. public string model { get; set; }
  40. public string service_tier { get; set; }
  41. public List<Choice> choices { get; set; }
  42. public Usage usage { get; set; }
  43. }
  44. public class Choice
  45. {
  46. public int index { get; set; }
  47. public string finish_reason { get; set; }
  48. public object logprobs { get; set; } // 可以是 null 或者详细概率结构
  49. public Message message { get; set; }
  50. }
  51. public class Message
  52. {
  53. public string role { get; set; }
  54. public string content { get; set; }
  55. public string reasoning_content { get; set; } // 豆包特有字段
  56. }
  57. public class Usage
  58. {
  59. public int completion_tokens { get; set; }
  60. public int prompt_tokens { get; set; }
  61. public int total_tokens { get; set; }
  62. public TokenDetails prompt_tokens_details { get; set; }
  63. public TokenDetails completion_tokens_details { get; set; }
  64. }
  65. public class TokenDetails
  66. {
  67. public int reasoning_tokens { get; set; }
  68. }
  69. public class DoubaoFileResponse
  70. {
  71. public string id { get; set; }
  72. public string @object { get; set; }
  73. public long bytes { get; set; }
  74. public long created_at { get; set; }
  75. public string filename { get; set; }
  76. public string purpose { get; set; }
  77. }
  78. public interface IDoubaoService
  79. {
  80. Task<string> CompleteChatAsync(List<DouBaoChatMessage> messages, CompleteChatOptions? options = null);
  81. Task<string> CompleteMultimodalChatAsync(List<DoubaoMultimodalChatMessage> messages, CompleteMultimodalChatOptions? options);
  82. Task<DoubaoFileResponse> UploadFileAsync(Stream fileStream, string fileName, string purpose = "user_data");
  83. Task<DoubaoFileListResponse> ListFilesAsync();
  84. Task<bool> DeleteFileAsync(string fileId);
  85. }
  86. public class DoubaoFileListResponse
  87. {
  88. public string @object { get; set; }
  89. public List<DoubaoFileResponse> data { get; set; }
  90. }
  91. #region 多模态
  92. // 重命名:DoubaoContentItem → DoubaoMultimodalContentItem
  93. public class DoubaoMultimodalContentItem
  94. {
  95. [JsonProperty("type")]
  96. // 合法值:input_text(文本)/ input_image(图片)/ input_file(文件)
  97. public string Type { get; set; }
  98. [JsonProperty("text", NullValueHandling = NullValueHandling.Ignore)]
  99. public string Text { get; set; }
  100. [JsonProperty("image_url", NullValueHandling = NullValueHandling.Ignore)]
  101. public DoubaoMultimodalImageUrl ImageUrl { get; set; }
  102. // 补充:文件类型需要的file_id字段
  103. [JsonProperty("file_id", NullValueHandling = NullValueHandling.Ignore)]
  104. public string FileId { get; set; }
  105. }
  106. // 重命名:DoubaoImageUrl → DoubaoMultimodalImageUrl
  107. public class DoubaoMultimodalImageUrl
  108. {
  109. [JsonProperty("url")]
  110. public string Url { get; set; }
  111. }
  112. // 重命名:DoubaoMultimodalChatMessage(原已带Multimodal,保持但字段适配新类)
  113. public class DoubaoMultimodalChatMessage
  114. {
  115. public string Role { get; set; } // 值必须是 user/system/assistant(小写)
  116. public List<DoubaoMultimodalContentItem> Content { get; set; } = new List<DoubaoMultimodalContentItem>();
  117. }
  118. // 重命名:CompleteChatOptions → CompleteMultimodalChatOptions
  119. public class CompleteMultimodalChatOptions
  120. {
  121. public DoubaoMultimodalThinkingOptions ThinkingOptions { get; set; } = new DoubaoMultimodalThinkingOptions();
  122. public float Temperature { get; set; } = 0.7f;
  123. public int? MaxOutputTokens { get; set; }
  124. public string PreviousResponseId { get; set; }
  125. public long? ExpireAt { get; set; }
  126. }
  127. // 重命名:ThinkingOptions → DoubaoMultimodalThinkingOptions
  128. public class DoubaoMultimodalThinkingOptions
  129. {
  130. public bool IsThinking { get; set; }
  131. public string ReasoningEffort { get; set; } = "medium";
  132. }
  133. // 重命名:DoubaoSetting → DoubaoMultimodalSetting
  134. public class DoubaoMultimodalSetting
  135. {
  136. public string ApiKey { get; set; }
  137. public string EndpointId { get; set; }
  138. public string BaseAddress { get; set; }
  139. }
  140. // 重命名:DoubaoResponse → DoubaoMultimodalResponse
  141. public class DoubaoMultimodalResponse
  142. {
  143. [JsonProperty("choices")]
  144. public List<DoubaoMultimodalChoice> Choices { get; set; } = new List<DoubaoMultimodalChoice>();
  145. }
  146. // 重命名:DoubaoChoice → DoubaoMultimodalChoice
  147. public class DoubaoMultimodalChoice
  148. {
  149. [JsonProperty("message")]
  150. public DoubaoMultimodalResponseMessage Message { get; set; }
  151. }
  152. // 重命名:DoubaoResponseMessage → DoubaoMultimodalResponseMessage
  153. public class DoubaoMultimodalResponseMessage
  154. {
  155. [JsonProperty("content")]
  156. public List<DoubaoMultimodalContentItem> Content { get; set; }
  157. }
  158. #endregion
  159. }