Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BC Idea]: Number Series Copilot #659

Open
1 task done
DmitryKatson opened this issue Feb 28, 2024 · 60 comments · May be fixed by #764
Open
1 task done

[BC Idea]: Number Series Copilot #659

DmitryKatson opened this issue Feb 28, 2024 · 60 comments · May be fixed by #764
Assignees
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Linked Issue is linked to a Azure Boards work item Requires PG Review Requires a review session with the product group to settle on the design details.

Comments

@DmitryKatson
Copy link
Contributor

DmitryKatson commented Feb 28, 2024

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=ae4b0c3a-30d6-ee11-92bd-000d3adb9365

Description

Introducing the concept of a "Number Series Copilot" for Business Central, an innovative feature designed to simplify the creation of number series through natural language commands. This idea allows users to effortlessly set up number series for specific entities like customers, vendors, or even across all entities, by simply describing their needs or specifying a format example.

Idea Highlights:

  • Natural Language Processing: Users can interact with Business Central in everyday language to request the creation of number series, making the system more intuitive and user-friendly.

  • Customizable Formats: By providing examples or masks, users can define how their number series should be structured, offering flexibility and control over their data organization.

  • Efficiency and Time-Saving: Eliminates the complexity and manual effort involved in setting up number series, streamlining administrative tasks.

  • Accessibility: Makes the process of creating number series accessible to users with varying levels of technical expertise, democratizing the use of Business Central features.

This concept envisions a more interactive and intelligent Business Central, where routine tasks are automated and simplified through AI, enhancing the user experience and operational efficiency.

Linked ideas - Document numeration series templates

Number of Votes - 47

I will provide the implementation for this BC Idea

  • I will provide the implementation for this BC Idea

Fixes AB#503148

Internal work item: AB#503148

@DmitryKatson DmitryKatson added the BCIdea Issue related to a BCIdea label Feb 28, 2024
@ikoletic ikoletic added the Approved The issue is approved label Feb 28, 2024
@ikoletic
Copy link

@DmitryKatson , @JesperSchulz approving, but let's have a short discussion on this before we dive in. Want to understand if we'll be able ask for generation for master data documents posted documents (that may need year in no series and or not allow gaps) separately and apply no series in various setup pages, updating existing number series, generating new no series lines on top of your existing ones to make this an E2E story.

@JesperSchulz JesperSchulz added the Requires PG Review Requires a review session with the product group to settle on the design details. label Feb 28, 2024
@JesperSchulz
Copy link
Contributor

Setting up meeting to discuss.

@DmitryKatson
Copy link
Contributor Author

@ikoletic great questions, basically defining a possible set of questions that LLM should cover in the AI implementation is the right way to start

@JesperSchulz
Copy link
Contributor

PG Review conducted today. Discussed the need to follow Microsoft's responsible AI practices and agreed upon feature set.
@DmitryKatson, you're good to go!

As agreed, I tried to run .\build\scripts\DevEnv\NewDevEnv.ps1 -containerName 'BC-BusinessFoundation' -userName admin -password 'somePW' -projectPaths '.\src\BusinessFoundation\*'

Unfortunately it deletes the Business Foundation and System Application in the end, which leaves an environment without any apps, but @mazhelez has agreed to look into this right away and you should soon be good to take your first steps into the world of code contributions 🥳

Again, if you have any questions, don't ever hesitate to reach out to me! We'll be in touch 😊

@mazhelez
Copy link
Contributor

mazhelez commented Mar 1, 2024

@JesperSchulz @DmitryKatson, earlier I tried running:

.\build\scripts\DevEnv\NewDevEnv.ps1 -userName admin -password '<pass>' -projectPaths '.\src\BusinessFoundation\*'

And it worked as expected.

Unfortunately, after some recent changes, it is painfully slow, it took a bit more than 30 minutes, but once set up, the container is ready with all the apps installed.

If something fails on your side, can you check if apps are created in an .artifactsCache folder? Or check the logs, maybe something failed silently.

Let me know if there is more I can help out with!

@DmitryKatson
Copy link
Contributor Author

Great. I will write down here steps I did to proceed with the development (so to make a full blog about the process at the end).

  1. Submit the idea at https://experience.dynamics.com/ideas/
  2. Get enough votes
  3. Submit [BC Idea] issue at https://github.com/microsoft/BCApps/issues , link to the idea and assign to myself
  4. Wait "Approved" status
  5. Make fork from https://github.com/microsoft/BCApps
  6. Clone locally and create feature branch
  7. Locally: run Powershell (as Administrador) on the project folder path
  8. Run command .\build\scripts\DevEnv\NewDevEnv.ps1 -userName admin -password '<pass>' -projectPaths '.\src\Business Foundation\*'

@DmitryKatson
Copy link
Contributor Author

@mazhelez I have weird error
image

Seems that container was created, but i can't open it.
This is the full log full log.rtf.zip

@mazhelez
Copy link
Contributor

mazhelez commented Mar 3, 2024

Which BCContainerHelper version are you using?

You'd need the latest one.

@DmitryKatson
Copy link
Contributor Author

Seems the fix for this error is this commit and it's been deployed to the version 6.0.7-preview1150 of BCContainerHelper.

To get this i had to run Install-Module -Name BcContainerHelper -AllowPrerelease -Force in Powershell (as Administrator).

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz how should I create app.json file for "Number Series Copilot" ?
Should it be something like this?
What Id range to use?

{
    "id":  "7efce506-def2-4195-9d1e-bc538e729242",
    "name":  "No. Series Copilot",
    "publisher":  "Microsoft",
    "brief":  "",
    "description":  "",
    "version":  "25.0.0.0",
    "privacyStatement":  "https://go.microsoft.com/fwlink/?linkid=724009",
    "EULA":  "https://go.microsoft.com/fwlink/?linkid=2009120",
    "help":  "https://go.microsoft.com/fwlink/?linkid=2103698",
    "url":  "https://go.microsoft.com/fwlink/?linkid=724011",
    "logo":  "",
    "dependencies":  [
                         {
                             "id":  "63ca2fa4-4f03-4f2b-a480-172fef340d3f",
                             "name":  "System Application",
                             "publisher":  "Microsoft",
                             "version":  "25.0.0.0"
                         }
                     ],
    "internalsVisibleTo":  [
                               {
                               }
                           ],
    "screenshots":  [

                    ],
    "platform":  "24.0.0.0",
    "target":  "OnPrem",
    "idRanges":  [
                     {
                         "from":  1,
                         "to":  9999
                     },
                 ],
    "features":  [
                     "TranslationFile",
                     "GenerateCaptions",
                     "NoImplicitWith",
                     "NoPromotedActionProperties"
                 ],
    "resourceExposurePolicy":  {
                                   "allowDebugging":  true,
                                   "allowDownloadingSource":  true,
                                   "includeSourceInSymbolFile":  true
                               },
    "contextSensitiveHelpUrl":  "https://learn.microsoft.com/dynamics365/business-central/"
}

@DmitryKatson
Copy link
Contributor Author

@mazhelez with the latest (preview) bc container helper the script was executed successfully. However for some reason I can't access container from the browser.

This is the status

 BcContainerHelper version 6.0.7-preview1151
BC.HelperFunctions emits usage statistics telemetry to Microsoft
PS C:\Users\vmadmin> Restart-BcContainer BC-BusinessFoundation
Removing Session BC-BusinessFoundation
BC-BusinessFoundation
Waiting for container BC-BusinessFoundation to be ready

Initializing...
Setting host.containerhelper.internal to 172.19.176.1 in container hosts file
Restarting Container
PublicDnsName unchanged
Hostname is BC-BusinessFoundation
PublicDnsName is BC-BusinessFoundation
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Starting Service Tier
Container IP Address: 172.19.185.225
Container Hostname  : BC-BusinessFoundation
Container Dns Name  : BC-BusinessFoundation
Web Client          : http://BC-BusinessFoundation/BC/
Dev. Server         : http://BC-BusinessFoundation
Dev. ServerInstance : BC

Files:
http://BC-BusinessFoundation:8080/ALLanguage.vsix

Container Total Physical Memory is 32.0Gb
Container Free Physical Memory is 26.7Gb

Initialization took 24 seconds
Ready for connections! 

but when i open http://BC-BusinessFoundation/BC/ i see
image

When I run download symbols i get

[2024-03-04 12:55:20.37] Using reference symbols cache paths: [c:\Users\vmadmin\Documents\AL\BCApps-Number-Series-Copilot\BCApps\src\Business Foundation\App\.alpackages]
[2024-03-04 12:55:20.41] Targeting server 'http://BC-BusinessFoundation', server instance 'BC' and tenant 'default'.
[2024-03-04 12:55:20.62] Please authenticate in the Visual Studio Code...
[2024-03-04 12:55:28.28] Using reference symbols cache paths: [c:\Users\vmadmin\Documents\AL\BCApps-Number-Series-Copilot\BCApps\src\Business Foundation\App\.alpackages]
[2024-03-04 12:55:28.28] Targeting server 'http://BC-BusinessFoundation', server instance 'BC' and tenant 'default'.
[2024-03-04 12:55:28.30] Using user name and password authentication. User name used is: 'admin'.
[2024-03-04 12:55:28.32] Sending request to http://bc-businessfoundation:7049/BC/dev/metadata?tenant=default
[2024-03-04 12:55:29.41] Error: No such host is known. (bc-businessfoundation:7049)
No such host is known.

[2024-03-04 12:55:29.41] Error: An error occured while processing the request.
Request ID: 6a3a9330-c44c-433d-a5a1-45dae9c2eee0
Session ID: e222fbd6-cee4-4eba-88a0-ab4c2efce434

If you are targeting a cloud instance, supply these IDs if contacting Microsoft support.
[2024-03-04 12:55:29.42] Sending request to http://bc-businessfoundation:7049/BC/dev/metadata?tenant=default
[2024-03-04 12:55:30.42] Error: No such host is known. (bc-businessfoundation:7049)
No such host is known.

[2024-03-04 12:55:30.42] Error: An error occured while processing the request.
Request ID: a8a69d2d-9b04-464f-8423-e880216aca15
Session ID: e222fbd6-cee4-4eba-88a0-ab4c2efce434

If you are targeting a cloud instance, supply these IDs if contacting Microsoft support.

@JesperSchulz
Copy link
Contributor

Your app.json looks about right! You should indeed just use the ID range between 1 - 9.999. Try to find available IDs close to the IDs already in the module. E.g. codeunit 326 and up seem to be free. We want to use ID Ninja going forward, but not everyone is using it yet, which sometimes leads to ID conflicts when using it.

@DmitryKatson
Copy link
Contributor Author

@mazhelez there was probably something with my VM. I made a new one and everything worked as expected. Thanks.

@mazhelez
Copy link
Contributor

mazhelez commented Mar 4, 2024

@mazhelez there was probably something with my VM. I made a new one and everything worked as expected. Thanks.

Happy to hear everything works for you now!

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz sorry for stupid questions :)

  • I made a local branch
  • I created new folder src\Business Foundation\App\NoSeriesCopilot

My business central is empty
image

So, there are no base app, system app, foundation app etc.
It's a bit uncomfortable to see such picture ;)
What are the next steps?

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz also if i need to add, let's say, action to the Number Series page, should I change the Number Series page directly, or make pageextention ?

@Drakonian
Copy link
Contributor

@JesperSchulz sorry for stupid questions :)

  • I made a local branch
  • I created new folder src\Business Foundation\App\NoSeriesCopilot

My business central is empty image

So, there are no base app, system app, foundation app etc. It's a bit uncomfortable to see such picture ;) What are the next steps?

This is something what should be improved :)
#417 (comment)

@JesperSchulz
Copy link
Contributor

@JesperSchulz also if i need to add, let's say, action to the Number Series page, should I change the Number Series page directly, or make pageextention ?

Since you're now working directly on the application platform, you should just change the No. Series module to your liking. As a matter of fact... why are you even creating a separate module? Would it maybe make sense that you just add your capabilities to the "No. Series" module? 🤔 I actually think it would! Or would one maybe want to have No. Series without AI wizards? I'm a little torn here - but this can be adjusted as we go along.

With regards to the environment, I just discussed the same matter with @mazhelez last week. I was expecting a container with at least the System App and Business Foundation pre-installed, but she told me I have to compile and publish those myself.

@freddydk, I seem to recall "in the old days" (say half a year ago), my containers came with everything pre-installed. Have we changed that?

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz also if i need to add, let's say, action to the Number Series page, should I change the Number Series page directly, or make pageextention ?

Since you're now working directly on the application platform, you should just change the No. Series module to your liking. As a matter of fact... why are you even creating a separate module? Would it maybe make sense that you just add your capabilities to the "No. Series" module? 🤔 I actually think it would! Or would one maybe want to have No. Series without AI wizards? I'm a little torn here - but this can be adjusted as we go along.

With regards to the environment, I just discussed the same matter with @mazhelez last week. I was expecting a container with at least the System App and Business Foundation pre-installed, but she told me I have to compile and publish those myself.

@freddydk, I seem to recall "in the old days" (say half a year ago), my containers came with everything pre-installed. Have we changed that?

I try to follow the other copilots pattern, which are separate apps. Also, having in mind that some localizations (like Canada), and, probably India, according o the latest news, have separate AI regulations and rules, I think it make sense to make it as separate app, that can be uninstalled.

@JesperSchulz
Copy link
Contributor

If you're putting the module in the Business Foundation, it will get compiled into one app (just as it happens in the System Application) and you will not have a possibility to uninstall the app. If you want it to be a separate app, you would have to create it as a first party app. In that case, we need to move this issue to the ALAppExtensions repository though.
I would very much be in favor of keeping the code in the Business Foundation. @grobyns / @darjoo, what's your take on this?

@darjoo
Copy link
Contributor

darjoo commented Mar 4, 2024

I'd be in favor of keeping it within Business Foundation as well.
I understand Dmitry's concern about the localization and regulations, however in the long run, the view is that all these copilots will be part of BC by default irregardless of your the country and also can't be turned deactivated. As No. Series is a Business Foundation feature, its copilot should also be part of it.
The registration etc can be limited within the Install/Upgrade codeunits where we specifically disallow the registration of the copilot in CA region. I'm not sure what other regions will have this limitation off the top of my head, but we can always update that when we're going through the responsible AI reviews.

@DmitryKatson
Copy link
Contributor Author

Ok, got it.
@JesperSchulz would that be correct structure then?
image

@JesperSchulz
Copy link
Contributor

Getting there. We usually put our code into a src folder (see NoSeries module). Also, even though everything gets compiled into a single app, the modules must be able to compile individually. You will hence need a dependency to the No. Series module.

@DmitryKatson
Copy link
Contributor Author

The work started DmitryKatson@44ac608
The progress can be seen here https://github.com/DmitryKatson/BCApps/tree/Number-Series-Copilot

@JesperSchulz
Copy link
Contributor

The work started DmitryKatson@44ac608 The progress can be seen here https://github.com/DmitryKatson/BCApps/tree/Number-Series-Copilot

Now that is exciting! I'll tag along 💪

@DmitryKatson
Copy link
Contributor Author

DmitryKatson commented Mar 5, 2024

@JesperSchulz also if i need to add, let's say, action to the Number Series page, should I change the Number Series page directly, or make pageextention ?

Since you're now working directly on the application platform, you should just change the No. Series module to your liking. As a matter of fact... why are you even creating a separate module? Would it maybe make sense that you just add your capabilities to the "No. Series" module? 🤔 I actually think it would! Or would one maybe want to have No. Series without AI wizards? I'm a little torn here - but this can be adjusted as we go along.

With regards to the environment, I just discussed the same matter with @mazhelez last week. I was expecting a container with at least the System App and Business Foundation pre-installed, but she told me I have to compile and publish those myself.

@freddydk, I seem to recall "in the old days" (say half a year ago), my containers came with everything pre-installed. Have we changed that?

Ok. I compiled and published System Application and Business Foundation app.

PS C:\Windows\System32> (Get-BcContainerAppInfo -containerName "BC-BusinessFoundation").Name
Business Foundation
Business Foundation Test Libraries
Business Foundation Tests
Library Assert
Any
Permissions Mock
System Application

The Business Cdntral UI didn't change (still empty)
How should i publish base app?

@DmitryKatson
Copy link
Contributor Author

@darjoo the Copilots issued by Microsoft run only in SaaS, so there is CopilotActionsVisible := EnvironmentInformation.IsSaaSInfrastructure() in many places. I will do the same, but how do you manually test/debug copilots in docker? Or do you add this at the very end when everything is tested?

@JesperSchulz
Copy link
Contributor

JesperSchulz commented Mar 7, 2024

@JesperSchulz dependency question. I would like to use codeunit 5459 "JSON Management", but it's a part of Base Application. I don't think I need to make dependency on Base App, it makes no sense for the Business Foundation Level. However, I believe, Json Management should be in the system app. What would you suggest?

You're absolutely right, that JSON Management should be a module in the System App. You are also right, that you may not take a dependency on the BaseApp from the Business Foundation, just as you may not use .NET in the Business Foundation. In reality that only leaves you with one option: Go the extra mile and create a JSON module (only implement the API you require). This is actually the way we do componentization these days internally as well. We refactor and componentize on a "per need" basis. It shouldn't be too hard to create such module. Let me know if you need my help doing so!

If I would need some JSON Module APIs, should I run a separate idea > issue flow ?

That's mostly up to you. To reduce the chance of code review fatigue, I would suggest that you split the PRs and first get the JSON module checked in - that should be a quick one! The larger PRs get, the less effective the code reviews are.
Whether you want to track your work under a new issue, or whether you want to link your separate PR to this issue, is up to you. It'll take me 10 sec to approve the new issue, if you create one (no BC idea needed here - just refer to this issue in the new issue and mention it's a spin-off) 😊

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz seems i have a major issue.
To make it all work as expected i need to have the info about Business Central tables. For this i use table 2000000136 "Table Metadata".

This is my function

    local procedure ListAllTablesWithNumberSeries(var NewNoSeriesPrompt: TextBuilder)
    var
        TableMetadata: Record "Table Metadata";
    begin
        // Looping trhough all Setup tables
        TableMetadata.SetFilter(Name, '* Setup');
        TableMetadata.SetRange(ObsoleteState, TableMetadata.ObsoleteState::No); //TODO: Check if 'Pending' should be included
        TableMetadata.SetRange(TableType, TableMetadata.TableType::Normal);
        if TableMetadata.FindSet() then
            repeat
                ListAllNoSeriesFields(NewNoSeriesPrompt, TableMetadata);
            until TableMetadata.Next() = 0;
    end;

The problem is that, seems, that from Business Foundation layer this table don't "see" all tables from the Base Application!
Is it me? Or this is our stop factor?

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz seems i have a major issue. To make it all work as expected i need to have the info about Business Central tables. For this i use table 2000000136 "Table Metadata".

This is my function

    local procedure ListAllTablesWithNumberSeries(var NewNoSeriesPrompt: TextBuilder)
    var
        TableMetadata: Record "Table Metadata";
    begin
        // Looping trhough all Setup tables
        TableMetadata.SetFilter(Name, '* Setup');
        TableMetadata.SetRange(ObsoleteState, TableMetadata.ObsoleteState::No); //TODO: Check if 'Pending' should be included
        TableMetadata.SetRange(TableType, TableMetadata.TableType::Normal);
        if TableMetadata.FindSet() then
            repeat
                ListAllNoSeriesFields(NewNoSeriesPrompt, TableMetadata);
            until TableMetadata.Next() = 0;
    end;

The problem is that, seems, that from Business Foundation layer this table don't "see" all tables from the Base Application! Is it me? Or this is our stop factor?

Wait, seems it's me. When I publish Business Foundation app, my Base Application is been removed ... hm

@JesperSchulz
Copy link
Contributor

Indeed you should have full access to the "Table Metadata" table!

@DmitryKatson
Copy link
Contributor Author

DmitryKatson commented Mar 8, 2024

@darjoo I've added AddToolMessage API to the codeunit 7763 "AOAI Chat Messages" as i need to construct message in this format

                    "tool_call_id": tool_call.id,
                    "role": "tool",
                    "name": function_name,
                    "content": function_response,

according to https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling?tabs=python-new

Take a look here

This is a mockup of the new chat history, that's been send to

{"role":"system","content":"Help with Number Series"}
{"role":"user","content":"Set up numbers series for the new company"}
{"role":"assistant","tool_calls":[{"id":"call_KzEtrcxiQNaXOOUJjOeyike1","type":"function","function":{"name":"generate_new_numbers_series","arguments":"{}"}}]}
{"role":"tool","content":"Bank Account Nos.\r\nPatterns: \r\n B00010","name":"generate_new_numbers_series","tool_call_id":"call_KzEtrcxiQNaXOOUJjOeyike1"}

@darjoo
Copy link
Contributor

darjoo commented Mar 8, 2024

Thanks for pointing out the spelling in the test name. I will get that fixed.
Yes, the tool should come from KV and you can mock the KV similar to the function below (Ripped from ImageAnalysis test).
We haven't put out guidance on it, however, not everything of the function is required to be from KV. Fx name, parameters. The key is description which is passed and interpreted by the model for what the function does. We consider the description to be IP, just like metaprompts.

    local procedure InitializeMockKeyvault(ApiKey: Text; ApiEndpoint: Text; ImageAnalysisLimit: Text; ImageAnalysisPeriodType: Text)
    var
        AzureKeyVaultTestLibrary: Codeunit "Azure Key Vault Test Library";
    begin
        MockAzureKeyvaultSecretProvider := MockAzureKeyvaultSecretProvider.MockAzureKeyVaultSecretProvider();
        MockAzureKeyvaultSecretProvider.AddSecretMapping('AllowedApplicationSecrets', 'cognitive-vision-params');
        MockAzureKeyvaultSecretProvider.AddSecretMapping(
          'cognitive-vision-params', StrSubstNo(KeyvaultValueTxt, ApiKey, ApiEndpoint, ImageAnalysisPeriodType, ImageAnalysisLimit));

        AzureKeyVaultTestLibrary.SetAzureKeyVaultSecretProvider(MockAzureKeyvaultSecretProvider);
    end;

It is a very good suggestion to add the tools into the messages, we didn't directly add it yet because we weren't exactly sure how that should be used as GetLastMessage returns the parsed message (without tools) and if we add it, we know have a json in there. Or we track it separately. That's something that needs a bit more brainstorming.
I definitely agree there are improvements that need to be done when working with Tools/Functions.
One of the biggest annoyance I have with it right now is having to parse with JSONObjects & tokens when you get the result. Which is repetitive work devs should not be required to do and that should live in the module directly.

When it comes parts where we have CopilotActionsVisible := EnvironmentInformation.IsSaaSInfrastructure(), we add that at the very end once we have everything completed and tested locally. Then when going to test on SaaS we start to add it and ensure the SaaS & OnPrem are as expected.

Let me review that last message about AddToolMessage and get back to you again later today!

@DmitryKatson
Copy link
Contributor Author

@darjoo I found little issue in this commit. I'll fix, rebase commit once again and let you know.

@DmitryKatson
Copy link
Contributor Author

@darjoo fixed, you can check here

Now it's correctly accept this chat history and return back answer

{"role":"system","content":"Help with Number Series"}
{"role":"user","content":"Set up numbers series for the new company"}
{"role":"assistant","tool_calls":[{"id":"call_KzEtrcxiQNaXOOUJjOeyike1","type":"function","function":{"name":"generate_new_numbers_series","arguments":"{}"}}]}
{"role":"tool","content":"Bank Account Nos.\r\nPatterns: \r\n B00010","name":"generate_new_numbers_series","tool_call_id":"call_KzEtrcxiQNaXOOUJjOeyike1"}

@DmitryKatson
Copy link
Contributor Author

DmitryKatson commented Mar 9, 2024

@darjoo Introduce here "response_format":"{ "type": "json_object" }" to explicitly set JSON Mode output as described here . It works perfectly well.

However 1 thing is out of my control. Would be nice to get finish_reason from the responce, to understand if Json output is full by analysing values stop or length. I added a placeholder to this in

codeunit 7770 "AOAI Operation Response"
    var
...
    // FinishReason: Text; //TODO: Enable this when FinishReason is added to ALCopilotOperationResponse dotnet class

...

    /// <summary>
    /// Gets the finish reason of last response.
    /// </summary>
    /// <returns></returns>
    // TODO: Enable this when FinishReason is added to ALCopilotOperationResponse dotnet class
    // procedure GetFinishReason(): Text
    // begin
    //     exit(FinishReason);
    // end;

    internal procedure SetOperationResponse(var ALCopilotOperationResponse: DotNet ALCopilotOperationResponse)
    begin
        Success := ALCopilotOperationResponse.IsSuccess();
        StatusCode := ALCopilotOperationResponse.StatusCode;
        Result := ALCopilotOperationResponse.Result();
        Error := ALCopilotOperationResponse.ErrorText();
        // FinishReason := ALCopilotOperationResponse.FinishReason; //TODO: Add FinishReason to ALCopilotOperationResponse dotnet class

        if Error = '' then
            Error := GetLastErrorText();
    end;

@DmitryKatson
Copy link
Contributor Author

@JesperSchulz dependency question. I would like to use codeunit 5459 "JSON Management", but it's a part of Base Application. I don't think I need to make dependency on Base App, it makes no sense for the Business Foundation Level. However, I believe, Json Management should be in the system app. What would you suggest?

You're absolutely right, that JSON Management should be a module in the System App. You are also right, that you may not take a dependency on the BaseApp from the Business Foundation, just as you may not use .NET in the Business Foundation. In reality that only leaves you with one option: Go the extra mile and create a JSON module (only implement the API you require). This is actually the way we do componentization these days internally as well. We refactor and componentize on a "per need" basis. It shouldn't be too hard to create such module. Let me know if you need my help doing so!

If I would need some JSON Module APIs, should I run a separate idea > issue flow ?

That's mostly up to you. To reduce the chance of code review fatigue, I would suggest that you split the PRs and first get the JSON module checked in - that should be a quick one! The larger PRs get, the less effective the code reviews are. Whether you want to track your work under a new issue, or whether you want to link your separate PR to this issue, is up to you. It'll take me 10 sec to approve the new issue, if you create one (no BC idea needed here - just refer to this issue in the new issue and mention it's a spin-off) 😊

Done Json module (only required for the copilot implementation apis) #716

@DmitryKatson
Copy link
Contributor Author

@darjoo added PR with AI module changes required to Number Series Copilot #719

@DmitryKatson
Copy link
Contributor Author

@darjoo weird behaviour. TokenCountImpl.GetGPT4TokenCount return me always 0. Am I doing something wrong?

procedure TestGetGPT4TokenCount()
        TestText: Text;
        TestTextTokens: Integer;
        TestSecretText: SecretText;
        TestSecretTextTokens: Integer;
    begin
        TestText := 'This is test text';
        TestSecretText := TestText;

        TestTextTokens := TokenCountImpl.GetGPT4TokenCount(TestText);
        TestSecretTextTokens := TokenCountImpl.GetGPT4TokenCount(TestSecretText);
end

results for TestTextTokens, TestSecretTextTokens = 0

@darjoo
Copy link
Contributor

darjoo commented Mar 12, 2024

@darjoo weird behaviour. TokenCountImpl.GetGPT4TokenCount return me always 0. Am I doing something wrong?

procedure TestGetGPT4TokenCount()
        TestText: Text;
        TestTextTokens: Integer;
        TestSecretText: SecretText;
        TestSecretTextTokens: Integer;
    begin
        TestText := 'This is test text';
        TestSecretText := TestText;

        TestTextTokens := TokenCountImpl.GetGPT4TokenCount(TestText);
        TestSecretTextTokens := TokenCountImpl.GetGPT4TokenCount(TestSecretText);
end

results for TestTextTokens, TestSecretTextTokens = 0

Oh no.. I just tested and got the same issue. Let me investigate into that. It worked before :(

@darjoo
Copy link
Contributor

darjoo commented Mar 12, 2024

Found the silly mistake.. The procedures weren't returning the value. I'll open a PR to fix that right now

procedure GetGPT4TokenCount(Input: SecretText): Integer
    begin
        AzureOpenAIImpl.GetTokenCount(Input, Encodingcl100kbaseLbl);
    end;

@DmitryKatson
Copy link
Contributor Author

Found the silly mistake.. The procedures weren't returning the value. I'll open a PR to fix that right now

procedure GetGPT4TokenCount(Input: SecretText): Integer
    begin
        AzureOpenAIImpl.GetTokenCount(Input, Encodingcl100kbaseLbl);
    end;

Ah :) uff, i though something major. Great, I'll fix locally to be able to continue.

@DmitryKatson
Copy link
Contributor Author

@darjoo Added a new method to calculate the whole message history tokens count 3654bbd

This is required to calculate the remaining token limit, taking into account existing chat history.

@DmitryKatson
Copy link
Contributor Author

First draft version (for start from blank scenarios) is ready!

It15Vxr4vX-ezgif com-cut

It uses:

  • tools calling, for getting user intent and getting data from BC
  • multiple LLM calls, as getting 120+ correct json objects in the output is not possible. Need to chunk calls and then concatenate results in the end in one big response
  • retry logic in case of format inconsistency, etc.

Should i continue on the next scenario, or should i push draft PR for early preview?

@JesperSchulz
Copy link
Contributor

  • multiple LLM calls, as getting 120+ correct json objects in the output is not possible. Need to chunk calls and then concatenate results in the end in one big response

Those are amazing news! You're truly on 🔥! I tend to suggest to do a DRAFT PR - better to get eyes on your work early. It's also easier to review code in smaller chunks. Large PRs tend to lead to "review fatigue". But in the end it's up to you how you prefer to work. Personally, I cannot wait to see your code 😎

@DmitryKatson
Copy link
Contributor Author

DmitryKatson commented Mar 16, 2024

Updated diagram

diagram-export-16-03-2024-13_39_19

@DmitryKatson DmitryKatson linked a pull request Mar 16, 2024 that will close this issue
@DmitryKatson
Copy link
Contributor Author

  • multiple LLM calls, as getting 120+ correct json objects in the output is not possible. Need to chunk calls and then concatenate results in the end in one big response

Those are amazing news! You're truly on 🔥! I tend to suggest to do a DRAFT PR - better to get eyes on your work early. It's also easier to review code in smaller chunks. Large PRs tend to lead to "review fatigue". But in the end it's up to you how you prefer to work. Personally, I cannot wait to see your code 😎

And here we go #764 ;)

@JesperSchulz JesperSchulz linked a pull request Mar 18, 2024 that will close this issue
JesperSchulz added a commit that referenced this issue Mar 22, 2024
#716)

Add new Json module to provide tools for working with JSON data,
including reading, writing, and parsing JSON. Introduces codeunit for
initializing JSON array and object, retrieving element counts, fetching
objects by index, and getting values for specified record fields.
Implements methods to interact with JSON data using .NET types.

This is partial implementation of the`Base Application` `codeunit 5459
"Json management"`

<!-- Thank you for submitting a Pull Request. If you're new to
contributing to BCApps please read our pull request guideline below
* https://github.com/microsoft/BCApps/Contributing.md
-->
#### Summary 

This PR is required for the [Number Series
Copilot](#659) implementation
as we agreed
[here](#659 (comment))

#### Work Item(s) 
Fixes #715

Fixes
[AB#506714](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/506714)

---------

Co-authored-by: Jesper Schulz-Wedde <JesperSchulz@users.noreply.github.com>
Co-authored-by: Darrick <darjoo@users.noreply.github.com>
@bcbuild-github-agent bcbuild-github-agent added the Linked Issue is linked to a Azure Boards work item label Mar 26, 2024
@VGEELH
Copy link

VGEELH commented May 13, 2024

Hi gents,

i bumped into this branch from a LinkedIn post.
Just for your records: i am 90% the application guy and only 10% technical.

From a use-case perspective: is the Co-Pilot functionality designed to support the yearly No. Series agony, aka the process of re-iussing new No series Lines for posted documents, containing new lines for eachmonth/year/Q ...

If so, very happy to join the discussion.

@DmitryKatson
Copy link
Contributor Author

Hi gents,

i bumped into this branch from a LinkedIn post.

Just for your records: i am 90% the application guy and only 10% technical.

From a use-case perspective: is the Co-Pilot functionality designed to support the yearly No. Series agony, aka the process of re-iussing new No series Lines for posted documents, containing new lines for eachmonth/year/Q ...

If so, very happy to join the discussion.

We have this scenario in mind, however deeper investigation will be required. Can you provide examples of no series lines that you need to update every year?

@VGEELH
Copy link

VGEELH commented May 14, 2024

Hi Dmitry,
Thanks for getting back on this on.

Bottom line for this use case is the fact that companies update their No Series Lines in order to be able to

  • distinguish documents easily by the fact that the FY is visible IN the attributed No Value
  • comply to local legislation (f.i. Invoices and CN MUST restart at 1 at the beginning of a new FY, and contain the FY in it)
  • spit No Series Lines in monthly layers, in order to quickly spot when documents were created (typical in Sales orders and Purchase orders in FMCG where prices evolve quickly)

At first glance: the NoSeries that are referred to in Sales & Receivalbles Setup / Purchase and Payables Setup / Manufacturing Setup / ... %MODULE NAME% Setup are the most common No Series to undergo this treatment.

Please allow me the time to prepare a full scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Linked Issue is linked to a Azure Boards work item Requires PG Review Requires a review session with the product group to settle on the design details.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants