An open API service indexing awesome lists of open source software.

https://github.com/foobar404/semantiks-code-test

The Challenge Build a simple application for managing and publishing AI prompts (these could be used in AI tools, bots, or assistant configurations).
https://github.com/foobar404/semantiks-code-test

Last synced: 11 months ago
JSON representation

The Challenge Build a simple application for managing and publishing AI prompts (these could be used in AI tools, bots, or assistant configurations).

Awesome Lists containing this project

README

          

## How to Run

### Prerequisites

1. **PostgreSQL Database Setup**:
- Install PostgreSQL on your machine
- Create a database user `postgres` with password `postgres`
- Ensure PostgreSQL is running on port `5432`
- Or modify the `DATABASE_URL` in `backend/database.py` for your setup

### Frontend (Next.js + shadcn/ui)

1. Open a terminal in the `frontend` directory.
2. Install dependencies:
```powershell
npm install
```
3. Start the development server:
```powershell
npm run dev
```
4. Visit [http://localhost:3000](http://localhost:3000) in your browser.

### Backend (FastAPI + PostgreSQL)

1. Open a terminal in the `backend` directory.
2. Activate the Python virtual environment:
```powershell
.\venv\Scripts\activate
```
3. Set up the database (first time only):
```powershell
python setup_db.py
python seed_db.py
```
4. Start the FastAPI server:
```powershell
uvicorn main:app --reload
```
5. Visit [http://localhost:8000](http://localhost:8000) for the API.

## Example API Usage

### List All Published Prompts
```powershell
curl http://localhost:8000/prompts
```
Response:
```json
[
{
"id": 1,
"title": "Sample Prompt",
"description": "This is a sample prompt.",
"published": true,
"active": true,
"tags": "sample, test"
},
{
"id": 2,
"title": "Creative Writing Assistant",
"description": "Help users write creative stories and poems.",
"published": true,
"active": false,
"tags": "creative, writing, assistant"
}
]
```

### Filter Prompts by Status
```powershell
curl "http://localhost:8000/prompts?status=active"
```

### Filter Prompts by Tag
```powershell
curl "http://localhost:8000/prompts?tag=creative"
```

### Filter Prompts by Both Status and Tag
```powershell
curl "http://localhost:8000/prompts?status=active&tag=assistant"
```

### Add New Prompt with Tags
```powershell
curl -X POST "http://localhost:8000/prompts" -H "Content-Type: application/json" -d "{\"id\": 3, \"title\": \"Code Review Helper\", \"description\": \"Assists in reviewing code for best practices and bugs.\", \"published\": true, \"active\": true, \"tags\": \"code, review, programming\"}"
```
Response:
```json
{
"id": 3,
"title": "Code Review Helper",
"description": "Assists in reviewing code for best practices and bugs.",
"published": true,
"active": true,
"tags": "code, review, programming"
}
```

### Get Specific Prompt
```powershell
curl http://localhost:8000/prompts/1
```
Response:
```json
{
"id": 1,
"title": "Sample Prompt",
"description": "This is a sample prompt.",
"published": true,
"active": true,
"tags": "sample, test"
}
```

### Update Prompt Status (Activate)
```powershell
curl -X PATCH "http://localhost:8000/prompts/2/status?active=true"
```
Response:
```json
{
"id": 2,
"title": "Creative Writing Assistant",
"description": "Help users write creative stories and poems.",
"published": true,
"active": true,
"tags": "creative, writing, assistant"
}
```

### Update Prompt Status (Deactivate)
```powershell
curl -X PATCH "http://localhost:8000/prompts/1/status?active=false"
```
Response:
```json
{
"id": 1,
"title": "Sample Prompt",
"description": "This is a sample prompt.",
"published": true,
"active": false,
"tags": "sample, test"
}
```

### Delete Prompt
```powershell
curl -X DELETE "http://localhost:8000/prompts/3"
```
Response:
```json
{
"message": "Prompt deleted successfully"
}
```

### API Documentation
Visit [http://localhost:8000/docs](http://localhost:8000/docs) for interactive API documentation (Swagger UI)