45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using LinkToolAddin.common;
|
|
using LinkToolAddin.host.llm.entity;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace LinkToolAddin.host.llm;
|
|
|
|
public class Bailian : Llm
|
|
{
|
|
public string model { get; set; } = "qwen-max";
|
|
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 IAsyncEnumerable<string> SendChatStreamAsync(string message)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public IAsyncEnumerable<string> SendApplicationStreamAsync(string message)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public async Task<string> SendChatAsync(LlmJsonContent jsonContent)
|
|
{
|
|
string url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
|
|
string responseBody = await HttpRequest.SendPostRequestAsync(url, JsonConvert.SerializeObject(jsonContent), api_key);
|
|
LlmChat result = JsonConvert.DeserializeObject<LlmChat>(responseBody);
|
|
return result.Choices[0].Message.Content;
|
|
}
|
|
|
|
public async Task<string> SendApplicationAsync(CommonInput commonInput)
|
|
{
|
|
string url = $"https://dashscope.aliyuncs.com/api/v1/apps/{app_id}/completion";
|
|
string responseBody = await HttpRequest.SendPostRequestAsync(url, JsonConvert.SerializeObject(commonInput), api_key);
|
|
ApplicationOutput result = JsonConvert.DeserializeObject<ApplicationOutput>(responseBody);
|
|
return responseBody;
|
|
}
|
|
} |