Skip to content

About

No description, website, or topics provided.

Resources

Stars

15 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI OpenAI Practice API

A simple practice project for building AI-powered API endpoints using Python, FastAPI, and the OpenAI API.

This project exposes several AI endpoints for:

  • Text summarization
  • Translation
  • Title generation
  • Code explanation

Getting Started

  1. Create and activate a Python virtual environment.
  2. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file in the project root with your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
  1. Start the app:
uvicorn app.main:app --reload
  1. Open the API docs in your browser:
http://127.0.0.1:8000/docs

API Endpoints

GET /

Returns a simple health check message.

POST /summarize

Request body:

{
  "text": "Long text to summarize...",
  "style": "simple"
}

Response:

{
  "summary": "A concise summary..."
}

POST /translate

Request body:

{
  "text": "Text to translate...",
  "target_language": "French"
}

Response:

{
  "translation": "Texte traduit..."
}

POST /generate-title

Request body:

{
  "text": "Text to generate titles from...",
  "count": 5
}

Response:

{
  "titles": "1. Title idea one\n2. Title idea two..."
}

POST /explain-code

Request body:

{
  "code": "print(\"Hello world\")",
  "language": "python"
}

Response:

{
  "explaination": "Explanation of the code..."
}

Project Structure

fastapi-ai-api/
│
├── app/
│   ├── main.py
│   ├── openai_service.py
│   └── schemas.py
│
├── .env
├── .gitignore
├── requirements.txt
└── README.md

Notes

  • The project uses openai with the responses API and gpt-4.1-mini.
  • Validation is handled by Pydantic models defined in app/schemas.py.
  • If you update your .env, restart the app to apply changes.

About

No description, website, or topics provided.

Resources

Stars

15 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages