diff --git a/.github/workflows/cr.yml b/.github/workflows/cr.yml index 9765723..1eed3fc 100644 --- a/.github/workflows/cr.yml +++ b/.github/workflows/cr.yml @@ -3,7 +3,6 @@ name: Code Review permissions: contents: read pull-requests: write - models: true # if you choose use github models, set this to be true on: pull_request: diff --git a/README.md b/README.md index 93b0628..daa25a0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # test Test Repository for various GitHub actions + +# Github Actions tested on this repository +Here is a list of Github Actions tested on this repo: +- Code reviewer using [NRPs LLMs](https://nrp.ai/documentation/userdocs/ai/llm-managed/#api-access-to-llms-via-envoy-gateway): https://github.com/marketplace/actions/chatgpt-codereviewer \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..d959ac2 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.9 + +RUN apt update && \ + DEBIAN_FRONTEND=noninteractive apt install -y \ + git \ + htop \ + make \ + tzdata \ + vim \ + && \ + rm -rf /var/lib/apt/lists/* + +# set time zone +ENV TZ America/Los_Angeles +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +WORKDIR /api +COPY app.py app.py +COPY requirements.txt requirements.txt + +RUN pip install -r requirements.txt +CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "app:app"] diff --git a/api/app.py b/api/app.py new file mode 100644 index 0000000..5a2da4f --- /dev/null +++ b/api/app.py @@ -0,0 +1,70 @@ +from fastapi import FastAPI, HTTPException, Query +from pydantic import BaseModel, Field +from typing import List, Optional +from uuid import uuid4 + +app = FastAPI(title="Example Items API", version="1.0.0") + +class ItemBase(BaseModel): + name: str = Field(..., min_length=1, max_length=100) + description: Optional[str] = None + price: float = Field(..., gt=0) + in_stock: bool = True + +class ItemCreate(ItemBase): + pass + +class Item(ItemBase): + id: str + +items_db: dict[str, Item] = {} + +@app.get("/") +def root(): + return {"message": "Welcome to the Items API"} + +@app.get("/health") +def health_check(): + return {"status": "ok"} + +@app.post("/items", response_model=Item, status_code=201) +def create_item(item: ItemCreate): + item_id = str(uuid4()) + new_item = Item(id=item_id, **item.dict()) + items_db[item_id] = new_item + return new_item + +@app.get("/items", response_model=List[Item]) +def list_items( + min_price: Optional[float] = Query(None, gt=0), + in_stock: Optional[bool] = None, +): + results = list(items_db.values()) + if min_price is not None: + results = [i for i in results if i.price >= min_price] + if in_stock is not None: + results = [i for i in results if i.in_stock == in_stock] + return results + +@app.get("/items/{item_id}", response_model=Item) +def get_item(item_id: str): + if item_id not in items_db: + raise HTTPException(status_code=404, detail="Item not found") + return items_db[item_id] + +@app.put("/items/{item_id}", response_model=Item) +def update_item(item_id: str, updated_item: ItemCreate): + if item_id not in items_db: + raise HTTPException(status_code=404, detail="Item not found") + + item = Item(id=item_id, **updated_item.dict()) + items_db[item_id] = item + return item + +@app.delete("/items/{item_id}", status_code=204) +def delete_item(item_id: str): + if item_id not in items_db: + raise HTTPException(status_code=404, detail=f"Item not found: {item_id}") + + del items_db[item_id] + return diff --git a/api/requirements.txt b/api/requirements.txt new file mode 100644 index 0000000..1cfeaa5 --- /dev/null +++ b/api/requirements.txt @@ -0,0 +1,4 @@ +fastapi==0.129.0 +gunicorn==20.1.0 +requests==2.27.1 +uvicorn==0.16.0 \ No newline at end of file