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

[Copilot No. Series] Number series copilot #764

Merged
merged 81 commits into from
Aug 1, 2024

Conversation

DmitryKatson
Copy link
Contributor

@DmitryKatson DmitryKatson commented Mar 16, 2024

Summary

Introducing the first [draft] version of a "Number Series Copilot" for Business Central, an innovative feature designed to simplify the creation of number series through natural language commands. This 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.

Current version is intent to create number series for NEW company, where no Number Series exist yet.

Number.Series.Copilot.-.New.company.Scenario.mp4

This flow was tested on the Set up numbers series for the new company like user prompts

Please follow this diagram (green flow), to get the idea of the ongoing process.

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

Key ideas:

  • Azure OpenAI Tools calling is used to understand the user intent
  • AL is used to gather data from BC and build tool response
  • The new company flow requires about 120 different number series to be generated. Nor GPT-4, not GPT 3.5 turbo (latest) where possible to generate accurate json array with 1 go
  • Thus, instead of 1 LLM call to build 120 number series, the tool response is been chunked, to generate not more than 10 number series in one go
  • All LLM generations results (12 in total, each requires 5-9 sec of GPT 3.5 time) then been combined in 1 answer, which is presented to the user

Setup:

  • Use No. Series with Copilot Setup to set up Azure Open AI connection and prompts
  • Prompts should be provided separately (using other channels) due to security reasons
  • Model used: gpt-35-turbo-1106
image

Work Item(s)

Fixes #659
Fixes AB#503148

…ut AI implementation business logic)

Added new app components and capabilities for the No. Series Copilot app, including codeunits, page extensions, pages, and tables, to introduce AI features for generating number series. Additionally, new registers and installers were included to handle capability registration and app installation. This enhances the app's functionality and extensibility.
Update page and table numbers as there was overflow with the Base Application.
- Temporary adding Number Series Copilot Setup table and page to store aoai secrets, system prompt and functions prompt in the isolated storage.
- Add Jupyter Notebook patterns to gitignore.
- Updating codeunit, page, and table objects numbers.
The code refactor improves tool retrieval, adds tool ID handling, and updates UI elements. The changes aim to enhance the No. Series Copilot tool functionality and user experience. These alterations are crucial for integrating Azure Key Vault in future.

Include tool calls to the chat history

- Add support for tool call IDs in chat history, improving traceability and accountability for tool call results. The changes enable associating tool call IDs with tool messages in the chat history, enhancing the clarity and transparency of the interactions. This update aligns with the need to provide comprehensive context for tool call responses within the chat history.
- Introduce 'AddToolMessage' method and modify existing methods to capture tool-related data for chat messages.
- Add 'HistoryToolCallIds' list to save tool call IDs for messages.
- Create 'IsToolsList' method to check if a message contains tool-related information.
- Update 'AOAIChatRoles.Enum.al' to define a new 'tool' chat role.

These changes enable the tracking and differentiation of tool call results in chat history.
Enable support for returning valid JSON object as chat completion, adding guidelines for JSON production, and checking compatibility for JSON response format.
Improve json output format specification declaration and [TEMPORARY] implement no. series number limitations to avoid reaching token limit and timeout when dealing with many tables.
Consolidates tool invocation logic by using a dedicated function and refines prompt formats for better user experience. Also updates existing patterns to reflect more accurate numbering conventions. These changes aim to streamline tool usage and enhance prompt clarity.
Consolidate tool retrieval methods; refactor output format instructions.
Improved modularity and maintainability.
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 partly ported from Base Application codeunit 5459 "Json management"
Additionally, the visibility of response text on the No. Series Proposal Page is dynamically managed, depending on json response validation
Tools message parsing into `function name`, `arguments` and `tool call id`
Replace direct parsing with dedicated method for improved maintainability and readability. This enhances code structure and sets the stage for future extensibility. No related issues.
…f the tool response exceeds token limit.

Ensure secure handling of sensitive data in chat messages by swapping text types with secure text types. Implement chunking of tool responses to avoid exceeding token limits, resulting in improved prompt generation for new number series. Indirectly address potential security vulnerabilities and enhance system functionality.
Change the dictionary to standardize chunk processing of tables in order to avoid hallucinations and effectively handle large volumes. This ensures accurate and complete model responses, enhancing overall functionality. The refactor also introduces new helper functions to process tool completions and validate generated number series.
…nd output examples from setup

Introduce methods to retrieve tool 1 patterns and output examples from setup. Also, add labels and separators for better formatting. Improve error handling and optimize code readability.
Improved retrieval of tool 1 general instructions and output format for better modularity and maintainability.
…dle duplicate No. Series codes

This commit refactors JSON manipulation by separating common JSON operations into a separate file and introduces new functionality to handle duplicate No. Series codes using random character generation. This change improves data integrity and ensures uniqueness of No. Series codes. It adds methods to replace or add properties in JSON objects and modify JSON arrays as necessary.
Replace text prompts for tool limitations, code guidelines, description guidelines, number guidelines, output examples, and output format prompts. Add validation for property lengths in generating number series.
Refactor JSON handling methods to return JSON objects and arrays as text, enhancing readability and modularity across the codebase, paving the way for simplified integration with other modules. This change sets the stage for easier maintenance and future expansions of the JSON-related functionalities. No related issues are involved.
DmitryKatson and others added 3 commits July 5, 2024 16:29
Adjusted function to correctly remove the last character in the AreasText variable to ensure proper string formatting. This change ensures accurate text representation.
Copy link
Contributor

@JesperSchulz JesperSchulz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look into the remaining TODOs and open code review comments. It's time to get this code production ready. When we think we're there, we can get one final round of review from the product group.

Adjusted No. Series handling to support 'Is Next Year' scenario and added Next Year Intent tool to facilitate setting up number series for the next year. These changes aim to improve future number series management.
Update a function to handle different scenarios for generating number series prompts based on the current or next year. This change improves flexibility and customization in managing number series adjustments.
@DmitryKatson
Copy link
Contributor Author

🧨 New Skill is added: Prepare for next year.
This skill (or tool) allows to create new number series lines for the next year, if number series are yearly based (have year prefix in the number).

See in the video example.

NextYearNumberSeries.mov

Removed the duplicate "Generate With Copilot" action to optimize code clarity and avoid redundancy. This action was unnecessary due to duplication with an existing action. Refactoring enhances maintainability.
DmitryKatson and others added 11 commits July 24, 2024 16:29
Simplify notification handling by integrating it directly into the main codebase, removing redundant manager code segments. This consolidation streamlines notifications within the NoSeriesCopilot system.
… shift from handling "No. Series Proposal" to "No. Series Generation" and "No. Series Proposal Line" to "No. Series Generation Detail"
@darjoo darjoo merged commit f71bdbd into microsoft:main Aug 1, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AL: Business Foundation From Fork Pull request is coming from a fork Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BC Idea]: Number Series Copilot