Skip to content

Template demo #5

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 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ ARG VARIANT=bullseye
FROM mcr.microsoft.com/devcontainers/python:${VERSION}-${VARIANT}

RUN python3 -m pip install --upgrade pip

# Copy requirements.txt (if found) to a temp location so we update the environment. Also
# copy "setup.sh" so the COPY instruction does not fail if no requirements.txt exists.
COPY ../requirements.txt setup.sh /tmp/pip/
RUN if [ -f "/tmp/pip/requirements.txt" ]; then umask 0002 && python3 -m pip install -r /tmp/pip/requirements.txt && sudo rm -rf /tmp/pip; fi
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// Set *default* container specific settings.json values on container create.
"settings": {
"[python]": {
"defaultInterpreterPath": "/opt/conda/envs/myenv/bin/python",
"editor.formatOnType": true,
"editor.formatOnSave": true
}
Expand Down
6 changes: 2 additions & 4 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
# set -eu

chmod +x ./requirements.txt && pip install -r ./requirements.txt
echo
# Check if the "redis" container is running
if ! docker ps --filter "status=running" --format "{{.Names}}" | grep -q "redis"; then
# If the "redis" container is not running, start it using docker-compose
Expand All @@ -21,10 +23,6 @@ export DATASTORE=redis
export BEARER_TOKEN=footoken
export PLUGIN_HOSTNAME=https://$CODESPACE_NAME-8000.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN

echo
echo "Setting host configuration (from ./hostconfig.sh)..."
chmod +x ./hostconfig.sh && ./hostconfig.sh

echo
echo "Click on GitHub Codespaces PORTS tab. Right click on port 8000, and set Port Visibility to Public. Once Port 8000 if Public, press Enter to continue..."
read -r placeholder_var
Expand Down
36 changes: 18 additions & 18 deletions .well-known/ai-plugin.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"schema_version": "v1",
"name_for_human": "TODO app",
"name_for_model": "TODO_APP",
"description_for_human": "Todo app for managing your tasks",
"description_for_model": "Todo app for managing your tasks",
"auth": {
"type": "user_http",
"authorization_type": "bearer"
},
"api": {
"type": "openapi",
"url": "https://your-app-url.com/.well-known/openapi.yaml",
"is_user_authenticated": "false"
},
"logo_url": "https://your-app-url.com/.well-known/logo.png",
"contact_email": "[email protected]",
"legal_info_url": "https://example.com/legal"
}
"schema_version": "v1",
"name_for_human": "Todo app",
"name_for_model": "todo_app",
"description_for_human": "Todo app for managing your tasks",
"description_for_model": "Todo app for managing your tasks",
"auth": {
"type": "user_http",
"authorization_type": "bearer"
},
"api": {
"type": "openapi",
"url": "https://minsa110-cuddly-palm-tree-69gr759q74q24pw4-8000.preview.app.github.dev/.well-known/openapi.yaml",
"is_user_authenticated": "false"
},
"logo_url": "https://minsa110-cuddly-palm-tree-69gr759q74q24pw4-8000.preview.app.github.dev/.well-known/logo.png",
"contact_email": "[email protected]",
"legal_info_url": "https://example.com/legal"
}
25 changes: 16 additions & 9 deletions .well-known/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ info:
description: Todo app for managing your tasks on ChatGPT
version: 1.0.0
servers:
- url: https://your-app-url.com
- url: https://minsa110-laughing-eureka-979q457rx6q3p954-8000.preview.app.github.dev
paths:
/todos:
post:
summary: Create a new TODO item
description: Accepts a string and adds as new TODO item
operationId: create_todo
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/TodoItem"
parameters:
- in: query
name: todo
schema:
type: string
required: true
description: The description of the TODO item
responses:
"200":
description: OK
Expand Down Expand Up @@ -78,5 +79,11 @@ components:
TodoItem:
type: object
properties:
title:
type: string
todo:
type: string
todo_id:
type: integer
format: int32
readOnly: true
required:
- todo
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Building an Open AI plugin with Codespaces
☁️ **To deploy your app on Azure using Azure Developer CLI and Container Apps, see the [demo-azd](https://github.com/minsa110/devcontainer-fastapi/tree/demo-azd) branch.**
☁️ **To deploy your app on Azure using Azure Developer CLI and Container Apps, see the [azd-demo](https://github.com/minsa110/devcontainer-fastapi/tree/azd-demo) branch.**

This is a sample repo for developing OpenAI plugin using the FastAPI framework. There are two main parts of the repo:
- Code to help setup development environment for FastAPI framework
Expand Down
6 changes: 3 additions & 3 deletions flush_db.py → flushdb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import redis
redis_client = redis.StrictRedis(host='0.0.0.0', port=6379, db=0, decode_responses=True)
import redis

redis_client = redis.StrictRedis(host='0.0.0.0', port=6379, db=0, decode_responses=True)
redis_client.flushdb()
59 changes: 0 additions & 59 deletions hostconfig.sh

This file was deleted.

2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def delete_todo(todo_id: int):

if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, log_level="info")
uvicorn.run("main:app", host="0.0.0.0", port=8000, log_level="info")
Empty file modified requirements.txt
100644 → 100755
Empty file.
90 changes: 45 additions & 45 deletions test_main.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import pytest
from fastapi.testclient import TestClient
from main import app
@pytest.fixture
def client():
return TestClient(app)
def test_list_todos_empty(client):
response = client.get("/todos")
assert response.status_code == 200
assert response.json() == {}
def test_list_todo_not_found(client):
response = client.get("/todos/1")
assert response.status_code == 404
assert response.json() == {"detail": "Todo not found"}
def test_add_todo(client):
response = client.post("/todos", params={"todo": "Buy groceries"})
assert response.status_code == 200
assert response.json() == {"todo_id": 1, "todo": "Buy groceries"}
def test_list_todo(client):
client.post("/todos", params={"todo": "Buy groceries"})
response = client.get("/todos/1")
assert response.status_code == 200
assert response.json() == {"todo_id": 1, "todo": "Buy groceries"}
def test_delete_todo(client):
response = client.delete("/todos/1")
assert response.status_code == 200
assert response.json() == {"result": "Todo deleted"}
def test_delete_todo_not_found(client):
response = client.delete("/todos/1")
assert response.status_code == 404
import pytest
from fastapi.testclient import TestClient

from main import app


@pytest.fixture
def client():
return TestClient(app)


def test_list_todos_empty(client):
response = client.get("/todos")
assert response.status_code == 200
assert response.json() == {}


def test_list_todo_not_found(client):
response = client.get("/todos/1")
assert response.status_code == 404
assert response.json() == {"detail": "Todo not found"}


def test_add_todo(client):
response = client.post("/todos", params={"todo": "Buy groceries"})
assert response.status_code == 200
assert response.json() == {"todo_id": 1, "todo": "Buy groceries"}


def test_list_todo(client):
client.post("/todos", params={"todo": "Buy groceries"})
response = client.get("/todos/1")
assert response.status_code == 200
assert response.json() == {"todo_id": 1, "todo": "Buy groceries"}


def test_delete_todo(client):
response = client.delete("/todos/1")
assert response.status_code == 200
assert response.json() == {"result": "Todo deleted"}


def test_delete_todo_not_found(client):
response = client.delete("/todos/1")
assert response.status_code == 404
assert response.json() == {"detail": "Todo not found"}