Skip to content

AI Logic Introduction

Step 5 of 8

This part of the workshop guides you on how to integrate your Project Planning Copilot with Azure OpenAI, enabling it to generate intelligent project plans from user inputs.

Before You Start

Make sure you have completed the setup of new PromptDialog UI elements and understand how the part page works. This knowledge is essential for effectively integrating Azure OpenAI services.

Implementing AI Logic

1. Open Implementation File

  • Location: Navigate to "\src\2-PlanningCopilot\Implementation\ProjectPlanCopilotImpl.Codeunit.al".

2. Understand Code Structure

The code skeleton provided includes placeholders for you to add specific code blocks to interact with Azure OpenAI. These sections are crucial for setting up the AI logic to process and generate project plans.

3. Integrate Azure OpenAI

  • Task: Implement the necessary code to enable Azure OpenAI, set authorization, send inputs, receive outputs, and handle errors.
  • Key Implementation Areas:
  • Setting up authorization with Azure OpenAI.
  • Managing data transmission to and from Azure OpenAI.
  • Handling errors from AI operations.

    Info

    Use the GetSystemMessage() procedure to define instructions and limitations for the copilot.

4. System message

The system message is a crucial component in guiding the AI's generation process. It acts as a set of instructions that defines the AI's tasks and boundaries.

The user will describe a project. 
Your task is to prepare the project plan for this project to be used in 
Microsoft Dynamics 365 Business Central.

The output should be in XML format.
Use project as the root level tag, use tasks as list tag, use task as task tag.
The project must contain a shortDescription tag, a detailedDescription tag.

Generate at least 6 tasks for the project. 
Use %1 as a start date for the project, and suggest a timeline. 
Use the yyyy-mm-dd date format for dates.

Each task should contain a shortDescription tag, a detailedDescription tag 
(make sure it''s less than 100 characters), a startDate tag, an endDate tag.

Each task should also contain a type tag, which can be "resource" if the task 
needs a resource, "item" if the task needs a physical item, 
or "both" if it needs both. 

If the type is "item" or "both", include a tag itemCategory, 
if the type is "resource" or "both" include a resourceRole tag.

Structure

  • Instructions: Clearly outlines what the AI is supposed to do. This typically includes the type of content expected (e.g., project plans, tasks), the format (e.g., XML), and specific details like tags or attributes.
  • Limitations: Specifies what the AI should not do, such as avoiding unrelated topics or inappropriate content.
  • Hints: Provides additional context that helps the AI understand the domain or specific requirements (e.g., business, technology).
  • Examples: Offers sample inputs or outputs to illustrate the expected interactions and outcomes.

Influence on AI

  • Precision: The system message directly influences the AI's focus and output, guiding it to generate content that aligns with the user's needs.
  • Accuracy: By specifying detailed instructions and expected formats, the system message helps improve the relevance and accuracy of the AI's output.
  • Consistency: Ensures that the AI consistently adheres to the specified guidelines, providing reliable and predictable results.

    Warning

    Sometimes, AI may not follow the system message exactly due to inherent limitations or unexpected inputs. However, a well-crafted system message can significantly enhance the AI's performance and user experience.

    Info

    Hallucinations are a common issue in AI-generated content, where the AI may produce irrelevant or nonsensical outputs, not aligned with the system message. Proper system message design can help mitigate this issue by providing clear guidelines and constraints for the AI to follow.

Key Takeaway

Think of the system message as a blueprint for the AI. It determines how the AI responds and is important for getting useful and relevant outputs. Changing the system message can greatly impact how the AI behaves, allowing you to customize your interactions with it.

Additional Resources

5. Test and Debug

  • Action: After implementing the AI logic, publish your copilot extension to your Business Central environment and test the functionality.
  • Debugging: Use debugging tools to step through your code and verify that the AI responses are correctly generated and processed.

Tip

If you encounter any compilation errors, not related to the AI Logic, you can temporarily comment the non-related code to focus on the AI Logic implementation.

6. Azure OpenAI Playground

In the Azure AI Studio Playground, you can explore, prototype, and test AI models, to understand how they process and generate content. This can help you refine your AI logic and system message for better results.

Go to the Azure OpenAI Studio

Navigate to Azure OpenAI Studio at https://oai.azure.com/ and sign-in with credentials that have access to your OpenAI resource. During or after the sign-in workflow, select the appropriate directory, Azure subscription, and Azure OpenAI resource.

From the Azure OpenAI Studio landing page launch the Chat playground from the left-hand navigation Playground > Chat

Paste the system message and user input in the respective fields and observe the AI's response.

  • Examine: Look at how the AI structures its response in XML format. Understand how the AI's output aligns with the expected structure for project plans in Business Central.
  • Adjustments: Make necessary adjustments to the AI prompts or handling logic based on the observed outputs to improve the relevance and accuracy of the generated plans.

Conclusion

You now have a functioning AI logic within your Project Planning Copilot capable of generating detailed project plans. Experiment with different inputs to evaluate how the AI interprets and responds.

Remember, the effectiveness of your copilot largely depends on the clarity and detail of the system message and the robustness of your integration logic. Continue refining these elements to enhance the copilot's utility and reliability.

Next Steps

Proceed to the next step to learn how to convert these text generated project plans into actionable items within Dynamics 365 Business Central.