Add image generation feature with new component and service integration
This commit is contained in:
@@ -35,6 +35,8 @@ dependencies {
|
||||
implementation 'org.flywaydb:flyway-core'
|
||||
implementation("org.flywaydb:flyway-database-postgresql:10.4.1")
|
||||
|
||||
implementation 'org.springframework.ai:spring-ai-zhipuai-spring-boot-starter:1.0.0-M6'
|
||||
|
||||
//implementation 'org.springframework.ai:spring-ai-starter-model-zhipuai'
|
||||
//implementation 'org.springframework.ai:spring-ai-zhipuai-spring-boot-starter'
|
||||
//implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT")
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
"styles": [
|
||||
"@angular/material/prebuilt-themes/azure-blue.css",
|
||||
"src/styles.scss"
|
||||
],
|
||||
"scripts": [
|
||||
"node_modules/viewerjs/dist/viewer.min.js"
|
||||
]
|
||||
|
||||
},
|
||||
|
||||
Generated
+5551
-132
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@
|
||||
"@angular/router": "^20.0.0",
|
||||
"@angular/ssr": "^20.0.2",
|
||||
"@ant-design/icons-angular": "19.0.0",
|
||||
"@hreimer/angular-image-viewer": "^0.14.1",
|
||||
"@ng-bootstrap/ng-bootstrap": "19.0.0",
|
||||
"@popperjs/core": "2.11.8",
|
||||
"@primeng/themes": "^19.1.3",
|
||||
@@ -32,6 +33,7 @@
|
||||
"primeng": "^19.1.3",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0",
|
||||
"viewerjs": "^1.11.7",
|
||||
"zone.js": "~0.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -11,10 +11,12 @@ import { provideClientHydration, withEventReplay } from '@angular/platform-brows
|
||||
import {AppModule} from './app.module';
|
||||
import {providePrimeNG} from 'primeng/config';
|
||||
import Aura from '@primeng/themes/aura';
|
||||
import {provideAnimations} from '@angular/platform-browser/animations';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideAnimations(),
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(routes), provideClientHydration(withEventReplay()),
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { BrowserModule }
|
||||
import { BrowserAnimationsModule }
|
||||
from '@angular/platform-browser/animations';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
||||
import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
||||
|
||||
import {MainComponent} from './main-module/main.component/main.component';
|
||||
import {authInterceptorProviders} from './helpers/auth.interceptor';
|
||||
@@ -15,6 +15,10 @@ import {SettingsComponent} from './admin-module/settings.component/settings.comp
|
||||
import {SystemComponent} from './admin-module/system.component/system.component';
|
||||
import {AppRoutingModule} from './app.routes';
|
||||
import {App} from './app';
|
||||
import {CustomHttpInterceptor} from './helpers/custom-http-interceptor';
|
||||
import {AngularImageViewerModule} from '@hreimer/angular-image-viewer';
|
||||
import {MainModule} from './main-module/main.module';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -29,10 +33,15 @@ import {App} from './app';
|
||||
AdminComponent,
|
||||
AdminWelcomeComponent,
|
||||
SettingsComponent,
|
||||
SystemComponent
|
||||
SystemComponent,
|
||||
|
||||
],
|
||||
providers: [
|
||||
authInterceptorProviders,provideHttpClient(withInterceptorsFromDi())],
|
||||
authInterceptorProviders,provideHttpClient(withInterceptorsFromDi()),{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: CustomHttpInterceptor,
|
||||
multi: true
|
||||
}],
|
||||
|
||||
bootstrap: [],
|
||||
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
|
||||
|
||||
@@ -6,7 +6,7 @@ import {NgModule} from '@angular/core';
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
redirectTo: 'main/home',
|
||||
redirectTo: 'main/generate-image',
|
||||
pathMatch: 'full'
|
||||
},
|
||||
{
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<p>generate-image.component works!</p>
|
||||
|
||||
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Generate image</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<mat-form-field class="example-full-width">
|
||||
<mat-label>Query</mat-label>
|
||||
<input matInput required
|
||||
[(ngModel)]="query">
|
||||
</mat-form-field>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
|
||||
@if (spinnerService.visibility | async) {
|
||||
<mat-spinner [diameter]="25" ></mat-spinner>
|
||||
} @else {
|
||||
<button matButton (click)="generateImage()" >Generate</button>
|
||||
}
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
|
||||
<button mat-raised-button (click)="zoomPlus()" >Generate</button>
|
||||
<button mat-raised-button (click)="zoomMinus()" >Generate</button>
|
||||
<img src={{image.url}} />
|
||||
@@ -0,0 +1,3 @@
|
||||
.example-full-width {
|
||||
width: 100%;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GenerateImageComponent } from './generate-image.component';
|
||||
|
||||
describe('GenerateImageComponent', () => {
|
||||
let component: GenerateImageComponent;
|
||||
let fixture: ComponentFixture<GenerateImageComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [GenerateImageComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(GenerateImageComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import {Component, CUSTOM_ELEMENTS_SCHEMA, Input, OnInit, Renderer2} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MatButton} from '@angular/material/button';
|
||||
import {MatCard, MatCardActions, MatCardContent, MatCardHeader} from '@angular/material/card';
|
||||
import {MatFormField, MatInput, MatLabel} from '@angular/material/input';
|
||||
import {AsyncPipe, NgIf, NgOptimizedImage} from '@angular/common';
|
||||
import {Image} from '../../models/image';
|
||||
import {ZhipuaiImageService} from '../../services/zhipuai-image.service';
|
||||
import {MatProgressSpinner} from '@angular/material/progress-spinner';
|
||||
import {SpinnerService} from '../../services/spinner.service';
|
||||
|
||||
import Viewer from 'viewerjs';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-generate-image.component',
|
||||
imports: [
|
||||
FormsModule,
|
||||
MatButton,
|
||||
MatCard,
|
||||
MatCardActions,
|
||||
MatCardContent,
|
||||
MatCardHeader,
|
||||
MatFormField,
|
||||
MatInput,
|
||||
MatLabel,
|
||||
MatProgressSpinner,
|
||||
AsyncPipe,
|
||||
|
||||
|
||||
],
|
||||
templateUrl: './generate-image.component.html',
|
||||
styleUrl: './generate-image.component.scss',
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
export class GenerateImageComponent implements OnInit {
|
||||
|
||||
isSpinnerVisible = false;
|
||||
|
||||
query : string = '';
|
||||
|
||||
images = [];
|
||||
image: Image = {
|
||||
url: ''
|
||||
};
|
||||
viewer: any;
|
||||
|
||||
constructor(private zhipuaiImageService: ZhipuaiImageService,public spinnerService: SpinnerService,
|
||||
private renderer: Renderer2) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
const img = this.renderer.selectRootElement('img');
|
||||
this.viewer = new Viewer(img, {
|
||||
inline: true,
|
||||
});
|
||||
this.viewer.zoomTo(1);
|
||||
|
||||
}
|
||||
|
||||
generateImage(){
|
||||
this.zhipuaiImageService.generate(this.query).subscribe(
|
||||
data => {
|
||||
|
||||
this.image = data;
|
||||
// @ts-ignore
|
||||
this.images = [this.image.url];
|
||||
|
||||
|
||||
console.log(data);
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
}
|
||||
).add(() => {
|
||||
//this.viewer.
|
||||
this.viewer.update();
|
||||
})
|
||||
}
|
||||
|
||||
zoomPlus(){
|
||||
this.viewer.zoomTo(5);
|
||||
}
|
||||
zoomMinus(){
|
||||
this.viewer.zoomTo(-5);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,50 @@
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>home.component works!</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p><p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p><p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
<p>dfsdgdsgsdg</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Add tutorial</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content *ngIf="!submitted">
|
||||
<mat-form-field class="example-full-width">
|
||||
<mat-label>Title</mat-label>
|
||||
<input matInput [(ngModel)]="query">
|
||||
</mat-form-field>
|
||||
<!– <kendo-editor [(ngModel)]="tutorial.description" ></kendo-editor>–>
|
||||
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button matButton (click)="generateImage()" >Save</button>
|
||||
<div>
|
||||
<h4>Tutorial was submitted successfully!</h4>
|
||||
|
||||
</div>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
|
||||
|
||||
<div>
|
||||
<angular-image-viewer [src]="images" [(config)]="config" [(index)]="imageIndexOne"
|
||||
[screenHeightOccupied]='0' (customImageEvent)="handleEvent($event)" >
|
||||
</angular-image-viewer>
|
||||
</div>
|
||||
-->
|
||||
|
||||
@@ -1,11 +1,76 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
||||
import {MatFormField, MatInput, MatLabel} from '@angular/material/input';
|
||||
import {AngularImageViewerModule, CustomImageEvent, ImageViewerConfig} from '@hreimer/angular-image-viewer';
|
||||
|
||||
import {ZhipuaiImageService} from '../../services/zhipuai-image.service';
|
||||
import {MatButton} from '@angular/material/button';
|
||||
|
||||
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {MatCard, MatCardActions, MatCardContent, MatCardHeader} from '@angular/material/card';
|
||||
import {Image} from '../../models/image';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home.component',
|
||||
imports: [],
|
||||
imports: [
|
||||
|
||||
AngularImageViewerModule,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './home.component.html',
|
||||
styleUrl: './home.component.scss'
|
||||
styleUrl: './home.component.scss',
|
||||
schemas :[CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
|
||||
export class HomeComponent {
|
||||
|
||||
query : string = '';
|
||||
|
||||
images = [];
|
||||
image: Image = {
|
||||
url: ''
|
||||
};
|
||||
imageIndexOne = 0;
|
||||
|
||||
config: ImageViewerConfig = { customBtns: [{ name: 'print', icon: {
|
||||
classes: 'fas fa-paperclip',
|
||||
text: 'link'
|
||||
} }, { name: 'link', icon: {
|
||||
classes: 'fas fa-paperclip',
|
||||
text: 'link'
|
||||
} }] };
|
||||
|
||||
submitted: boolean = false;
|
||||
|
||||
constructor(private zhipuaiImageService: ZhipuaiImageService) {
|
||||
|
||||
}
|
||||
|
||||
handleEvent(event: CustomImageEvent) {
|
||||
console.log(`${event.name} has been click on img ${event.imageIndex + 1}`);
|
||||
|
||||
switch (event.name) {
|
||||
case 'print':
|
||||
console.log('run print logic');
|
||||
break;
|
||||
}
|
||||
}
|
||||
generateImage(){
|
||||
this.zhipuaiImageService.generate(this.query).subscribe(
|
||||
data => {
|
||||
this.image = data;
|
||||
// @ts-ignore
|
||||
this.images = [this.image.url];
|
||||
|
||||
|
||||
console.log(data);
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<!--<p>main.component works!</p>-->
|
||||
|
||||
<mat-toolbar class="fixed-top">
|
||||
<button mat-raised-button routerLink="/" href="#">
|
||||
<img ngSrc="jambotron_logo.svg" height="40" width="135">
|
||||
<button mat-raised-button routerLink="home">
|
||||
<!-- <img ngSrc="jambotron_logo.svg" height="40" width="135">-->
|
||||
My App
|
||||
</button>
|
||||
<span class="menu-spacer"></span>
|
||||
<button mat-raised-button routerLink="generate-image">
|
||||
Generate Image
|
||||
</button>
|
||||
<button mat-raised-button routerLink="tutorials">
|
||||
Tutorials
|
||||
</button>
|
||||
@@ -17,14 +20,14 @@
|
||||
<span class="menu-spacer"></span>
|
||||
@if (showAdminBoard) {
|
||||
<button mat-raised-button routerLink="admin/welcome">
|
||||
<mat-icon>manage_accounts</mat-icon>
|
||||
<!-- <mat-icon>manage_accounts</mat-icon>-->
|
||||
Admin Bord
|
||||
</button>
|
||||
}
|
||||
|
||||
@if (showAdminBoard) {
|
||||
<button mat-raised-button routerLink="admin/system" >
|
||||
<mat-icon>settings_applications</mat-icon>
|
||||
<!-- <mat-icon>settings_applications</mat-icon>-->
|
||||
System
|
||||
</button>
|
||||
}
|
||||
@@ -32,7 +35,7 @@
|
||||
<span class="menu-spacer"></span>
|
||||
@if (isLoggedIn) {
|
||||
<button mat-raised-button routerLink="register">
|
||||
<mat-icon>app_registration</mat-icon>
|
||||
<!-- <mat-icon>app_registration</mat-icon>-->
|
||||
Register
|
||||
</button>
|
||||
}
|
||||
@@ -40,17 +43,17 @@
|
||||
<button mat-raised-button (click)="openDialog('100ms', '5ms')" >
|
||||
<!-- <i antIcon type="bell" theme="outline"></i>-->
|
||||
<!-- <mat-icon>login</mat-icon>-->
|
||||
<i class="d- f-20" antIcon theme="outline" type="login">Login</i>
|
||||
<!-- <i class="d- f-20" antIcon theme="outline" type="login">Login</i>-->
|
||||
</button>
|
||||
}
|
||||
@if (isLoggedIn) {
|
||||
<button mat-raised-button routerLink="profile" >
|
||||
<mat-icon>account_circle</mat-icon>
|
||||
<!-- <mat-icon>account_circle</mat-icon>-->
|
||||
{{ username }}
|
||||
</button>
|
||||
<button mat-raised-button (click)="logout()">
|
||||
|
||||
<i class="d-flex f-20" antIcon theme="outline" type="logout"></i>
|
||||
<!-- <i class="d-flex f-20" antIcon theme="outline" type="logout"></i>-->
|
||||
Logout
|
||||
</button>
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import {Component, CUSTOM_ELEMENTS_SCHEMA, inject, OnInit} from '@angular/core';
|
||||
//import {NavigationComponent} from '../navigation/navigation.component';
|
||||
import {NgClass, NgOptimizedImage} from '@angular/common';
|
||||
import {NavigationComponent} from '../../layouts/admin-layout/navigation/navigation.component';
|
||||
|
||||
import {Router, RouterLink, RouterOutlet} from '@angular/router';
|
||||
import {BreadcrumbComponent} from '../../components/breadcrumb/breadcrumb.component';
|
||||
import {NavBarComponent} from '../../layouts/admin-layout/nav-bar/nav-bar.component';
|
||||
import {MatToolbar} from '@angular/material/toolbar';
|
||||
import {MatButton} from '@angular/material/button';
|
||||
import {IconDirective, IconService} from '@ant-design/icons-angular';
|
||||
@@ -22,17 +19,20 @@ import {
|
||||
PhoneOutline, ProfileOutline, QuestionCircleOutline,
|
||||
SettingOutline, UnorderedListOutline, UserOutline, WalletOutline
|
||||
} from '@ant-design/icons-angular/icons';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-main.component',
|
||||
imports: [
|
||||
NavBarComponent,
|
||||
|
||||
MatToolbar,
|
||||
MatButton,
|
||||
RouterLink,
|
||||
IconDirective,
|
||||
RouterOutlet,
|
||||
NgOptimizedImage
|
||||
CommonModule
|
||||
|
||||
],
|
||||
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
|
||||
templateUrl: './main.component.html',
|
||||
|
||||
@@ -2,12 +2,30 @@ import {RouterModule} from '@angular/router';
|
||||
import {MainComponent} from './main.component/main.component';
|
||||
import {mainRouting} from './main.routing';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
import {HTTP_INTERCEPTORS} from '@angular/common/http';
|
||||
import {CustomHttpInterceptor} from '../helpers/custom-http-interceptor';
|
||||
import {AngularImageViewerModule} from '@hreimer/angular-image-viewer';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
||||
],
|
||||
imports: [mainRouting, MainComponent],
|
||||
imports: [
|
||||
mainRouting,
|
||||
MainComponent,
|
||||
|
||||
|
||||
|
||||
],
|
||||
exports: [RouterModule],
|
||||
providers: [{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: CustomHttpInterceptor,
|
||||
multi: true
|
||||
}],
|
||||
})
|
||||
export class MainModule {}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {TutorialsComponent} from '../components/tutorials.component/tutorials.co
|
||||
import {AddTutorialComponent} from '../components/add-tutorial/add-tutorial.component';
|
||||
import {RegisterComponent} from '../components/register/register.component';
|
||||
import {ProfileComponent} from '../components/profile/profile.component';
|
||||
import {GenerateImageComponent} from '../components/generate-image.component/generate-image.component';
|
||||
|
||||
const MAIN_ROUTES: Routes =[
|
||||
{
|
||||
@@ -21,6 +22,10 @@ const MAIN_ROUTES: Routes =[
|
||||
path: 'home',
|
||||
component: HomeComponent
|
||||
},
|
||||
{
|
||||
path: 'generate-image',
|
||||
component: GenerateImageComponent
|
||||
},
|
||||
{
|
||||
path: 'tutorials',
|
||||
component: TutorialsComponent
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export class Image {
|
||||
|
||||
url?:string;
|
||||
b64Json?:boolean;
|
||||
}
|
||||
@@ -21,6 +21,10 @@ export class SystemService {
|
||||
return this.http.get<Bean[]>(this.baseUrl+"/beans");
|
||||
}
|
||||
|
||||
getImage(): Observable<Blob> {
|
||||
return this.http.get(this.baseUrl+"/image", {responseType: 'blob'});
|
||||
}
|
||||
|
||||
getCustomBeans(): Observable<Bean[]> {
|
||||
return this.http.get<Bean[]>(this.baseUrl+"/beans/custom");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ZhipuaiImageService } from './zhipuai-image.service';
|
||||
|
||||
describe('ZhipuaiImageService', () => {
|
||||
let service: ZhipuaiImageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ZhipuaiImageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Tutorial} from '../models/tutorial.model';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Image} from '../models/image';
|
||||
import {SpinnerService} from './spinner.service';
|
||||
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
|
||||
export class ZhipuaiImageService {
|
||||
baseUrl : string = 'http://localhost:8080/api/zhipuai';
|
||||
|
||||
constructor(private http: HttpClient,public spinnerService: SpinnerService) {
|
||||
|
||||
}
|
||||
|
||||
generate(query: String): Observable<Image> {
|
||||
return this.http.get(`${(this.baseUrl)}/image/${query}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.jambotronGroup.jambotron.ZhiPuAi;
|
||||
|
||||
import com.jambotronGroup.jambotron.model.NameValueItem;
|
||||
import org.springframework.ai.image.Image;
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.image.ImageResponse;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@RequestMapping("/api/zhipuai")
|
||||
public class ImageController {
|
||||
|
||||
@Autowired
|
||||
ZhiPuAiImageService _zhiPuAiImageService;
|
||||
|
||||
@GetMapping("/image/{query}")
|
||||
public ResponseEntity<Image> getImage(@PathVariable("query") String query) {
|
||||
try {
|
||||
Image returnValue = _zhiPuAiImageService.generateImage(query).getResult().getOutput();
|
||||
//userRepository.findAll().forEach(users::add);
|
||||
|
||||
|
||||
if (returnValue == null) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(returnValue, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,45 @@
|
||||
package com.jambotronGroup.jambotron.ZhiPuAi;
|
||||
|
||||
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.image.ImageResponse;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
//import org.springframework.web.reactive.function.client.WebClient;
|
||||
//
|
||||
//@Service
|
||||
//public class ZhiPuAiImageService {
|
||||
//
|
||||
// @Value("${spring.ai.zhipuai.base-url}")
|
||||
// private String baseUrl;
|
||||
//
|
||||
// @Value("${spring.ai.zhipuai.api-key}")
|
||||
// private String apiKey;
|
||||
//
|
||||
// private final WebClient webClient;
|
||||
//
|
||||
// public ZhiPuAiImageService(WebClient.Builder webClientBuilder) {
|
||||
// this.webClient = webClientBuilder.baseUrl(baseUrl).build();
|
||||
// }
|
||||
//
|
||||
// public String generateImage(String prompt) {
|
||||
// return webClient.post()
|
||||
// .uri("/image/generate")
|
||||
// .header("Authorization", "Bearer " + apiKey)
|
||||
// .bodyValue(new ImageRequest(prompt))
|
||||
// .retrieve()
|
||||
// .bodyToMono(String.class)
|
||||
// .block();
|
||||
// }
|
||||
//
|
||||
// private static class ImageRequest {
|
||||
// private final String prompt;
|
||||
//
|
||||
// public ImageRequest(String prompt) {
|
||||
// this.prompt = prompt;
|
||||
// }
|
||||
//
|
||||
// public String getPrompt() {
|
||||
// return prompt;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@Service
|
||||
public class ZhiPuAiImageService {
|
||||
|
||||
@Value("${spring.ai.zhipuai.base-url}")
|
||||
private String baseUrl;
|
||||
|
||||
@Value("${spring.ai.zhipuai.api-key}")
|
||||
private String apiKey;
|
||||
|
||||
|
||||
private ZhiPuAiImageApi _zhiPuAiImageApi;
|
||||
|
||||
private ZhiPuAiImageModel _zhiPuAiImageModel;
|
||||
|
||||
public ZhiPuAiImageService() {
|
||||
|
||||
_zhiPuAiImageApi = new ZhiPuAiImageApi("628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI");
|
||||
|
||||
_zhiPuAiImageModel = new ZhiPuAiImageModel(_zhiPuAiImageApi);
|
||||
}
|
||||
|
||||
public ImageResponse generateImage(String prompt) {
|
||||
// Create an ImagePrompt object with the desired prompt
|
||||
ImagePrompt imagePrompt = new ImagePrompt(prompt);
|
||||
|
||||
// Call the generate method to get the image response
|
||||
ImageResponse imageResponse = _zhiPuAiImageModel.call(imagePrompt);
|
||||
|
||||
// Return the image response
|
||||
return imageResponse;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -23,6 +23,8 @@ public class SystemController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/data-source-properties")
|
||||
public ResponseEntity<List<NameValueItem>> getDataSourceProperties(@RequestParam(required = false) String title) {
|
||||
try {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
public class ZhiPuAiController {
|
||||
|
||||
// This class is a placeholder for the ZhiPuAiController.
|
||||
// You can implement methods to handle requests related to ZhiPuAi functionality.
|
||||
// For example, you might want to add methods for generating images or processing text.
|
||||
|
||||
// Example method (to be implemented):
|
||||
// @GetMapping("/generate-image")
|
||||
// public ResponseEntity<String> generateImage(@RequestParam String prompt) {
|
||||
// String imageUrl = zhiPuAiService.generateImage(prompt);
|
||||
// return new ResponseEntity<>(imageUrl, HttpStatus.OK);
|
||||
// }
|
||||
}
|
||||
@@ -120,6 +120,8 @@ public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecuri
|
||||
.requestMatchers("/api/test/**").permitAll()
|
||||
.requestMatchers("/api/tutorials").permitAll()
|
||||
|
||||
.requestMatchers("/api/zhipuai/image/**").permitAll()
|
||||
|
||||
.requestMatchers("/api/users").permitAll()
|
||||
.requestMatchers("/api/users/**").permitAll()
|
||||
|
||||
|
||||
@@ -12,4 +12,6 @@ public interface SystemService {
|
||||
|
||||
List<NameValueItem> getDataSourceProperties();
|
||||
|
||||
List<NameValueItem> getImage();
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ import com.jambotronGroup.jambotron.model.NameValueItem;
|
||||
import com.jambotronGroup.jambotron.utils.EntityLoggingConsumer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.image.ImageResponse;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -29,11 +33,14 @@ public class SystemServiceImpl implements SystemService {
|
||||
@Autowired
|
||||
DataSourceProperties _dataSourceProperties;
|
||||
|
||||
@Autowired
|
||||
ZhiPuAiImageModel imageClient;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SystemServiceImpl.class);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<NameValueItem> getDataSourceProperties(){
|
||||
List<NameValueItem> returnValue = new ArrayList<NameValueItem>();
|
||||
|
||||
@@ -45,6 +52,28 @@ public class SystemServiceImpl implements SystemService {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NameValueItem> getImage(){
|
||||
List<NameValueItem> returnValue = new ArrayList<NameValueItem>();
|
||||
|
||||
ZhiPuAiImageApi api = new ZhiPuAiImageApi("628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI");
|
||||
|
||||
ZhiPuAiImageModel imageClient = new ZhiPuAiImageModel(api);
|
||||
|
||||
//imageClient.
|
||||
|
||||
|
||||
//imageClient.getDefaultOptions().setUser("44621746535994937");
|
||||
|
||||
ImageResponse imageResponse = imageClient.call(new ImagePrompt("Ukr zaliznicya station in the style cubisme"));
|
||||
|
||||
|
||||
|
||||
returnValue.add(new NameValueItem("response", "imageResponse."));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Bean> getLodedBeans() {
|
||||
// Get all bean names from the application context and map them to Bean objects
|
||||
|
||||
@@ -48,5 +48,5 @@ spring.flyway.url=jdbc:postgresql://localhost:5432/jambotronDB
|
||||
|
||||
|
||||
|
||||
//spring.ai.zhipuai.base-url=https://open.bigmodel.cn/api/paas/v3
|
||||
//spring.ai.zhipuai.api-key = 628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI
|
||||
spring.ai.zhipuai.base-url=https://open.bigmodel.cn/api/paas/v4/images/generations
|
||||
spring.ai.zhipuai.api-key = 628447c8c65845a48a7226391464a2ea.Dw8ci6TiW0BRF5LI
|
||||
|
||||
Reference in New Issue
Block a user