From 8d0fb87da5fcb9e9476a8a180c0f94da1160c589 Mon Sep 17 00:00:00 2001 From: kachourihassen <60717797+kachourihassen@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:52:38 +0100 Subject: [PATCH] Generate brief with AI (#593) * Generate brief with AI * wip * en api key --- .../draft-campaign-presentation.component.css | 23 +++++- ...draft-campaign-presentation.component.html | 74 ++++++++++++------- .../draft-campaign-presentation.component.ts | 28 ++++++- src/app/campaigns/facade/campaigns.facade.ts | 4 + .../services/campaign/campaign.service.ts | 15 ++++ src/assets/i18n/en.json | 3 +- src/assets/i18n/fr.json | 3 +- src/environments/environment.prod.ts | 1 + src/environments/environment.ts | 2 +- 9 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.css b/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.css index be16b9e97..44d86d89b 100755 --- a/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.css +++ b/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.css @@ -446,4 +446,25 @@ ng-deep .cropper .resize-bar { ::ng-deep.CodeMirror pre { white-space: pre !important; -} \ No newline at end of file +} +.btn-blue { + font-style: normal; + font-weight: 600; + font-size: 18px; + line-height: 48.4px; + align-items: center; + text-align: center; + letter-spacing: 0.03em; + border: none; + color: #ffff; + background: #4048ff; + box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25); + border-radius: 30px; + width: 100%; + height: 48px; +} + +.btn-blue:hover:enabled { + background: linear-gradient(85.14deg, #f52079 -1.05%, #4048ff 103.39%); + box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25); +} diff --git a/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.html b/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.html index 165371bdd..6cacdd0db 100755 --- a/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.html +++ b/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.html @@ -8,24 +8,52 @@ }} +
-
+
{{ 'campaign_name' | translate }} + +
+ {{ 'Profil.field_required' | translate }} - -
- {{ 'Profil.field_required' | translate }} -
+
+ +
+
+ + +
+
- -
- - - + +
+ +
+
diff --git a/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.ts b/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.ts index 489440442..a79e7b3e6 100755 --- a/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.ts +++ b/src/app/campaigns/components/draft-campaign-presentation/draft-campaign-presentation.component.ts @@ -18,6 +18,9 @@ import { DraftCampaignService } from '@campaigns/services/draft-campaign.service import { Campaign } from '@app/models/campaign.model'; import { TranslateService } from '@ngx-translate/core'; import { ImageTransform } from 'ngx-image-cropper'; +import { FormBuilder, FormGroup } from '@angular/forms'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { CampaignsService } from '@app/campaigns/facade/campaigns.facade'; @Component({ selector: 'app-draft-campaign-presentation', @@ -36,6 +39,8 @@ export class DraftCampaignPresentationComponent implements OnInit { @Output() validFormPresentation = new EventEmitter(); @Output() saveFormStatus = new EventEmitter(); private render: Renderer2; + isGenerating: boolean = false; + ai_result :any; containWithinAspectRatio = false; form = new UntypedFormGroup({}); editor = new Editor(); @@ -52,12 +57,22 @@ export class DraftCampaignPresentationComponent implements OnInit { draftId: string = ''; private isDestroyed$ = new Subject(); + + constructor( + private fb: FormBuilder, + private http: HttpClient, private service: DraftCampaignService, public translate: TranslateService, + private campaignFacade: CampaignsService, rendererFactory: RendererFactory2, + @Inject(PLATFORM_ID) private platformId: string ) { + this.form = fb.group({ + title: ['', Validators.required], + description: [''] // Assuming you have a description field in your form + }); this.render = rendererFactory.createRenderer(null, null); this.form = new UntypedFormGroup({ title: new UntypedFormControl('', Validators.required), @@ -69,10 +84,19 @@ export class DraftCampaignPresentationComponent implements OnInit { ]), description: new UntypedFormControl('', Validators.required) }); - - } + + generateBrief() { + this.isGenerating = true; +this.campaignFacade.generateBriefIA(this.form.get('title')?.value).subscribe((data:any) => { +this.ai_result= data.choices[0].message.content; +this.form.patchValue({ description: this.ai_result }); +this.isGenerating = false; + }) +} + + ngOnInit(): void { this.saveForm(); this.emitFormStatus(); diff --git a/src/app/campaigns/facade/campaigns.facade.ts b/src/app/campaigns/facade/campaigns.facade.ts index 2e57844a6..ed94fec76 100755 --- a/src/app/campaigns/facade/campaigns.facade.ts +++ b/src/app/campaigns/facade/campaigns.facade.ts @@ -78,4 +78,8 @@ export class CampaignsService implements CampaignsFacade { getWelcomePageStats() { return this.campaignsHttpApiService.getWelcomePageStats(); } + + generateBriefIA(title: string) { + return this.campaignsHttpApiService.generateBrief(title); + } } diff --git a/src/app/core/services/campaign/campaign.service.ts b/src/app/core/services/campaign/campaign.service.ts index c0322ca17..a78ae3a66 100755 --- a/src/app/core/services/campaign/campaign.service.ts +++ b/src/app/core/services/campaign/campaign.service.ts @@ -109,6 +109,21 @@ export class CampaignHttpApiService { hash }); } + generateBrief(title: string) { + console.log(title); + const apiUrl = 'https://api.openai.com/v1/chat/completions'; + const payload = { + "model": "gpt-3.5-turbo", + "messages": [{"role": "user", "content": "please create a comprehensive Influencer Campaign Brief for me that will serve as an explanatory sheet for integration into a campaign presentation platform. We need title, description, short description, rules, and examples."+ title, }], + "temperature": 0.7 + }; + + const headers = new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + env.API_AI, + }); + return this.http.post(`${apiUrl}`, payload, { headers }); + } getBestInfluencerPic(id: any) { return this.http.get(sattUrl + `/profile/picture?id=${id}`, { diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 65e30e07d..3f3ffe5a3 100755 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -643,7 +643,8 @@ "create_campaign_form.create_new_campaign": "Finalize my Pool", "create_campaign_form.alert_required": "Warning! Please fill in the necessary fields", "create_campaign_form.summary_maxlength": "Summary must contain a maximum of 250 characters", - + "generate_campaign_Ai": "Generate brief", + "campaign_Ai":"Adpool Brief IA generator", "date": "Date", "description": "Description", "desktop": "Desktop", diff --git a/src/assets/i18n/fr.json b/src/assets/i18n/fr.json index d3c7d8a14..59f7b0dd9 100755 --- a/src/assets/i18n/fr.json +++ b/src/assets/i18n/fr.json @@ -341,7 +341,8 @@ "create_campaign_form.alert_expire": "La campagne débutera 1 heure après la validation de la campagne.", "create_campaign_form.generate_preview": "Générer un aperçu", "create_campaign_form.create_new_campaign": "Finaliser AdPool.", - + "generate_campaign_Ai": "Générer un brief", + "campaign_Ai":"Générateur Adpool Brief IA", "create_campaign_form.alert_required": "Attention! Veuillez remplir les champs nécessaires", "create_campaign_form.summary_maxlength": "Le résumé doit contenir un maximum de 250 caractères", "date": "Date", diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 9b09301a1..15accfabf 100755 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -8,6 +8,7 @@ export const environment = { 'https://api.thegraph.com/subgraphs/name/atayen/satt--bsc-mainnet', url_subgraph_ether: 'https://api.thegraph.com/subgraphs/name/atayen/satt-ether-mainnet', + API_AI: '', addresses: { smartContracts: { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 083f67bfb..f958bb7e7 100755 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -11,7 +11,7 @@ export const environment = { //https://api-preprod2.satt-token.com API_URL: 'https://api-preprod2.satt-token.com', - + API_AI: '', url_subgraph_bsc: 'https://api.thegraph.com/subgraphs/name/atayen/satt-testnet', url_subgraph_ether: