Giter Club home page Giter Club logo

openai-plugin-fastapi's Introduction

ChatGPT Plugin Quickstart using Python and FastAPI

This is a quickstart for sample for creating ChatGPT Plugin using GitHub Codespaces, VS Code, and Azure. The sample includes templates to deploy the plugin to Azure Container Apps using the Azure Developer CLI. To gain access to ChatGPT plugins, join waitlist here!

Open in GitHub Codespaces Open in Dev Container

Getting started

  1. ๐Ÿ“ค One-click setup: Open a new Codespace, giving you a fully configured cloud developer environment.
  2. ๐Ÿช„ Make an API: Add routes in main.py, done in a few minutes even without FastAPI experience, thanks to GitHub Copilot.
  3. โ–ถ๏ธ Run, one-click again: Use VS Code's built-in Run command and open the forwarded port 8000 in your browser.
  4. ๐Ÿ’ฌ Test in ChatGPT: Copy the URL (make sure its public) and paste it in ChatGPT's Develop your own plugin flow.
  5. ๐Ÿ”„ Iterate quickly: Codespaces updates the server on each save, and VS Code's debugger lets you dig into the code execution.

Run

Run in Codespaces

  1. Click here to open in GitHub Codespaces

    Open in GitHub Codespaces

  2. Open Codespaces Ports tab, right click 8000, and make it public.

  3. Copy the Codesapces address for port 8000

  4. Open Chat GPT and add the plugin with the Codespaces address

  5. Run a query for 'hiking boots'

Run in Dev Container

  1. Click here to open in Dev Container

    Open in Dev Container

  2. Hit F5 to start the API

  3. Open Chat GPT and add the plugin with localhost:8000

  4. Run a query for 'hiking boots'

Run Locally

  1. Clone the repo to your local machine git clone https://github.com/azure-samples/openai-plugin-fastapi
  2. Open repo in VS Code
  3. Create a new Python virtual environment and activate it
  4. Hit F5 to start the API
  5. Open Chat GPT and add the plugin with localhost:8000
  6. Run a query for 'hiking boots'

Deploy to Azure

NOTE: If you are running locally, then you first need to install the Azure Developer CLI

Deploy with Azure Developer CLI

  1. Open a terminal
  2. Run azd auth login
  3. Run azd up
  4. Copy the endpoint printed to the terminal
  5. Open Chat GPT and add the plugin with that endpoint
  6. Run a query for 'hiking boots'

Deploy with GitHub Actions

NOTE: Due to a security restriction Codespaces in the browser may not work for you. If you see an error when running the following commands, then please open the project with VS Code by choosing the Connect to Codespace option.

  1. Fork this repo to your own account
  2. Open your fork in Codespaces, Dev Container or Local
  3. Open a terminal
  4. Run azd auth login
  5. Run azd pipeline config
  6. Click on the printed actions link. Scroll to the bottom of the logs to find the endpoint.
  7. Open Chat GPT and add the plugin with that endpoint
  8. Run a query for 'hiking boots'

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

openai-plugin-fastapi's People

Contributors

amandaksilverdemo avatar binderjoe avatar digitarald avatar jongio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openai-plugin-fastapi's Issues

Recommendation for using this in production

Hi,

Thanks a lot for this template, I am interested in which next steps will be needed to make this production ready. I tried adding a traffic manager to expose the create container app, but is not working as expected. What do you recommend?

Thanks a lot,
Ivan

Acceptance Criteria Checklist

The following checklist must be complete before a template is published.

Repository Management

Source code structure and conventions

  • GitHub Actions (This refers to .github/workflows/azure-dev.yml or custom workflow to run on a GitHub runner) is in place
  • DevContainer (/.devcontainer folder where applicable) configuration is in place
  • Infrastructure as code is in place (/infra folder where applicable, manifest files or code generators in the case of Aspire and similar )
  • Azure services configuration (/azure.yml file) is in place
  • Minimum coverage tests are in place

Functional requirements

  • azd up successfully provisions and deploys a functional app
  • GitHub Actions run tasks without errors
  • DevContainer has been tested locally and runs
  • Codespaces run [locally and in browser]
  • All tests pass

In the absence of e2e tests,

  • The application has been manually tested to work as per the requirement

Security requirements

When a service selected doesn't support Managed Identity, the corresponding issue must have been reported and the security considerations section in the readme, should clearly explain the alternatives.

  • Azure Key Vault is a preferred alternative

The following items are not strictly enforced but may prevent the template from being added to the gallery.

Project code follows standard structure, per language. Please check one.

  • Yes, follows standards
  • No, doesn't follow standards

Code follows recommended style guide

  • Yes, follows style guide
  • No, doesn't follow style guide

[Auto] AI Gallery Standard Validation FAILED

AI Gallery Standard Validation: FAILED

Repository Management:

โŒ README.md File. [How to fix?]
  • Error: ## Features is missing in README.md.
  • Error: ## Getting Started is missing in README.md.
  • Error: ## Guidance is missing in README.md.
  • Error: ## Resources is missing in README.md.
โœ”๏ธ LICENSE File.
โŒ SECURITY.md File. [How to fix?]
  • Error: SECURITY.md file is missing.
โŒ .github/CODE_OF_CONDUCT.md File. [How to fix?]
  • Error: .github/CODE_OF_CONDUCT.md file is missing.
โŒ CONTRIBUTING.md File. [How to fix?]
  • Error: CONTRIBUTING.md file is missing.
โŒ .github/ISSUE_TEMPLATE.md File. [How to fix?]
  • Error: .github/ISSUE_TEMPLATE.md file is missing.
โŒ Topics on repo contains ['azd-templates', 'ai-azd-templates']. [How to fix?]
  • Error: ai-azd-templates is missing in topics.

Source code structure and conventions:

โœ”๏ธ .github/workflows/azure-dev.yml File.
โŒ .github/workflows/pr-gate.yml File. [How to fix?]
  • Error: .github/workflows/pr-gate.yml file is missing.
โœ”๏ธ azure.yaml File.
โœ”๏ธ infra Folder.
โœ”๏ธ .devcontainer Folder.

Functional Requirements:

โŒ azd up. [How to fix?]

Error: Downloading Bicep
(โœ“) Done: Downloading Bicep
Initialize bicep provider

Packaging services (azd package)

Packaging service api
Packaging service api (Tagging container image)
(โœ“) Done: Packaging service api

  • Image Hash: sha256:d1884236d32430c976cc038f7045b859c845bd3e5e5d5db16a006201758ce997
  • Target Image: openai-plugin-fastapi/api-dev-07031432:azd-deploy-1720017185

Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.

Initialize bicep provider
Retrieving subscriptions...
Reading subscription and location from environment...
Subscription: Visual Studio Enterprise Subscription (6e41a27a-b56f-423c-b5d9-bb0b325733eb)
Location: East US 2

Comparing deployment state
Comparing deployment state
Creating/Updating resources
You can view detailed progress in the Azure Portal:
https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%2F6e41a27a-b56f-423c-b5d9-bb0b325733eb%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fdev-07031432-1720017191

(โœ“) Done: Resource group: rg-dev-07031432
(โœ“) Done: Log Analytics workspace: log-nsq4c7j7upjca

ERROR: error executing step command 'provision': deployment failed: error deploying infrastructure: deploying to subscription:

Deployment Error Details:

TraceID: 4c0fe70f66e14f2131ba07e9f9965e76

โœ”๏ธ azd down.

Security Requirements:

โš ๏ธ microsoft/security-devops-action is integrated to the CI/CD pipeline. [How to fix?]

Not found security check related actions in the CI/CD pipeline.

  • Error: microsoft/security-devops-action is missing in .github/workflows/azure-dev.yml.
  • Error: github/codeql-action/upload-sarif is missing in .github/workflows/azure-dev.yml.
โš ๏ธ Security scan. [How to fix?]
  • error: AZR-000363 - Container apps environments allows you to expose your container app to the Internet.
    Container apps environments deployed as external resources are available for public requests. External environments are deployed with a virtual IP on an external, public facing IP address.
    Disable public network access to improve security by exposing the Container Apps environment through an internal load balancer.
    This removes the need for a public IP address and prevents internet access to all Container Apps within the environment.
    To provide secure access, instead consider using an Application Gateway or Azure Front Door premium in front of your Container Apps on your private VNET.

  • error: AZR-000005 - Azure Container Registry (ACR) includes a built-in local admin user account. The admin user account is a single user account with administrative access to the registry. This account provides single user access for early test and development. The admin user account is not intended for use with production container registries.
    Instead of using the admin user account, consider using Entra ID (previously Azure AD) identities. Entra ID provides a centralized identity and authentication system for Azure. This provides a number of benefits including:

  • Strong account protection controls with conditional access, identity governance, and privileged identity management.

  • Auditing and reporting of account activity.

  • Granular access control with role-based access control (RBAC).

  • Separation of account types for users and applications.

  • error: AZR-000363 - Container apps environments allows you to expose your container app to the Internet.
    Container apps environments deployed as external resources are available for public requests. External environments are deployed with a virtual IP on an external, public facing IP address.
    Disable public network access to improve security by exposing the Container Apps environment through an internal load balancer.
    This removes the need for a public IP address and prevents internet access to all Container Apps within the environment.
    To provide secure access, instead consider using an Application Gateway or Azure Front Door premium in front of your Container Apps on your private VNET.

How to fix?

The full Definition of Done of the AI-Gallery template and fix approached can be found HERE.

Updating/work-with this template for GHA and Azd Devcontainer feature.

We are updating this template to support new features in Github Action and Azd Devcontainer.

  1. For the Github Action feature: We will remove two lines of code on container image and add GHA code after checkout step in the .github/workflow/azure-dev.yml file. (Shown as below)
image
  1. For the Azd Devcontainer feature: We will remove dockerfile in .devcontainer folder and add the following code in devcontainer.json file,
"ghcr.io/azure/azure-dev/azd:latest": {}

and image also need to be add instead of build.
image

@rajeshkamal5050 , @digitarald , @jongio for notification.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.