Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Integrate OpenAI ChatGPT with Finance and operations

(0) ShareShare
ReportReport
Posted on by 404

Hello guys, i want to integrate chatgpt with f&o, is there a documentation explaining step by step how it can be done?

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    can i have more explanation related to the forms created in the documentation, like what form design its used, and in the OpenapiquestionWindow, what data source is added etc..

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    my code is fixed. when i compile im getting this error:

    The model element was saved with unparsable source code and cannot be used. Please edit the element in Visual Studio to fix the errors.

  • Martin Dráb Profile Picture
    Martin Dráb 230,934 Most Valuable Professional on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    Let's not waste time with runtime errors if your code doesn't even compile. Fix your code, compile everything and try it again.

    Also, your code is pasted in a wrong way. Please always use Insert > Code. It'll prevent the double line spacing, for instance.

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    i have added the parameter for apikey and heres how my code is :

    when i compile i get this error:

    The model element was saved with unparsable source code and cannot be used. Please edit the element in Visual Studio to fix the errors.

    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, string apikey)

           {

               var openAiKey = "get from Chat GPT";

               var apiCall = "api.openai.com/.../" + 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;

           }

       }

    }

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    Im following the same steps of the documentation, so what do u suggest in order to fix it?

  • Martin Dráb Profile Picture
    Martin Dráb 230,934 Most Valuable Professional on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    The message is correct - your method doesn't accept such parameters. It doesn't have a parameter for the last string (apikey).

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    After downloading the dll file, the error is resolved and was able to build my solution. but when i go back to my x++ code, and i remove the comments from the:

    // output = ClassOPENAPI.OpenAPIQuestions::callOpenAI(tokens, _question, engine,temperature,topP,frequencyPenalty,presencePenalty,apikey);

    if i remove the comments i get this error message:

    Method 'call OpenAI(System.Int32, System.String, System.String, System.Decimal, System.Int32, System.Int32, System.Int32, System.String)'is not found on type 'ClassOPENAPI.OpenAPIQuestions'.

  • Martin Dráb Profile Picture
    Martin Dráb 230,934 Most Valuable Professional on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    You should use a search engine in such cases. For example, this thread on Stack Overflow suggest adding a reference to Microsoft.CSharp.dll. Give it a try and look for other suggestions if this one doesn't help.

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    after all the errors are gone, when i try to rebuild, a new error showing:

    CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

  • D365FO DEV Profile Picture
    D365FO DEV 404 on at
    RE: Integrate OpenAI ChatGPT with Finance and operations

    I was able to solve the errors by choosing a higher .NET framework (4.7)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans