Design a site like this with WordPress.com
Get started

ChatGPT by Open AI with Dynamics 365 Finance and operation

Guys vote if you want Microsoft to add chat GPT by Open API integration with Dynamics 365 Finance and operation in upcoming release.

https://experience.dynamics.com/ideas/idea/?ideaid=df3d2836-24a6-ed11-9ac4-0003ff458e61

This blog is for ChatGPT and D365 Finance and operation integration, As we know so many people are talking about ChatGPT now a days and why don’t we try to access ChatGPT features from Dynamics 365 finance and operation and let user interact with AI to get required help.

Yes it is possible to with some C# and X++ code combination.

To start with I will suggest everyone to play with ChatGPT for sometime and understand. (New chat (openai.com))

If you feel now you are ready for technical integration, its time to jump on Playground and understand some technical stuff.

Playground – OpenAI API (To understand each parameters, Refer https://www.makeuseof.com/how-to-use-gpt-3-openai-playground/, Blog.

Main parameters to understand.

1.Model,

2.Temperature (To fine tune output response)

3.Maximum length (Max output response)

4Top P,

5.Frequency Penalty

6.Presence penalty.

Once you understand more about parameter, It time to get API and secret key from beta.openai.com.

ApiCall = “https://api.openai.com/v1/engines/” + engine + “/completions”;

You can generate secret key from

Once you have all required information you can write C# code to integrate.

I have created D365 parameter table to store required parameters for ChatGPT API call.

Here you can find C# code for calling ChatGPT API.

You can refer same code in D365 and call using X++ reference.

Once you are done with above technical changes, Now we can proceed with parameters setup for API call and start playing with it

Here you have playground in D365 Finance and operation for your reference.

As a responsible technical I would suggest to have some restriction in place for responsible use of ChatGPT API if you wanted to implement same for customer.

Advertisement

11 responses to “ChatGPT by Open AI with Dynamics 365 Finance and operation”

  1. It’s really very good thing to learn and implement. Thanks for sharing.

    Like

  2. Hi,
    like it a lot!
    can you share your project?
    br,

    Like

      1. גילי דרמוני Avatar
        גילי דרמוני

        Thanks!

        Like

    1. 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 openAiKey = “get from Chat GPT”

      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;
      }
      }

      }

      Like

      1. can you share the full project including all X++ involved objects

        Like

  3. Really great content, congrats! It’s really a hot topic these days. Just waiting you share the project to test it. By the way, I voted on Microsoft Ideas and shared the campaign via LinkedIn 🙂

    Like

    1. 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 openAiKey = “get from Chat GPT”

      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;
      }
      }

      }

      Like

    2. Complete project I can share end of this week.

      Like

  4. Please share the project

    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