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 Infrastructure;
|
||||
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.Completions;
|
||||
|
||||
@ -14,6 +18,9 @@ namespace ARW.Admin.WebApi.Controllers.Business.Api.ChatGPT
|
||||
[Route("api/[controller]")]
|
||||
public class ChatGPTController : BaseController
|
||||
{
|
||||
const string OPENAPI_TOKEN = "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";//输入自己的api-key
|
||||
|
||||
|
||||
private readonly IChatGPTLogService _ChatGPTLogService;
|
||||
|
||||
public ChatGPTController(IChatGPTLogService chatGPTLogService)
|
||||
@ -37,34 +44,33 @@ namespace ARW.Admin.WebApi.Controllers.Business.Api.ChatGPT
|
||||
/// 请求ChatGPT接口
|
||||
/// </summary>
|
||||
[HttpPost("getChatGPT")]
|
||||
public IActionResult GetChatGPT([FromBody] CahtGPTDto parm)
|
||||
public async Task<IActionResult> GetChatGPT([FromBody] CahtGPTDto parm)
|
||||
{
|
||||
return SUCCESS("你好!我是一个语言模型。");
|
||||
//return SUCCESS("你好!我是一个语言模型。");
|
||||
|
||||
//你的apiKey
|
||||
string apiKey = "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";
|
||||
//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)
|
||||
OpenAIService service = new OpenAIService(new OpenAiOptions() { ApiKey = OPENAPI_TOKEN });
|
||||
CompletionCreateRequest createRequest = new CompletionCreateRequest()
|
||||
{
|
||||
foreach (var item in result.Result.Completions)
|
||||
TopP = 1,
|
||||
Prompt = parm.Content,
|
||||
Temperature = 0.3f,
|
||||
MaxTokens = 1000
|
||||
};
|
||||
|
||||
var res = await service.Completions.CreateCompletion(createRequest, Models.TextDavinciV3);
|
||||
|
||||
if (res.Successful)
|
||||
{
|
||||
answer = item.Text;
|
||||
}
|
||||
return SUCCESS(answer);
|
||||
var ss = res.Choices.FirstOrDefault().Text;
|
||||
//Console.WriteLine(ss);
|
||||
|
||||
return SUCCESS(ss);
|
||||
}
|
||||
else
|
||||
{
|
||||
return SUCCESS("Not found");
|
||||
return SUCCESS(res.Error);
|
||||
}
|
||||
|
||||
return SUCCESS("已读");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user