Skip to content

Add Azure Functions backend with OpenAI integration for chatbot#73

Merged
fpittelo merged 3 commits intodevfrom
copilot/create-azure-function-chatbot-backend
Nov 23, 2025
Merged

Add Azure Functions backend with OpenAI integration for chatbot#73
fpittelo merged 3 commits intodevfrom
copilot/create-azure-function-chatbot-backend

Conversation

Copy link
Contributor

Copilot AI commented Nov 23, 2025

Implements Task 1.4.1: HTTP-triggered Azure Function to handle chatbot queries via Azure OpenAI.

Implementation

  • Function endpoint: POST /api/chat accepts user messages and optional conversation history, returns AI responses
  • OpenAI integration: Azure OpenAI client with environment-based credentials (AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT)
  • System prompt: AlpineBot persona specialized in Swiss information
  • Input validation: JSON parsing, message presence, conversation history structure validation with 400 responses
  • Error handling: Configuration errors, OpenAI API failures, empty response handling with appropriate status codes

API Contract

# Request
{
  "message": "What are the main cities in Switzerland?",
  "conversation_history": [  # Optional
    {"role": "user", "content": "Tell me about Switzerland"},
    {"role": "assistant", "content": "Switzerland is..."}
  ]
}

# Response
{
  "response": "The main cities include Zurich, Geneva...",
  "status": "success"
}

Dependencies

  • azure-functions==1.24.0 - Function runtime
  • openai==2.8.1 - Azure OpenAI SDK

Pinned versions for reproducible builds. Zero vulnerabilities (verified via gh-advisory-database and CodeQL).

Testing

10 unit tests covering:

  • Missing/malformed inputs (JSON, message, conversation history)
  • Configuration validation (missing credentials)
  • OpenAI error scenarios (API errors, empty responses)
  • Successful chat flow with/without history

All tests pass with mocked OpenAI client.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.functions.azure.com
    • Triggering command: /usr/bin/func func start (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Task 1.4.1: Create an Azure Function for the chatbot backend.</issue_title>
<issue_description>Task 1.4.1: Create an Azure Function for the chatbot backend.
The goal is to successfully and securely connect the chatbot to OpenAI to receive user's queries, and send the response back.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 23, 2025 14:12
Co-authored-by: fpittelo <3135901+fpittelo@users.noreply.github.com>
Co-authored-by: fpittelo <3135901+fpittelo@users.noreply.github.com>
Copilot AI changed the title [WIP] Create Azure Function for chatbot backend integration Add Azure Functions backend with OpenAI integration for chatbot Nov 23, 2025
Copilot AI requested a review from fpittelo November 23, 2025 14:20
Copy link
Owner

@fpittelo fpittelo left a comment

Choose a reason for hiding this comment

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

ok

@fpittelo fpittelo marked this pull request as ready for review November 23, 2025 14:22
@fpittelo fpittelo merged commit bf6144e into dev Nov 23, 2025
@fpittelo fpittelo deleted the copilot/create-azure-function-chatbot-backend branch November 23, 2025 14:28
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.

2 participants