1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using OpenAI.GPT3;
- using OpenAI.GPT3.Managers;
- using OpenAI.GPT3.ObjectModels;
- using OpenAI.GPT3.ObjectModels.RequestModels;
- 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;
- }
- }
- }
|