Design a site like this with WordPress.com
Get started

ChatGPT by Open AI with Dynamics 365 Finance and operation – Part 2 with Application

As part of Chat GPT integration with Dynamics 365 Finance and operation, here I have started working on real application which actually can help end user to identify and get more information about error message in system.

if you want to lean about how to integrate ChatGPT with Dynamics 365 Finance and operation.

I have decided to start with General journal posting and Validation process.

System store all validation message related to journal lines in header table (Log field)

I have decided to add new button on general journal screen which will help me to read log from header table and try to find out relevant information using ChatGPT call.

Here below I have showing sample X++ code for your reference.

Following tweaks I am trying to do here to make request more understandable to ChatGPT.

  1. Separate error message based on next line character.
  2. Add suffix “in D365 Finance and operations” keyword.

Creating message :

here is debugging window which helps to identify sequence of code.

here is output window which can provide more suitable response. to new user.

Here is information about parameters which I am using.

Attaching Sample C# code for your reference

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Globalization;
using Newtonsoft.Json;

namespace ClassOPENAPI
{
    public class OpenAPIQuestions
    {
        public static string callOpenAI(int tokens, string input, string engine,
              double temperature, int topP, int frequencyPenalty, int presencePenalty)
        {

        

        var apiCall = "https://api.openai.com/v1/engines/" + engine + "/completions";

        try
        {

            using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod("POST"), apiCall))
                {
                    request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + openAiKey);
                    request.Content = new StringContent("{\n  \"prompt\": \"" + input + "\",\n  \"temperature\": " +
                                                        temperature.ToString(CultureInfo.InvariantCulture) + ",\n  \"max_tokens\": " + tokens + ",\n  \"top_p\": " + topP +
                                                        ",\n  \"frequency_penalty\": " + frequencyPenalty + ",\n  \"presence_penalty\": " + presencePenalty + "\n}");

                    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                    var response = httpClient.SendAsync(request).Result;
                    var json = response.Content.ReadAsStringAsync().Result;

                    dynamic dynObj = JsonConvert.DeserializeObject(json);

                    if (dynObj != null)
                    {
                        return dynObj.choices[0].text.ToString();
                    }


                }
            }

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);

        }

        return null;
    }
    }
    
}

Advertisement

One response to “ChatGPT by Open AI with Dynamics 365 Finance and operation – Part 2 with Application”

  1. Hi home.blog owner, Your posts are always well-supported by facts and figures.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s