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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;
    }
    }
     
}

Comments