Beispiel #1
0
        internal static ConversationResult DeserializeConversationResult(JsonElement element)
        {
            string                 query            = default;
            Optional <string>      detectedLanguage = default;
            ConversationPrediction prediction       = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("query"))
                {
                    query = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("detectedLanguage"))
                {
                    detectedLanguage = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("prediction"))
                {
                    prediction = ConversationPrediction.DeserializeConversationPrediction(property.Value);
                    continue;
                }
            }
            return(new ConversationResult(query, detectedLanguage.Value, prediction));
        }
Beispiel #2
0
        internal static BasePrediction DeserializeBasePrediction(JsonElement element)
        {
            if (element.TryGetProperty("projectKind", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Orchestration": return(OrchestrationPrediction.DeserializeOrchestrationPrediction(element));

                case "Conversation": return(ConversationPrediction.DeserializeConversationPrediction(element));
                }
            }
            ProjectKind       projectKind = default;
            Optional <string> topIntent   = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("projectKind"))
                {
                    projectKind = new ProjectKind(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("topIntent"))
                {
                    topIntent = property.Value.GetString();
                    continue;
                }
            }
            return(new BasePrediction(projectKind, topIntent.Value));
        }