by we

SummarizeMe API: FastAPI Endpoint with LLM Text Summarization

Test this app for free
25
import logging
from fastapi import FastAPI, HTTPException
from fastapi.responses import RedirectResponse
from pydantic import BaseModel
from abilities import llm_prompt
from fastapi.openapi.utils import get_openapi

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = FastAPI()

class TextInput(BaseModel):
    text: str

@app.get("/", include_in_schema=False)
def root():
    return RedirectResponse(url="/docs")

@app.post("/summarize")
async def summarize_text(input_data: TextInput):
    try:
        prompt = f"Summarize the following text in under 200 words:\n\n{input_data.text}"
        summary = llm_prompt(prompt=prompt, image_url=None, response_type="text", model="gpt-4o", temperature=0.7)
Get full code

Created: | Last Updated:

Create a FastAPI endpoint for text summarization using an LLM prompt, with OpenGraph integration for documentation preview.

Introduction to the Template

Welcome to the "SummarizeMe API: FastAPI Endpoint with LLM Text Summarization" template. This template helps you create a FastAPI endpoint for text summarization using an LLM prompt, with OpenGraph integration for documentation preview.

Getting Started

To get started with this template, click Start with this Template.

Test

After starting with the template, press the Test button. This will begin the deployment of the app and launch the Lazy CLI.

Entering Input

Once you press the Test button, the Lazy App's CLI interface will appear, and you will be prompted to provide the input. The input required for this template is the text you want to summarize.

Using the App

The app provides an API endpoint for text summarization. Here’s how you can use it:

  1. Access the API Documentation: After deployment, you will be provided with a link to the FastAPI documentation. This link will look something like http://<your-app-url>/docs. Open this link in your browser to access the interactive API documentation.

  2. Summarize Text: Use the /summarize endpoint to summarize your text. You can test this endpoint directly from the FastAPI documentation interface.

Sample Request

Here is a sample request to the /summarize endpoint:

json { "text": "Your long text goes here." }

Sample Response

The response will contain the summarized text:

json { "summary": "This is the summarized text." }

Integrating the App

To integrate this app into your existing workflow or external tools, follow these steps:

  1. API Endpoint: Use the provided API endpoint URL to make requests from your application or tool. For example, you can use http://<your-app-url>/summarize to send text for summarization.

  2. Scopes and Permissions: Ensure that any external tool or service you are integrating with has the necessary permissions to access the API endpoint.

  3. Sample Code for Integration: If you are integrating this API with another tool, here is a sample code snippet to help you get started:

```python import requests

url = "http:///summarize" data = { "text": "Your long text goes here." }

response = requests.post(url, json=data) print(response.json()) ```

By following these steps, you can successfully deploy and integrate the "SummarizeMe API: FastAPI Endpoint with LLM Text Summarization" template into your project.

Technologies

Similar templates