Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ba88bd6
Author: Pamela Fox <[email protected]>
Date:   Thu Oct 19 17:37:00 2023 -0700

    Add front-matter needed for Sample browser (Azure-Samples#816)

    * Sample markup

    * Sample browser

    * Sample browser

    * Move less interesting things to the end

    * Move less interesting things to the end

    * Less descrip

    * Add ACS

commit d53fdb1
Author: Pamela Fox <[email protected]>
Date:   Thu Oct 19 16:26:17 2023 -0700

    Run prettier on files and add to precommit/CI (Azure-Samples#834)

    * Lint the frontend

    * Revert repo changes

    * Use prettier config in app/frontend

    * Use prettier config in app/frontend

    * Update comment

commit 1dd756f
Author: Pamela Fox <[email protected]>
Date:   Thu Oct 19 15:00:27 2023 -0700

    Fix if for tests running (Azure-Samples#833)

commit 97433c1
Author: Chris Harris <[email protected]>
Date:   Wed Oct 18 20:42:30 2023 -0700

    Update README.md - Dev Containers (Azure-Samples#829)

    Replace Remote Containers with Dev Containers
    Add instructions for using Dev Containers

commit a4801f9
Author: Pamela Fox <[email protected]>
Date:   Wed Oct 18 15:27:35 2023 -0700

    Support windows by using uvicorn without extras (Azure-Samples#815)

    * Support windows by using no extras

    * Try tests on Windows

    * jsonlines endings

    * debugging win

    * Try retry

    * Try retry

    * Warmup test

    * Warmup test

    * Warmup test

    * Add conditional to only run in Ubuntu

    * Revert other changes

    * Revert other changes

    * Revert other changes

    ---------

    Co-authored-by: Anthony Shaw <[email protected]>

commit 3475bb6
Author: Tim <[email protected]>
Date:   Wed Oct 18 06:47:48 2023 -0700

    Change role from bot to assistant to fix bug when asking follow-up question in chat (Azure-Samples#823)

commit f50db74
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Oct 17 22:06:09 2023 -0700

    Bump urllib3 from 2.0.6 to 2.0.7 in /app/backend (Azure-Samples#820)

    * Bump urllib3 from 2.0.6 to 2.0.7 in /app/backend

    Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.0.6 to 2.0.7.
    - [Release notes](https://github.com/urllib3/urllib3/releases)
    - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
    - [Commits](urllib3/urllib3@2.0.6...2.0.7)

    ---
    updated-dependencies:
    - dependency-name: urllib3
      dependency-type: indirect
    ...

    Signed-off-by: dependabot[bot] <[email protected]>

    * Update scripts too

    ---------

    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Pamela Fox <[email protected]>
    Co-authored-by: Pamela Fox <[email protected]>

commit 1844b00
Author: Matt <[email protected]>
Date:   Tue Oct 17 21:51:32 2023 -0700

    Add scheduler package (Azure-Samples#822)

    * add scheduler package

    * Fix new test

    ---------

    Co-authored-by: Pamela Fox <[email protected]>

commit 07c2afa
Author: Pamela Fox <[email protected]>
Date:   Tue Oct 17 12:35:54 2023 -0700

    Message builder fixes for history format and token count (Azure-Samples#778)

    * Message builder fixes

    * Fix types

    * Address Sri's comments

    * Update logic per Sris feedback

    * Test and log

commit 69c4147
Author: Kesavaraja Krishnan <[email protected]>
Date:   Mon Oct 16 22:57:07 2023 +0530

    Increased maxtoken to avoid malformed JSON in chatreadretrieveread.py (Azure-Samples#681)

    * Increased maxtoken to chatgpt_token_limit in chatreadretrieveread.

    * Modified to 1024 characters.

    * Change to 100

    ---------

    Co-authored-by: Pamela Fox <[email protected]>

commit 774c47c
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Oct 16 09:34:03 2023 -0700

    Bump @babel/traverse from 7.23.0 to 7.23.2 in /app/frontend (Azure-Samples#812)

    Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.23.0 to 7.23.2.
    - [Release notes](https://github.com/babel/babel/releases)
    - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

    ---
    updated-dependencies:
    - dependency-name: "@babel/traverse"
      dependency-type: indirect
    ...

    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit e02b347
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Oct 16 09:27:11 2023 -0700

    Bump the node-packages group in /app/frontend with 5 updates (Azure-Samples#800)

    Bumps the node-packages group in /app/frontend with 5 updates:

    | Package | From | To |
    | --- | --- | --- |
    | [@fluentui/react](https://github.com/microsoft/fluentui) | `8.112.2` | `8.112.3` |
    | [@fluentui/react-components](https://github.com/microsoft/fluentui) | `9.34.2` | `9.35.0` |
    | [@fluentui/react-icons](https://github.com/microsoft/fluentui-system-icons) | `2.0.219` | `2.0.220` |
    | [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) | `18.2.27` | `18.2.28` |
    | [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) | `18.2.12` | `18.2.13` |

    Updates `@fluentui/react` from 8.112.2 to 8.112.3
    - [Release notes](https://github.com/microsoft/fluentui/releases)
    - [Changelog](https://github.com/microsoft/fluentui/blob/master/azure-pipelines.release-fluentui.yml)
    - [Commits](https://github.com/microsoft/fluentui/compare/@fluentui/react_v8.112.2...@fluentui/react_v8.112.3)

    Updates `@fluentui/react-components` from 9.34.2 to 9.35.0
    - [Release notes](https://github.com/microsoft/fluentui/releases)
    - [Changelog](https://github.com/microsoft/fluentui/blob/master/azure-pipelines.release-fluentui.yml)
    - [Commits](https://github.com/microsoft/fluentui/compare/@fluentui/react-components_v9.34.2...@fluentui/react-components_v9.35.0)

    Updates `@fluentui/react-icons` from 2.0.219 to 2.0.220
    - [Commits](https://github.com/microsoft/fluentui-system-icons/commits)

    Updates `@types/react` from 18.2.27 to 18.2.28
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

    Updates `@types/react-dom` from 18.2.12 to 18.2.13
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

    ---
    updated-dependencies:
    - dependency-name: "@fluentui/react"
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: node-packages
    - dependency-name: "@fluentui/react-components"
      dependency-type: direct:production
      update-type: version-update:semver-minor
      dependency-group: node-packages
    - dependency-name: "@fluentui/react-icons"
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: node-packages
    - dependency-name: "@types/react"
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: node-packages
    - dependency-name: "@types/react-dom"
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: node-packages
    ...

    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 8c83284
Author: Will Fox <[email protected]>
Date:   Sat Oct 14 12:37:12 2023 -0500

    Add arguments required for OpenAI connection (Azure-Samples#796)

    * Add arguments required for OpenAI connection

    * Remove unnecessary args

commit 5300bb5
Author: ks6088ts <[email protected]>
Date:   Sat Oct 14 09:01:32 2023 +0900

    support non English languages (Azure-Samples#780)

    * add search analyzer name option to prepdocs script

    * parameterize search query language and search query speller

    * update IaC codes to inject environment variables to app service

    * apply formatter via `black .`

    * update reference links

    * update descriptions to reflect review comments

commit 08fdbd1
Author: Pamela Fox <[email protected]>
Date:   Fri Oct 13 13:58:21 2023 -0700

    Improvements to VS Code and Vite debug experience (Azure-Samples#786)

    * Initial launch improvements

    * Fix up extensions

commit 475885e
Author: Pamela Fox <[email protected]>
Date:   Fri Oct 13 13:54:56 2023 -0700

    Daily tests (Azure-Samples#787)

commit ca09627
Author: Matt <[email protected]>
Date:   Thu Oct 12 11:04:00 2023 -0700

    Use absolute redirect uris for login and fetching tokens (Azure-Samples#784)

commit 7c614bb
Author: Pamela Fox <[email protected]>
Date:   Thu Oct 12 09:12:33 2023 -0700

    Adding session_state to conform to ChatApp protocol (Azure-Samples#773)

    * Adding session_state

    * Pass null vs undef

commit ff273c2
Author: Pamela Fox <[email protected]>
Date:   Tue Oct 10 14:51:24 2023 -0700

    Rm print statements (Azure-Samples#772)

commit 3324bdb
Author: Pamela Fox <[email protected]>
Date:   Tue Oct 10 14:22:45 2023 -0700

    Chat response (Azure-Samples#748)

    * Adding anchors

    * Prelim change to support chatresponse schema

    * Update test data to use role properly

    * Change log level back

    * Remove debugging

    * Remove debugging

    * Fix role location

    * Use chat response protocol

    * Updates e2e tests per response change

commit 7b2e887
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Oct 10 11:17:14 2023 -0700

    Bump the node-packages group in /app/frontend with 7 updates (Azure-Samples#771)

    Bumps the node-packages group in /app/frontend with 7 updates:

    | Package | From | To |
    | --- | --- | --- |
    | [@fluentui/react-components](https://github.com/microsoft/fluentui) | `9.33.0` | `9.34.2` |
    | [@fluentui/react-icons](https://github.com/microsoft/fluentui-system-icons) | `2.0.218` | `2.0.219` |
    | [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) | `18.2.14` | `18.2.27` |
    | [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) | `18.2.8` | `18.2.12` |
    | [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/HEAD/packages/plugin-react) | `4.0.2` | `4.1.0` |
    | [typescript](https://github.com/Microsoft/TypeScript) | `5.1.6` | `5.2.2` |
    | [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) | `4.4.2` | `4.4.11` |

    Updates `@fluentui/react-components` from 9.33.0 to 9.34.2
    - [Release notes](https://github.com/microsoft/fluentui/releases)
    - [Changelog](https://github.com/microsoft/fluentui/blob/master/azure-pipelines.release-fluentui.yml)
    - [Commits](https://github.com/microsoft/fluentui/compare/@fluentui/react-components_v9.33.0...@fluentui/react-components_v9.34.2)

    Updates `@fluentui/react-icons` from 2.0.218 to 2.0.219
    - [Commits](https://github.com/microsoft/fluentui-system-icons/commits)

    Updates `@types/react` from 18.2.14 to 18.2.27
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

    Updates `@types/react-dom` from 18.2.8 to 18.2.12
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

    Updates `@vitejs/plugin-react` from 4.0.2 to 4.1.0
    - [Release notes](https://github.com/vitejs/vite-plugin-react/releases)
    - [Changelog](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/CHANGELOG.md)
    - [Commits](https://github.com/vitejs/vite-plugin-react/commits/v4.1.0/packages/plugin-react)

    Updates `typescript` from 5.1.6 to 5.2.2
    - [Release notes](https://github.com/Microsoft/TypeScript/releases)
    - [Commits](microsoft/TypeScript@v5.1.6...v5.2.2)

    Updates `vite` from 4.4.2 to 4.4.11
    - [Release notes](https://github.com/vitejs/vite/releases)
    - [Changelog](https://github.com/vitejs/vite/blob/v4.4.11/packages/vite/CHANGELOG.md)
    - [Commits](https://github.com/vitejs/vite/commits/v4.4.11/packages/vite)

    ---
    updated-dependencies:
    - dependency-name: "@fluentui/react-components"
      dependency-type: direct:production
      update-type: version-update:semver-minor
      dependency-group: node-packages
    - dependency-name: "@fluentui/react-icons"
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: node-packages
    - dependency-name: "@types/react"
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: node-packages
    - dependency-name: "@types/react-dom"
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: node-packages
    - dependency-name: "@vitejs/plugin-react"
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: node-packages
    - dependency-name: typescript
      dependency-type: direct:development
      update-type: version-update:semver-minor
      dependency-group: node-packages
    - dependency-name: vite
      dependency-type: direct:development
      update-type: version-update:semver-patch
      dependency-group: node-packages
    ...

    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 2b9119a
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Oct 10 11:06:31 2023 -0700

    Bump @fluentui/react from 8.110.7 to 8.112.2 in /app/frontend (Azure-Samples#759)

    Bumps [@fluentui/react](https://github.com/microsoft/fluentui) from 8.110.7 to 8.112.2.
    - [Release notes](https://github.com/microsoft/fluentui/releases)
    - [Changelog](https://github.com/microsoft/fluentui/blob/master/azure-pipelines.release-fluentui.yml)
    - [Commits](https://github.com/microsoft/fluentui/compare/@fluentui/react_v8.110.7...@fluentui/react_v8.112.2)

    ---
    updated-dependencies:
    - dependency-name: "@fluentui/react"
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 79bfb0f
Author: Pamela Fox <[email protected]>
Date:   Tue Oct 10 10:54:06 2023 -0700

    Add more Playwright tests to check all routes and buttons (Azure-Samples#743)

    * Adding anchors

    * E2E tests

commit e69e884
Author: Pamela Fox <[email protected]>
Date:   Mon Oct 9 17:32:42 2023 -0700

    Urllib3 update for security issue (Azure-Samples#728)

    * Adding anchors

    * update urllib3

commit 25a2e0e
Author: Pamela Fox <[email protected]>
Date:   Mon Oct 9 17:32:07 2023 -0700

    Fixed type annotations per mypy and added mypy to CICD (Azure-Samples#749)

    * Adding anchors

    * Fix mypy types

commit dd5dcea
Author: Pamela Fox <[email protected]>
Date:   Mon Oct 9 14:37:53 2023 -0700

    Grouped updates (Azure-Samples#729)

    * Adding anchors

    * Grouped updates

commit 0c31808
Author: Pamela Fox <[email protected]>
Date:   Mon Oct 9 14:32:25 2023 -0700

    Python version updates (Azure-Samples#761)

    * Adding anchors

    * Python version changes
  • Loading branch information
vishalgtingre committed Oct 22, 2023
1 parent 1088f3b commit a656624
Show file tree
Hide file tree
Showing 96 changed files with 2,674 additions and 2,888 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Azure Search OpenAI Demo",
"image": "mcr.microsoft.com/devcontainers/python:3.10",
"image": "mcr.microsoft.com/devcontainers/python:3.11",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "16",
Expand All @@ -15,7 +15,8 @@
"extensions": [
"ms-azuretools.azure-dev",
"ms-azuretools.vscode-bicep",
"ms-python.python"
"ms-python.python",
"esbenp.prettier-vscode"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.sh text eol=lf
*.sh text eol=lf
*.jsonlines text eol=lf
17 changes: 17 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,36 @@ updates:
directory: "/"
schedule:
interval: "weekly"
groups:
github-actions:
patterns:
- "*"

# Maintain dependencies for npm
- package-ecosystem: "npm"
directory: "/app/frontend"
schedule:
interval: "weekly"
groups:
node-packages:
patterns:
- "*"

# Maintain dependencies for pip
- package-ecosystem: "pip"
directory: "/app/backend"
schedule:
interval: "weekly"
groups:
python-requirements:
patterns:
- "*"

- package-ecosystem: "pip"
directory: "/scripts"
schedule:
interval: "weekly"
groups:
python-requirements:
patterns:
- "*"
18 changes: 18 additions & 0 deletions .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Frontend linting

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run prettier on frontend
run: |
cd ./app/frontend
npm install
npx prettier --check .
10 changes: 8 additions & 2 deletions .github/workflows/python-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 0 * * *' # Run at midnight every day

jobs:
test_package:
Expand All @@ -13,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-20.04"]
os: ["ubuntu-20.04", "windows-latest"]
python_version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
Expand All @@ -37,11 +39,15 @@ jobs:
pip install -r requirements-dev.txt
- name: Lint with ruff
run: ruff .
- name: Check types with mypy
run: python3 -m mypy scripts/ app/
- name: Check formatting with black
run: black . --check --verbose
- name: Run Python tests
run: python3 -m pytest --cov --cov-fail-under=78
if: runner.os != 'Windows'
run: python3 -m pytest -s -vv --cov --cov-fail-under=78
- name: Run E2E tests with Playwright
if: runner.os != 'Windows'
run: |
playwright install --with-deps
python3 -m pytest tests/e2e.py
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ repos:
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
types_or: [css, javascript, ts, tsx, html]
8 changes: 5 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"ms-azuretools.azure-dev"
"ms-azuretools.azure-dev",
"ms-azuretools.vscode-bicep",
"ms-python.python",
"esbenp.prettier-vscode"
]
}
}
21 changes: 2 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,10 @@
},
{
"name": "Frontend: watch",
"type": "node",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev",
"cwd": "${workspaceFolder}/app/frontend",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"watch"
],
"console": "integratedTerminal",
},
{
"name": "Frontend: build",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/app/frontend",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"build"
],
"console": "integratedTerminal",
}
],
"inputs": [
Expand Down
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
---
name: ChatGPT + Enterprise data
description: Chat with your data using OpenAI and Cognitive Search.
languages:
- azdeveloper
- typescript
- python
- bicep
products:
- azure
- azure-cognitive-search
- azure-openai
- azure-app-service
page_type: sample
urlFragment: azure-search-openai-demo
---

# ChatGPT + Enterprise data with Azure OpenAI and Cognitive Search

## Table of Contents
Expand All @@ -8,7 +25,7 @@
- [Cost estimation](#cost-estimation)
- [Project setup](#project-setup)
- [GitHub Codespaces](#github-codespaces)
- [VS Code Remote Containers](#vs-code-remote-containers)
- [VS Code Dev Containers](#vs-code-dev-containers)
- [Local environment](#local-environment)
- [Deploying from scratch](#deploying-from-scratch)
- [Deploying with existing Azure resources](#deploying-with-existing-azure-resources)
Expand All @@ -28,7 +45,7 @@
- [Troubleshooting](#troubleshooting)

[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=599293758&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
[![Open in Remote - Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-search-openai-demo)
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-search-openai-demo)

This sample demonstrates a few approaches for creating ChatGPT-like experiences over your own data using the Retrieval Augmented Generation pattern. It uses Azure OpenAI Service to access the ChatGPT model (gpt-35-turbo), and Azure Cognitive Search for data indexing and retrieval.

Expand Down Expand Up @@ -87,18 +104,23 @@ You can run this repo virtually by using GitHub Codespaces, which will open a we

[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=599293758&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)

#### VS Code Remote Containers
#### VS Code Dev Containers

A related option is VS Code Remote Containers, which will open the project in your local VS Code using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers):
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers):

[![Open in Remote - Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-search-openai-demo)
1. Start Docker Desktop (install it if not already installed)
1. Open the project:
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-search-openai-demo)
1. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window
1. Run `azd auth login`
1. Now you can follow the instructions in [Deploying from scratch](#deploying-from-scratch) below

#### Local environment

First install the required tools:

* [Azure Developer CLI](https://aka.ms/azure-dev/install)
* [Python 3.9+](https://www.python.org/downloads/)
* [Python 3.9, 3.10, or 3.11](https://www.python.org/downloads/)
* **Important**: Python and the pip package manager must be in the path in Windows for the setup scripts to work.
* **Important**: Ensure you can run `python --version` from console. On Ubuntu, you might need to run `sudo apt install python-is-python3` to link `python` to `python3`.
* [Node.js 14+](https://nodejs.org/en/download/)
Expand Down Expand Up @@ -170,6 +192,11 @@ When you run `azd up` after and are prompted to select a value for `openAiResour
1. If the search service's SKU is not standard, then run `azd env set AZURE_SEARCH_SERVICE_SKU {Name of SKU}`. The free tier won't work as it doesn't support managed identity. ([See other possible values](https://learn.microsoft.com/azure/templates/microsoft.search/searchservices?pivots=deployment-language-bicep#sku))
1. If you have an existing index that is set up with all the expected fields, then run `azd env set AZURE_SEARCH_INDEX {Name of existing index}`. Otherwise, the `azd up` command will create a new index.

You can also customize the search service (new or existing) for non-English searches:

1. To configure the language of the search query to a value other than "en-us", run `azd env set AZURE_SEARCH_QUERY_LANGUAGE {Name of query language}`. ([See other possible values](https://learn.microsoft.com/python/api/azure-search-documents/azure.search.documents.models.querylanguage?view=azure-python-preview))
1. To turn off the spell checker, run `azd env set AZURE_SEARCH_QUERY_SPELLER none`. ([See other possible values](https://learn.microsoft.com/python/api/azure-search-documents/azure.search.documents.models.queryspellertype?view=azure-python-preview))
1. To configure the name of the analyzer to use for a searchable text field to a value other than "en.microsoft", run `azd env set AZURE_SEARCH_ANALYZER_NAME {Name of analyzer name}`. ([See other possible values](https://learn.microsoft.com/dotnet/api/microsoft.azure.search.models.field.analyzer?view=azure-dotnet-legacy&viewFallbackFrom=azure-dotnet))

#### Other existing Azure resources

Expand Down Expand Up @@ -418,7 +445,7 @@ to one of the [allowed log levels](https://docs.python.org/3/library/logging.htm
If you need to log in a route handler, use the the global variable `current_app`'s logger:

```python
async def chat_stream():
async def chat():
current_app.logger.info("Received /chat request")
```

Expand Down
65 changes: 30 additions & 35 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,20 @@ async def ask():
if not request.is_json:
return jsonify({"error": "request must be json"}), 415
request_json = await request.get_json()
context = request_json.get("context", {})
auth_helper = current_app.config[CONFIG_AUTH_CLIENT]
auth_claims = await auth_helper.get_auth_claims_if_enabled(request.headers)
context["auth_claims"] = await auth_helper.get_auth_claims_if_enabled(request.headers)
try:
impl = current_app.config[CONFIG_ASK_APPROACH]
approach = current_app.config[CONFIG_ASK_APPROACH]
# Workaround for: https://github.com/openai/openai-python/issues/371
async with aiohttp.ClientSession() as s:
openai.aiosession.set(s)
r = await impl.run(request_json["question"], request_json.get("overrides") or {}, auth_claims)
return jsonify(r)
except Exception as e:
logging.exception("Exception in /ask")
return jsonify({"error": str(e)}), 500


@bp.route("/chat", methods=["POST"])
async def chat():
if not request.is_json:
return jsonify({"error": "request must be json"}), 415
request_json = await request.get_json()
auth_helper = current_app.config[CONFIG_AUTH_CLIENT]
auth_claims = await auth_helper.get_auth_claims_if_enabled(request.headers)
try:
impl = current_app.config[CONFIG_CHAT_APPROACH]
# Workaround for: https://github.com/openai/openai-python/issues/371
async with aiohttp.ClientSession() as s:
openai.aiosession.set(s)
r = await impl.run_without_streaming(
request_json["history"], request_json.get("overrides", {}), auth_claims
r = await approach.run(
request_json["messages"], context=context, session_state=request_json.get("session_state")
)
return jsonify(r)
except Exception as e:
logging.exception("Exception in /chat")
logging.exception("Exception in /ask")
return jsonify({"error": str(e)}), 500


Expand All @@ -128,24 +110,30 @@ async def format_as_ndjson(r: AsyncGenerator[dict, None]) -> AsyncGenerator[str,
yield json.dumps(event, ensure_ascii=False) + "\n"


@bp.route("/chat_stream", methods=["POST"])
async def chat_stream():
@bp.route("/chat", methods=["POST"])
async def chat():
if not request.is_json:
return jsonify({"error": "request must be json"}), 415
print("Iam in app.py in chat stream")

request_json = await request.get_json()
context = request_json.get("context", {})
auth_helper = current_app.config[CONFIG_AUTH_CLIENT]
auth_claims = await auth_helper.get_auth_claims_if_enabled(request.headers)
context["auth_claims"] = await auth_helper.get_auth_claims_if_enabled(request.headers)
try:
impl = current_app.config[CONFIG_CHAT_APPROACH]
response_generator = impl.run_with_streaming(
request_json["history"], request_json.get("overrides", {}), auth_claims
approach = current_app.config[CONFIG_CHAT_APPROACH]
result = await approach.run(
request_json["messages"],
stream=request_json.get("stream", False),
context=context,
session_state=request_json.get("session_state"),
)
response = await make_response(format_as_ndjson(response_generator))
response.timeout = None # type: ignore
print ("Before response in app")
return response
if isinstance(result, dict):
return jsonify(result)
else:
response = await make_response(format_as_ndjson(result))
response.timeout = None # type: ignore
return response
except Exception as e:
logging.exception("Exception in /chat")
return jsonify({"error": str(e)}), 500
Expand Down Expand Up @@ -199,6 +187,9 @@ async def setup_clients():
KB_FIELDS_CONTENT = os.getenv("KB_FIELDS_CONTENT", "content")
KB_FIELDS_SOURCEPAGE = os.getenv("KB_FIELDS_SOURCEPAGE", "sourcepage")

AZURE_SEARCH_QUERY_LANGUAGE = os.getenv("AZURE_SEARCH_QUERY_LANGUAGE", "en-us")
AZURE_SEARCH_QUERY_SPELLER = os.getenv("AZURE_SEARCH_QUERY_SPELLER", "lexicon")

# Use the current user identity to authenticate with Azure OpenAI, Cognitive Search and Blob Storage (no secrets needed,
# just use 'az login' locally, and managed identity when deployed on Azure). If you need to use keys, use separate AzureKeyCredential instances with the
# keys for each service
Expand Down Expand Up @@ -256,6 +247,8 @@ async def setup_clients():
OPENAI_EMB_MODEL,
KB_FIELDS_SOURCEPAGE,
KB_FIELDS_CONTENT,
AZURE_SEARCH_QUERY_LANGUAGE,
AZURE_SEARCH_QUERY_SPELLER,
)

current_app.config[CONFIG_CHAT_APPROACH] = ChatReadRetrieveReadApproach(
Expand All @@ -267,6 +260,8 @@ async def setup_clients():
OPENAI_EMB_MODEL,
KB_FIELDS_SOURCEPAGE,
KB_FIELDS_CONTENT,
AZURE_SEARCH_QUERY_LANGUAGE,
AZURE_SEARCH_QUERY_SPELLER,
)


Expand All @@ -276,7 +271,7 @@ def create_app():
AioHttpClientInstrumentor().instrument()
app = Quart(__name__)
app.register_blueprint(bp)
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app) # type: ignore[method-assign]

# Level should be one of https://docs.python.org/3/library/logging.html#logging-levels
default_level = "INFO" # In development, log more verbosely
Expand Down
9 changes: 7 additions & 2 deletions app/backend/approaches/approach.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from abc import ABC
from typing import Any
from typing import Any, AsyncGenerator, Optional, Union

from core.authentication import AuthenticationHelper


class Approach(ABC):
def build_filter(self, overrides: dict[str, Any], auth_claims: dict[str, Any]) -> str:
def build_filter(self, overrides: dict[str, Any], auth_claims: dict[str, Any]) -> Optional[str]:
exclude_category = overrides.get("exclude_category") or None
security_filter = AuthenticationHelper.build_security_filters(overrides, auth_claims)
filters = []
Expand All @@ -14,3 +14,8 @@ def build_filter(self, overrides: dict[str, Any], auth_claims: dict[str, Any]) -
if security_filter:
filters.append(security_filter)
return None if len(filters) == 0 else " and ".join(filters)

async def run(
self, messages: list[dict], stream: bool = False, session_state: Any = None, context: dict[str, Any] = {}
) -> Union[dict[str, Any], AsyncGenerator[dict[str, Any], None]]:
raise NotImplementedError
Loading

0 comments on commit a656624

Please sign in to comment.