예제 #1
0
        // get summary and prepare generated reply to sender with confirmation
        static async Task cmdGetSummaryAsync(string textSource)
        {
            //  tl; dr:
            // initiate openai
            OpenAIAPI api    = new OpenAIAPI(new APIAuthentication(_oiKey));
            var       result = await api.Completions.CreateCompletionAsync(prompt : textSource + " tl;dr: ", temperature : 0.3, top_p : 1, frequencyPenalty : 0, presencePenalty : 0);

            var resultString = Regex.Replace(result.ToString(), @"^\s+$[\r\n]*", string.Empty, RegexOptions.Multiline);
            // openai response
            //  Console.WriteLine($"\t{resultString}");
            string prepReplyPrompt = "You got a " + _overallSentiment + " mail: " + resultString + ". Preparing response..";

            await SynthesisToSpeakerAsync(prepReplyPrompt);

            string txtContext = "This is a human friendly email generator responding to " + _overallSentiment + " topics.";

            txtContext += "Sender email: Do you know how to solve the project issue? I am in rush and have no ideea how to solve it. Please help me.  ";
            txtContext += "Seed words: solve , project issue, rush, no ideea, solve it, help";
            txtContext += "Reply Email: Ok, I'll look into it as soon as possible. No stress is necessary, we got this under control. ";
            txtContext += "Sender email:" + _userMails;
            txtContext += "Seed words:" + strKeyPhrases;
            txtContext += "Reply Email:";
            var email_result = await api.Completions.CreateCompletionAsync(txtContext, temperature : 0.8, max_tokens : 40, top_p : 1, frequencyPenalty : 0, presencePenalty : 0, stopSequences : "Human, AI");

            _prepEmail = email_result.ToString();
            string prepGeneratedEmail = "Here is my reply: \n" + email_result + ". \nSay Send, Next or Mail to Open Outlook!";

            Console.WriteLine($"\n\t{prepGeneratedEmail}");
            await SynthesisToSpeakerAsync(prepGeneratedEmail);

            var    speechConfig = SpeechConfig.FromSubscription(_stKey, _stRegion);
            string myRequest    = await FromMic(speechConfig);
        }
예제 #2
0
        private void Awake()
        {
            Instance = this;

            if (!EngineSO)
            {
                Debug.LogError("No EngineSO set. To create a new EngineSO, go to Assets>Create>ScriptableObjects>Open AI Engine");
                return;
            }

            if (string.IsNullOrEmpty(EngineSO.ApiKey))
            {
                Debug.LogError("Your ApiKey was not set. You can get your ApiKey from https://beta.openai.com/docs/developer-quickstart/your-api-keys");
                return;
            }
            Api = new OpenAIAPI(new APIAuthentication(EngineSO.ApiKey)); // specify manually
        }
예제 #3
0
        // you can also have conversational ai with the model
        async static Task ConversationStart()
        {
            Console.Clear();
            var    speechConfig = SpeechConfig.FromSubscription(_stKey, _stRegion);
            string myRequest    = await FromMic(speechConfig);

            if (myRequest != "")
            {
                // initiate openai
                OpenAIAPI api    = new OpenAIAPI(new APIAuthentication(_oiKey));
                var       result = await api.Completions.CreateCompletionAsync(prompt : _oiPrompt + " " + myRequest, temperature : 0.9, top_p : 1, frequencyPenalty : 0, presencePenalty : 0.6);

                var resultString = Regex.Replace(result.ToString(), @"^\s+$[\r\n]*", string.Empty, RegexOptions.Multiline);
                // openai response
                Console.WriteLine($"{resultString}");
                await SynthesisToSpeakerAsync(resultString);
            }
            // loop back
            await ConversationStart();
        }
예제 #4
0
 private OpenAICompletionService(string apiKey, IConfigurationProvider configuration)
 {
     _api = new OpenAIAPI(apiKey, configuration.OpenAIEngine);
 }