コード例 #1
0
        protected async Task <CompletionResponse> FindCompletionsAsync(string filename, string source, OmniSharpTestHost testHost, char?triggerChar = null, TestFile[] additionalFiles = null)
        {
            var testFile = new TestFile(filename, source);

            var files = new[] { testFile };

            if (additionalFiles is object)
            {
                files = files.Concat(additionalFiles).ToArray();
            }

            testHost.AddFilesToWorkspace(files);
            var point = testFile.Content.GetPointFromPosition();

            var request = new CompletionRequest
            {
                Line              = point.Line,
                Column            = point.Offset,
                FileName          = testFile.FileName,
                Buffer            = testFile.Content.Code,
                CompletionTrigger = triggerChar is object?CompletionTriggerKind.TriggerCharacter : CompletionTriggerKind.Invoked,
                TriggerCharacter  = triggerChar
            };

            var requestHandler = GetCompletionService(testHost);

            return(await requestHandler.Handle(request));
        }
コード例 #2
0
        public async Task <ActionResult> CompleteBid(CompletionRequest completionRequest)
        {
            if (!completionRequest.BidId.IsValidId())
            {
                return(this.StatusCode(StatusCodes.Status400BadRequest, $"Given bidId: {completionRequest.BidId} is not legal id"));
            }

            var authResult = await this.authorizationService.AuthorizeAsync(User, completionRequest.BidId, PolicyNames.ChosenSupplierPolicy).ConfigureAwait(false);

            if (!authResult.Succeeded)
            {
                return(this.StatusCode(StatusCodes.Status403Forbidden));
            }
            completionRequest.SupplierId = this.GetRequestUserId();

            Response response = await this.bidsManager.CompleteBid(completionRequest.BidId).ConfigureAwait(false);

            if (response.IsOperationSucceeded)
            {
                return(this.StatusCode(StatusCodes.Status200OK, response.SuccessOrFailureMessage));
            }
            Response notificationResponse = await this.notificationsManager.NotifyBidAllCompletion(completionRequest.BidId).ConfigureAwait(false);

            if (notificationResponse.IsOperationSucceeded)
            {
                return(this.StatusCode(StatusCodes.Status200OK, notificationResponse.SuccessOrFailureMessage));
            }
            return(this.StatusCode(StatusCodes.Status405MethodNotAllowed, notificationResponse.SuccessOrFailureMessage));
        }
コード例 #3
0
ファイル: OAICompletion.cs プロジェクト: lodlock/OpenAI_Unity
        public async void AddToStory(string value)
        {
            QuestionReceivedEvent?.Invoke(value);

            //Character should remember what they said before, since every time we send a request it requires the full 'story' to OpenAI
            memory.Append(value).Append(InjectStartText);

            if (logLevel == LogLevel.ResponsesAndMemory)
            {
                Debug.Log(memory);
            }

            if (!OAIEngine.Instance)
            {
                Debug.LogError("No OAIEngine object found in scene. Make sure there's a GameObject with an OAIEngine Component in your scene");
                return;
            }

            //We allow the engine to change per request (= per character and per statement)
            OAIEngine.Instance.Api.UsingEngine = GetEngine(engine);

            if (NumOutputs < 1)
            {
                Debug.LogWarning($"NumOutputs was set to {NumOutputs}. You should have at least 1 output!");
                NumOutputs = 1;
            }
            else if (autoAddResponseToMemory && NumOutputs > 1)
            {
                Debug.Log("Multiple or no outputs are requested while autoAddResponseToMemory is still true. You should set this to false and manually call 'AddResponseToMemory' after selecting your prefered response.");
            }

            var c       = new CompletionRequest(memory.ToString(), Max_tokens, Temperature, Top_p, NumOutputs, PresencePenalty, FrequencyPenalty, LogProbs, StopSequences);
            var results = await OAIEngine.Instance.Api.Completions.CreateCompletionsAsync(c);

            ResponseReceivedEvent?.Invoke(results.Completions);

            //We make it easy by auto-adding responses to the memory
            if (autoAddResponseToMemory)
            {
                var r = results.Completions[0].Text;
                AddResponseToMemory(r);
                if (logLevel == LogLevel.Responses || logLevel == LogLevel.ResponsesAndMemory)
                {
                    Debug.Log(r);
                }
            }
        }
コード例 #4
0
        private void FindCompletions(int line, int column)
        {
            if (Globals.PyClient != null && this.Lexer == Lexer.Python && this.CompletionEnabled)
            {
                this.HideCompletions();
                this.Completions.Clear();

                Script script = new Script(this.Text, line, column);

                PyRequest req  = new CompletionRequest(script);
                string    json = JsonConvert.SerializeObject(req);
                try
                {
                    JToken token = Globals.PyClient.DoRequest <JToken>(req);
                    if (token != null && token["completions"] is JArray)
                    {
                        JArray items = token["completions"] as JArray;
                        foreach (JToken t in items)
                        {
                            Completion comp = JsonConvert.DeserializeObject <Completion>(t.ToString());
                            if (comp != null)
                            {
                                this.Completions.Add(comp);
                            }
                        }

                        //Todo: move to Show
                        if (this.Completions.Count > 0)
                        {
                            this.ShowCompletion();
                        }
                        else
                        {
                            this.CallTipShow(this.CurrentPosition, "No suggestions");
                        }
                    }
                }
                catch
                {
                    this.CallTipShow(this.CurrentPosition, "Try again**");
                }
            }
        }
コード例 #5
0
        public async Task SetupAsync()
        {
            Setup(new KeyValuePair <string, string>("RoslynExtensionsOptions:EnableImportCompletion", "true"));

            var builder = new StringBuilder();

            builder.AppendLine("namespace N1");
            builder.AppendLine("{");
            builder.AppendLine("    using System.Collections.Generic;");
            builder.AppendLine("    class Base");
            builder.AppendLine("    {");
            for (int i = 0; i < NumOverrides; i++)
            {
                builder.AppendLine($"        public virtual Dictionary<string, string> M{i}(List<string> s) {{ return null; }}");
            }
            builder.AppendLine("    }");
            builder.AppendLine("}");
            builder.AppendLine("namespace N2 : N1.Base");
            builder.AppendLine("{");
            builder.AppendLine("    class Derived");
            builder.AppendLine("    {");
            builder.AppendLine("        override $$");
            builder.AppendLine("    }");
            builder.AppendLine("}");

            const string FileName = "OverrideTest.cs";
            var          file     = new TestFile(FileName, builder.ToString());

            OmniSharpTestHost.AddFilesToWorkspace(file);

            var point = file.Content.GetPointFromPosition();

            Request = new()
            {
                CompletionTrigger = OmniSharp.Models.v1.Completion.CompletionTriggerKind.Invoked,
                Line     = point.Line,
                Column   = point.Offset,
                FileName = FileName
            };

            // Trigger completion once to ensure that all the runs have a warmed-up server
            await OverrideCompletionAsync();
        }
コード例 #6
0
        private async Task<CompletionResponse> FindCompletionsAsync(string filename, string source, OmniSharpTestHost host, char? triggerChar = null, TestFile[] additionalFiles = null)
        {
            var testFile = new TestFile(filename, source);

            var files = new[] { testFile };
            if (additionalFiles is object)
            {
                files = files.Concat(additionalFiles).ToArray();
            }

            host.AddFilesToWorkspace(files);
            var point = testFile.Content.GetPointFromPosition();

            var request = new CompletionRequest
            {
                Line = point.Line,
                Column = point.Offset,
                FileName = testFile.FileName,
                Buffer = testFile.Content.Code,
                CompletionTrigger = triggerChar is object ? CompletionTriggerKind.TriggerCharacter : CompletionTriggerKind.Invoked,
                TriggerCharacter = triggerChar
            };

            var updateBufferRequest = new UpdateBufferRequest
            {
                Buffer = request.Buffer,
                Column = request.Column,
                FileName = request.FileName,
                Line = request.Line,
                FromDisk = false
            };

            await GetUpdateBufferHandler(host).Handle(updateBufferRequest);

            var requestHandler = GetRequestHandler(host);

            return await requestHandler.Handle(request);
        }
コード例 #7
0
        public async Task SetupAsync()
        {
            Setup(new KeyValuePair <string, string>("RoslynExtensionsOptions:EnableImportCompletion", "true"));

            var builder = new StringBuilder();

            builder.AppendLine("class Base");
            builder.AppendLine("{");
            builder.AppendLine("    void M()");
            builder.AppendLine("    {");
            builder.AppendLine("        $$");
            builder.AppendLine("    }");
            builder.AppendLine("}");

            const string FileName = "ImportCompletionTest.cs";
            var          file     = new TestFile(FileName, builder.ToString());

            OmniSharpTestHost.AddFilesToWorkspace(file);

            var point = file.Content.GetPointFromPosition();

            Request = new()
            {
                CompletionTrigger = CompletionTriggerKind.Invoked,
                Line     = point.Line,
                Column   = point.Offset,
                FileName = FileName
            };

            // Trigger completion once to ensure that all the runs have a warmed-up server, with full completions loaded
            CompletionResponse completions;

            do
            {
                completions = await ImportCompletionListAsync();
            } while (!completions.Items.Any(i => i.Label == "Console"));
        }
コード例 #8
0
 public async Task <CompletionResult[]> PostMembers([FromUri] CompletionRequest request, Source source)
 {
     return(await _compilationService.GetCompletionsAsync(request, source));
 }
コード例 #9
0
        public static async Task <CompletionResponse> TranslateAsync(this CompletionResponse response, OmniSharpWorkspace workspace, CompletionRequest request)
        {
            foreach (var item in response.Items)
            {
                if (item.TextEdit is null)
                {
                    continue;
                }

                var(_, textEdit) = await item.TextEdit.TranslateAsync(workspace, request.FileName);

                item.TextEdit = textEdit;

                List <LinePositionSpanTextChange> additionalTextEdits = null;

                foreach (var additionalTextEdit in item.AdditionalTextEdits ?? Enumerable.Empty <LinePositionSpanTextChange>())
                {
                    var(_, change) = await additionalTextEdit.TranslateAsync(workspace, request.FileName);

                    // Due to the fact that AdditionalTextEdits return the complete buffer, we can't currently use that in Cake.
                    // Revisit when we have a solution. At this point it's probably just best to remove AdditionalTextEdits.
                    if (change.StartLine < 0)
                    {
                        continue;
                    }

                    additionalTextEdits ??= new List <LinePositionSpanTextChange>();
                    additionalTextEdits.Add(change);
                }

                item.AdditionalTextEdits = additionalTextEdits;
            }

            return(response);
        }
コード例 #10
0
        public async Task <CompletionResult[]> PostMembers([FromUri] CompletionRequest request)
        {
            var code = await Request.Content.ReadAsStringAsync();

            return(await _compilationService.GetCompletionsAsync(request, code));
        }