52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using LinkToolAddin.common;
|
|
using LinkToolAddin.host.llm.entity;
|
|
using LinkToolAddin.host.llm.entity.stream;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace LinkToolAddin.host.llm;
|
|
|
|
public class DmxApi : Llm
|
|
{
|
|
public string model { get; set; } = "gpt-4o";
|
|
public string temperature { get; set; }
|
|
public string top_p { get; set; }
|
|
public string max_tokens { get; set; }
|
|
public string app_id { get; set; }
|
|
public string api_key { get; set; }
|
|
public async IAsyncEnumerable<LlmStreamChat> SendChatStreamAsync(LlmJsonContent jsonContent)
|
|
{
|
|
jsonContent.Stream = true;
|
|
StringBuilder contentBuilder = new StringBuilder();
|
|
StringBuilder reasonBuilder = new StringBuilder();
|
|
await foreach (LlmStreamChat chunk in HttpRequest.PostWithStreamingResponseAsync(
|
|
"https://www.dmxapi.cn/v1/chat/completions",
|
|
JsonConvert.SerializeObject(jsonContent),
|
|
api_key))
|
|
{
|
|
contentBuilder.Append(chunk.Choices[0].Delta.Content);
|
|
reasonBuilder.Append(chunk.Choices[0].Delta.ResoningContent);
|
|
LlmStreamChat fullChunk = chunk;
|
|
fullChunk.Choices[0].Delta.Content = contentBuilder.ToString();
|
|
fullChunk.Choices[0].Delta.ResoningContent = reasonBuilder.ToString();
|
|
yield return fullChunk;
|
|
}
|
|
}
|
|
|
|
public IAsyncEnumerable<string> SendApplicationStreamAsync(string message)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Task<string> SendChatAsync(LlmJsonContent jsonContent)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Task<string> SendApplicationAsync(CommonInput commonInput)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
} |