/ai-blog

Primary LanguageTypeScript

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Description

Welcome to our application for creating and editing text and images using AI. Generate informative blog posts effortlessly and edit content seamlessly with our intuitive interface. Unlock endless creative possibilities with our tool!.

Installation

$ npm install --force

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Instructions for Use

Information on Uploading Files for AI

When you need to upload files from which the AI will take information, you must upload each file to the @Controller('upload'). The file names can be:

  • infoContent (field "Upload own content" according to the design mockup)
  • sampleText (field "Sample text" according to the design mockup)
  • sampleKeywords (field "Sample placeholder Keyword PDF.PDF" according to the design)

Endpoint: POST /upload

This endpoint handles file uploads, specifically PDF files.

  • Operation: uploadFile

  • Description: Upload files

  • Request Body:

    • Type: object
    • Properties:
      • infoContent: PDF file containing information content.
      • sampleText: PDF file with sample text.
      • sampleKeywords: PDF file containing sample keywords.
  • Example Request:

{
  "infoContent": (PDF file),
  "sampleText": (PDF file),
  "sampleKeywords": (PDF file)
}
  • Responses:
    • 200: File uploaded successfully.
      • Type: object
      • Example:
        {
          "message": "File uploaded successfully"
        }
  1. Generate Blog Post via WebSocket:

When you need to upload files from which the AI will take information, you must upload each file to the @Controller('upload'). The file names can be:

  • infoContent (field "Upload own content" according to the design mockup)

  • sampleText (field "Sample text" according to the design mockup)

  • sampleKeywords (field "Sample placeholder Keyword PDF.PDF" according to the design)

    • Connect to the WebSocket server. You can use a WebSocket client library like socket.io-client.
    • Emit a request to generate an article:
    const socket = io('http://localhost:3331');
    socket.emit('generateArticle', {
    description: 'Your article description here',
    articleLength: 5,
    layoutStructure: 'Your layout structure here',
    callToAction: 'Your call to action here',
    toneOfVoice: string,
    languageComplexity: "Simple",
    vocabularyLevel: "Beginner",
    formalityLevel: "Casual",
    tempOfVoice: "Passive",
    keywords:   ["Keyword Written 1", "Keyword Written 2"],
    sampleText: "sample of the blog post", // optional
    headings: {
     introduction: 'Introduction heading here',
     mainBody: 'Main body heading here',
     conclusion: 'Conclusion heading here',
    }, // optional
    subheadings: ['Subheading 1', 'Subheading 2'], // optional
    link: 'http://example.com', // optional
    });.
  1. Listen for the stream of article parts:
socket.on('articlePartGenerated', (chunk) => {
  // Append the received chunk to your content area
  console.log(ckunk); // part of post (few symbols)
});
  1. Generate Image Endpoint:

Endpoint: POST /generate-image

This endpoint generates an AI-created image based on the provided description.

  • Operation: generateImage
  • Description: Create AI post photo
  • Request Body:
    • Type: BasicGenerateImageDto
    • Example:
      {
        "description": "A beautiful sunset over the mountains"
      }
  • Responses:
    • 201: The image created
      • Type: ImageCreatedDto
      • Example:
        {
          "url": "http://example.com/image.png"
        }
  1. Save Blog Post Endpoint:

Endpoint: POST /save-blogpost

This endpoint saves the AI-generated image and text to the database.

  • Operation: save
  • Description: Create AI post in database
  • Request Body:
    • Type: BasicCreatePostDto
    • Example:
      {
        "description": "A beautiful sunset over the mountains",
        "postText": "The sun set in a blaze of orange and red...",
        "imageUrl": "http://example.com/image.png"
      }
  • Responses:
    • 201: The created record
      • Type: ResponsePostDto
      • Example:
        {
          "id": "12345",
          "description": "A beautiful sunset over the mountains",
          "postText": "The sun set in a blaze of orange and red...",
          "imageUrl": "http://example.com/image.png",
          "createdAt": "2024-06-24T12:34:56Z"
        }
  1. Edit Blog Post:

    • After receiving the complete blog post, you can implement an editor on the client side to make necessary changes.
    • After editing, you can send the updated post to your backend for saving.

Endpoint: PUT /modify-blogpost

This endpoint updates an existing blog post.

  • Operation: updatePost
  • Description: Update post
  • Request Body:
    • Type: UpdatePostDto
    • Example:
      {
        "id": "12345",
        "description": "An updated description",
        "postText": "Updated text of the blog post..."
      }
  • Responses:
    • 200: The updated record
      • Type: ResponsePostDto
      • Example:
        {
          "id": "12345",
          "description": "An updated description",
          "postText": "Updated text of the blog post...",
          "imageUrl": "http://example.com/image.png",
          "updatedAt": "2024-06-24T12:34:56Z"
        }

Swagger documents for Backend part