fix:
This commit is contained in:
parent
d3d65603ac
commit
133e5cd4e8
@ -3,6 +3,10 @@ using ARW.Model.Chat.ChatGPT;
|
|||||||
using ARW.Service.Business.IBusinessService.Chat;
|
using ARW.Service.Business.IBusinessService.Chat;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using OpenAI.GPT3.Managers;
|
||||||
|
using OpenAI.GPT3.ObjectModels.RequestModels;
|
||||||
|
using OpenAI.GPT3.ObjectModels;
|
||||||
|
using OpenAI.GPT3;
|
||||||
using OpenAI_API;
|
using OpenAI_API;
|
||||||
using OpenAI_API.Completions;
|
using OpenAI_API.Completions;
|
||||||
|
|
||||||
@ -14,6 +18,9 @@ namespace ARW.Admin.WebApi.Controllers.Business.Api.ChatGPT
|
|||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class ChatGPTController : BaseController
|
public class ChatGPTController : BaseController
|
||||||
{
|
{
|
||||||
|
const string OPENAPI_TOKEN = "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";//输入自己的api-key
|
||||||
|
|
||||||
|
|
||||||
private readonly IChatGPTLogService _ChatGPTLogService;
|
private readonly IChatGPTLogService _ChatGPTLogService;
|
||||||
|
|
||||||
public ChatGPTController(IChatGPTLogService chatGPTLogService)
|
public ChatGPTController(IChatGPTLogService chatGPTLogService)
|
||||||
@ -28,7 +35,7 @@ namespace ARW.Admin.WebApi.Controllers.Business.Api.ChatGPT
|
|||||||
public async Task<IActionResult> GetChatGPTLog([FromQuery] ChatGPTQueryDto parm)
|
public async Task<IActionResult> GetChatGPTLog([FromQuery] ChatGPTQueryDto parm)
|
||||||
{
|
{
|
||||||
if (parm.UserGuId == 0) throw new CustomException("请传用户的Guid");
|
if (parm.UserGuId == 0) throw new CustomException("请传用户的Guid");
|
||||||
var list = await _ChatGPTLogService.GetChatGPTLogList(parm);
|
var list = await _ChatGPTLogService.GetChatGPTLogList(parm);
|
||||||
|
|
||||||
return SUCCESS(list);
|
return SUCCESS(list);
|
||||||
}
|
}
|
||||||
@ -37,34 +44,33 @@ namespace ARW.Admin.WebApi.Controllers.Business.Api.ChatGPT
|
|||||||
/// 请求ChatGPT接口
|
/// 请求ChatGPT接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpPost("getChatGPT")]
|
[HttpPost("getChatGPT")]
|
||||||
public IActionResult GetChatGPT([FromBody] CahtGPTDto parm)
|
public async Task<IActionResult> GetChatGPT([FromBody] CahtGPTDto parm)
|
||||||
{
|
{
|
||||||
return SUCCESS("你好!我是一个语言模型。");
|
//return SUCCESS("你好!我是一个语言模型。");
|
||||||
|
|
||||||
//你的apiKey
|
OpenAIService service = new OpenAIService(new OpenAiOptions() { ApiKey = OPENAPI_TOKEN });
|
||||||
string apiKey = "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";
|
CompletionCreateRequest createRequest = new CompletionCreateRequest()
|
||||||
//string apiKey = "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";
|
|
||||||
string answer = string.Empty;
|
|
||||||
var openai = new OpenAIAPI(apiKey);
|
|
||||||
CompletionRequest completion = new CompletionRequest();
|
|
||||||
completion.Prompt = parm.Content;
|
|
||||||
completion.Model = OpenAI_API.Models.Model.DavinciText;
|
|
||||||
completion.MaxTokens = 4000;
|
|
||||||
var result = openai.Completions.CreateCompletionAsync(completion);
|
|
||||||
if (result != null)
|
|
||||||
{
|
{
|
||||||
foreach (var item in result.Result.Completions)
|
TopP = 1,
|
||||||
{
|
Prompt = parm.Content,
|
||||||
answer = item.Text;
|
Temperature = 0.3f,
|
||||||
}
|
MaxTokens = 1000
|
||||||
return SUCCESS(answer);
|
};
|
||||||
|
|
||||||
|
var res = await service.Completions.CreateCompletion(createRequest, Models.TextDavinciV3);
|
||||||
|
|
||||||
|
if (res.Successful)
|
||||||
|
{
|
||||||
|
var ss = res.Choices.FirstOrDefault().Text;
|
||||||
|
//Console.WriteLine(ss);
|
||||||
|
|
||||||
|
return SUCCESS(ss);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return SUCCESS("Not found");
|
return SUCCESS(res.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS("已读");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user