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.
- Separate error message based on next line character.
- 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;
}
}
}
This was originally posted here.
Comments
-
ChatGPT by Open AI with Dynamics 365 Finance and operation – Part 2 with ApplicationIntroducing ChatGPT po Polsku - the revolutionary website that brings the power of ChatGPT to your fingertips, absolutely free! Say goodbye to tedious registrations and token limitations, because we believe in making artificial intelligence accessible to all.
Powered by the cutting-edge ChatGPT API developed by OpenAI, ChatGPTPL.com is where human-like conversations come to life. Whether you're a language enthusiast, a student, or simply curious about the incredible capabilities of AI, we've got you covered. Best of all, there's no need to jump through hoops or empty your pockets for this mind-blowing experience.
*This post is locked for comments