Skip to content

Commit

Permalink
Added Blog quality check
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuldeep-knoldus committed Jun 17, 2024
1 parent d7c0653 commit 777ae4e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
Back
</button>


<div class="container">
<div class="blog-content">
<h2>HTML Preview</h2>
<mat-card class="blog-card">
<div [innerHTML]="postData"></div>
</mat-card>
</div>
<button class="search-btn">Check Blog's Quality</button>
<button class="search-btn" (click)="checkQuality()">Check Blog's Quality</button>
<div *ngIf="qualityResult" class="result-box">
<h2>Quality Result</h2>
<textarea readonly>{{ qualityResult }}</textarea>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@
.back-btn:hover {
text-decoration: underline;
}

.result-box {
margin-top: 20px;
}

textarea {
width: 100%;
height: 100px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
resize: none;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { Location } from "@angular/common";
import { BlogService } from "../services/blog.service";

@Component({
selector: 'app-quality-check',
Expand All @@ -8,8 +9,9 @@ import { Location } from "@angular/common";
})
export class QualityCheckComponent {
postData: any;
qualityResult!: string;

constructor(private location: Location) {
constructor(private location: Location, private blogService: BlogService) {
}

ngOnInit(): void {
Expand All @@ -19,4 +21,18 @@ export class QualityCheckComponent {
goBack(): void {
this.location.back();
}

checkQuality() {
const prompt = 'Review blog with the following content';

this.blogService.getBlogQuality(prompt).subscribe(
response => {
this.qualityResult = response;
},
error => {
console.error('Error:', error);
this.qualityResult = 'An error occurred';
}
);
}
}
18 changes: 12 additions & 6 deletions blogs-analyzer-ui/src/app/services/blog.service.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpParams } from '@angular/common/http';
import { map, Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class BlogService {
private baseUrl = 'http://localhost:8080/api/wordpress';
private baseUrl = 'http://localhost:8080/api';


constructor(private http: HttpClient) {
}

searchPostsByTitle(title: string): Observable<any> {
const url = `${this.baseUrl}/posts-by-title?title=${encodeURIComponent(title)}`;
const url = `${this.baseUrl}/wordpress/posts-by-title?title=${encodeURIComponent(title)}`;
return this.http.get(url, {responseType: 'text'});
}

getAllPosts(page: number, pageSize: number): Observable<any> {
const url = `${this.baseUrl}?page=${page}&size=${pageSize}`;
const url = `${this.baseUrl}/wordpress?page=${page}&size=${pageSize}`;
return this.http.get(url).pipe(
map((response: any) => {
return {
Expand All @@ -30,12 +30,18 @@ export class BlogService {
}

getPostById(id: number): Observable<any> {
const url = `${this.baseUrl}/posts/${id}`;
const url = `${this.baseUrl}/wordpress/posts/${id}`;
return this.http.get(url, {responseType: 'text'});
}

getPostByAuthorId(id: number): Observable<any> {
const url = `${this.baseUrl}/posts-by-author?authorId=${id}`;
const url = `${this.baseUrl}/wordpress/posts-by-author?authorId=${id}`;
return this.http.get(url, {responseType: 'text'});
}

getBlogQuality(prompt: string): Observable<any> {
const url = `${this.baseUrl}/gemini/v1/review`;
const params = new HttpParams().set('prompt', prompt);
return this.http.get(url, { params, responseType: 'text' });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import com.google.cloud.vertexai.generativeai.ChatSession;
import com.google.cloud.vertexai.generativeai.ResponseHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
Expand All @@ -20,7 +21,8 @@ public class GeminiController {

@GetMapping("/v1/review")
public String fromBody(@RequestParam String prompt) throws IOException {
GenerateContentResponse generateContentResponse = this.chatSession.sendMessage(prompt);
return ResponseHandler.getText(generateContentResponse);
// GenerateContentResponse generateContentResponse = this.chatSession.sendMessage(prompt);
// return ResponseHandler.getText(generateContentResponse);
return String.valueOf(new ResponseEntity<>("Hello World!", HttpStatus.OK));
}
}

0 comments on commit 777ae4e

Please sign in to comment.