123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using Microsoft.AspNetCore.Http;
- using OASystem.Domain;
- using OpenAI.GPT3.Managers;
- using OpenAI.GPT3;
- using Org.BouncyCastle.Ocsp;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using OpenAI.GPT3.ObjectModels.RequestModels;
- using OpenAI.GPT3.ObjectModels;
- using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
- using System.IO;
- namespace OASystem.API.OAMethodLib.ChatGPT
- {
-
-
-
- public static class ChatGPTTools
- {
- private readonly static string _appKey = "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";
- private readonly static HttpClient _httpClient = new HttpClient { BaseAddress = new Uri("https://api.openai.com") };
-
-
-
-
-
- public static async Task<Result> Completions(string prompt)
- {
- var result = new Result();
- string url = string.Format("{0}", "/v1/completions");
- var reqData = new CompletionCreateRequest()
- {
- Prompt = prompt,
- Temperature = 0.3f,
-
- TopP =1f,
- N = 1,
- Stream = false,
- Echo = false,
-
- MaxTokens = 1024,
- };
- return await PostChatGPT(url, reqData);
- }
-
-
-
-
-
-
- public static async Task<Result> PostChatGPT(string url, CompletionCreateRequest reqData)
- {
- Result result = new Result();
- OpenAIService service = new OpenAIService(new OpenAiOptions() { ApiKey = _appKey });
- var res = await service.Completions.CreateCompletion(reqData, Models.TextDavinciV3);
- if (res.Successful)
- {
- result.Code = 0;
- result.Data = new { Text = res.Choices.FirstOrDefault().Text };
- }
- else result.Msg = "访问失败!";
- return result;
- }
- }
- }
|