| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- namespace OASystem.API.OAMethodLib.DoubaoAPI
- {
- public enum ReasoningEffort
- {
- Minimal,
- Low,
- Medium,
- High
- }
- public class DouBaoChatMessage
- {
- public DouBaoRole Role { get; set; }
- public string Content { get; set; }
- }
- public enum DouBaoRole
- {
- system,
- user,
- assistant
- }
- public class CompleteChatOptions
- {
- public thinkingOptions ThinkingOptions { get; set; } = new thinkingOptions()
- {
- IsThinking = false,
- ReasoningEffort = ReasoningEffort.Minimal
- };
- }
- public class thinkingOptions
- {
- public bool IsThinking { get; set; } = false;
- public ReasoningEffort ReasoningEffort { get; set; } = ReasoningEffort.Minimal;
- }
- public class DoubaoResponse
- {
- public string id { get; set; }
- public string @object { get; set; }
- public long created { get; set; }
- public string model { get; set; }
- public string service_tier { get; set; }
- public List<Choice> choices { get; set; }
- public Usage usage { get; set; }
- }
- public class Choice
- {
- public int index { get; set; }
- public string finish_reason { get; set; }
- public object logprobs { get; set; } // 可以是 null 或者详细概率结构
- public Message message { get; set; }
- }
- public class Message
- {
- public string role { get; set; }
- public string content { get; set; }
- public string reasoning_content { get; set; } // 豆包特有字段
- }
- public class Usage
- {
- public int completion_tokens { get; set; }
- public int prompt_tokens { get; set; }
- public int total_tokens { get; set; }
- public TokenDetails prompt_tokens_details { get; set; }
- public TokenDetails completion_tokens_details { get; set; }
- }
- public class TokenDetails
- {
- public int reasoning_tokens { get; set; }
- }
- public class DoubaoFileResponse
- {
- public string id { get; set; }
- public string @object { get; set; }
- public long bytes { get; set; }
- public long created_at { get; set; }
- public string filename { get; set; }
- public string purpose { get; set; }
- }
- public interface IDoubaoService
- {
- Task<string> CompleteChatAsync(List<DouBaoChatMessage> messages, CompleteChatOptions? options = null);
- Task<string> CompleteMultimodalChatAsync(List<DoubaoMultimodalChatMessage> messages, CompleteMultimodalChatOptions? options);
- Task<DoubaoFileResponse> UploadFileAsync(Stream fileStream, string fileName, string purpose = "fine-tune");
- Task<DoubaoFileListResponse> ListFilesAsync();
- Task<bool> DeleteFileAsync(string fileId);
- }
- public class DoubaoFileListResponse
- {
- public string @object { get; set; }
- public List<DoubaoFileResponse> data { get; set; }
- }
- #region 多模态
- // 重命名:DoubaoContentItem → DoubaoMultimodalContentItem
- public class DoubaoMultimodalContentItem
- {
- [JsonProperty("type")]
- // 合法值:input_text(文本)/ input_image(图片)/ input_file(文件)
- public string Type { get; set; }
- [JsonProperty("text", NullValueHandling = NullValueHandling.Ignore)]
- public string Text { get; set; }
- [JsonProperty("image_url", NullValueHandling = NullValueHandling.Ignore)]
- public DoubaoMultimodalImageUrl ImageUrl { get; set; }
- // 补充:文件类型需要的file_id字段
- [JsonProperty("file_id", NullValueHandling = NullValueHandling.Ignore)]
- public string FileId { get; set; }
- }
- // 重命名:DoubaoImageUrl → DoubaoMultimodalImageUrl
- public class DoubaoMultimodalImageUrl
- {
- [JsonProperty("url")]
- public string Url { get; set; }
- }
- // 重命名:DoubaoMultimodalChatMessage(原已带Multimodal,保持但字段适配新类)
- public class DoubaoMultimodalChatMessage
- {
- public string Role { get; set; } // 值必须是 user/system/assistant(小写)
- public List<DoubaoMultimodalContentItem> Content { get; set; } = new List<DoubaoMultimodalContentItem>();
- }
- // 重命名:CompleteChatOptions → CompleteMultimodalChatOptions
- public class CompleteMultimodalChatOptions
- {
- public DoubaoMultimodalThinkingOptions ThinkingOptions { get; set; } = new DoubaoMultimodalThinkingOptions();
- public float Temperature { get; set; } = 0.7f;
- public int? MaxOutputTokens { get; set; }
- public string PreviousResponseId { get; set; }
- public long? ExpireAt { get; set; }
- }
- // 重命名:ThinkingOptions → DoubaoMultimodalThinkingOptions
- public class DoubaoMultimodalThinkingOptions
- {
- public bool IsThinking { get; set; }
- public string ReasoningEffort { get; set; } = "medium";
- }
- // 重命名:DoubaoSetting → DoubaoMultimodalSetting
- public class DoubaoMultimodalSetting
- {
- public string ApiKey { get; set; }
- public string EndpointId { get; set; }
- public string BaseAddress { get; set; }
- }
- // 重命名:DoubaoResponse → DoubaoMultimodalResponse
- public class DoubaoMultimodalResponse
- {
- [JsonProperty("choices")]
- public List<DoubaoMultimodalChoice> Choices { get; set; } = new List<DoubaoMultimodalChoice>();
- }
- // 重命名:DoubaoChoice → DoubaoMultimodalChoice
- public class DoubaoMultimodalChoice
- {
- [JsonProperty("message")]
- public DoubaoMultimodalResponseMessage Message { get; set; }
- }
- // 重命名:DoubaoResponseMessage → DoubaoMultimodalResponseMessage
- public class DoubaoMultimodalResponseMessage
- {
- [JsonProperty("content")]
- public List<DoubaoMultimodalContentItem> Content { get; set; }
- }
- #endregion
- }
|