Skip to content

Create Python ChatApp example for AI configuration #1065

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 22, 2025

This PR adds a Python ChatApp example that mirrors the functionality of the .NET Core ChatApp sample for AI configuration.

Key Features

  • Implemented using Python and Flask as required
  • Uses azure-appconfiguration-provider for configuration management
  • Configured to load and refresh settings from Azure App Configuration
  • Integrates with Azure OpenAI for chat completions
  • Supports both web interface and console-like views
  • Leverages modern Python practices and the latest stable packages

Implementation Details

  • Created a Python application that mirrors the functionality of the .NET Core ChatApp example
  • Implemented model classes equivalent to the .NET Message and ModelConfiguration classes
  • Added support for dynamically refreshing configuration from Azure App Configuration
  • Built a web UI for chatting with the AI, as well as a console-like mode

Files Added

  • app.py - Main Flask application with Azure OpenAI integration
  • models.py - Contains data model classes for Message and ModelConfiguration
  • requirements.txt - Dependencies with latest stable versions
  • README.md - Setup and usage documentation
  • templates/ - HTML templates for the web interface

Fixes #1064.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@mrm9084
Copy link
Member

mrm9084 commented May 22, 2025

I've updated the description, this should be a console app, so Flask isn't needed.

Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Create Python ChatApp example for AI configuration Create Python ChatApp example for AI configuration May 22, 2025
@Copilot Copilot AI requested a review from mrm9084 May 22, 2025 15:57
Copilot finished work on behalf of mrm9084 May 22, 2025 15:57
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 22, 2025

I've updated the description, this should be a console app, so Flask isn't needed.

I've converted the app from a Flask web application to a console app similar to the .NET Core implementation. The changes include removing Flask dependencies, implementing a console-based interface with a continuous loop, and updating the documentation. All templates have been removed since they're not needed for a console app. See commit caf9cd0.

Copilot finished work on behalf of mrm9084 May 22, 2025 16:02
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copilot finished work on behalf of mrm9084 May 22, 2025 16:09
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copilot finished work on behalf of mrm9084 May 22, 2025 16:17
@mrm9084 mrm9084 marked this pull request as ready for review May 22, 2025 17:21
index, prop = parts
if index not in message_configs:
message_configs[index] = {}
message_configs[index][prop.lower()] = config[key]
Copy link
Contributor

Choose a reason for hiding this comment

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

@mrm9084 is there a way to do data binding so users don't need to parse configuration manually like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented data binding for the configuration using Pydantic in 6466ad8. This approach allows us to bind configuration values directly to model classes without manual parsing. The implementation includes a bind_config_section utility function that automatically maps configuration values to Pydantic models, handling nested structures like the messages list. This makes the code more maintainable and eliminates the manual parsing previously done in the get_model_configuration function.

Copy link
Member

Choose a reason for hiding this comment

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

@zhenlan we can as Copilot just showed, but I usually avoid the external dependency when it isn't needed.

@copilot can you do it in a way that doesn't use the external dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented the data binding functionality without using an external dependency. The solution uses plain Python classes with type annotations and from_dict methods to handle the configuration binding. The bind_config_section function now works with standard Python classes instead of Pydantic models, while maintaining the same functionality for binding nested structures like messages. See commit d377f84.

Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com>
Copilot finished work on behalf of zhenlan May 23, 2025 17:39
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copilot finished work on behalf of mrm9084 May 23, 2025 17:45
Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com>
Copilot finished work on behalf of zhenlan May 23, 2025 18:03
Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com>
Copilot finished work on behalf of zhenlan May 23, 2025 18:09
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copilot finished work on behalf of mrm9084 May 23, 2025 18:13
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copilot finished work on behalf of mrm9084 May 23, 2025 18:16
…redential

Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copilot finished work on behalf of mrm9084 May 23, 2025 18:22
@mrm9084
Copy link
Member

mrm9084 commented May 23, 2025

I've fixed the auth and model issues. But the app doesn't actually take in user input to chat.

Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 23, 2025

I've fixed the auth and model issues. But the app doesn't actually take in user input to chat.

I've implemented user input functionality for the chat application in 00136bd. Now the app allows users to have a continuous conversation with the AI model. The app displays the initial messages from the configuration, gets an AI response, and then prompts the user for input. The conversation history is maintained throughout the session while still refreshing configuration parameters at the beginning of each cycle.

Copilot finished work on behalf of mrm9084 May 23, 2025 22:33
@mrm9084 mrm9084 requested a review from Copilot May 23, 2025 23:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a Python ChatApp sample that mirrors the .NET Core ChatApp sample, enabling chat interactions via both web and console interfaces.

  • Implements a Flask-based application that integrates Azure App Configuration and Azure OpenAI.
  • Defines model classes for messages and model configurations with dynamic configuration refresh support.
  • Includes updated dependency declarations and comprehensive setup documentation.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
examples/Python/ChatApp/requirements.txt Added necessary dependencies for Azure and OpenAI integration
examples/Python/ChatApp/models.py Added data model classes for Message and ModelConfiguration
examples/Python/ChatApp/app.py Implemented Flask app with configuration refresh and chat logic
examples/Python/ChatApp/README.md Documented setup, usage instructions, and configuration details

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Python ChatApp example for AI configuration
3 participants