From 84e425ab79c7951c0c695cb453f19037a08c2ae9 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Wed, 29 Nov 2023 15:45:27 +0300 Subject: [PATCH 1/9] Optionally show/hide chat toolbar --- src/app/chat/chat.component.html | 2 +- src/app/chat/chat.component.ts | 3 ++- src/app/community/community.component.html | 3 +++ src/app/community/community.component.ts | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/chat/chat.component.html b/src/app/chat/chat.component.html index aa93842e40..678f107d92 100644 --- a/src/app/chat/chat.component.html +++ b/src/app/chat/chat.component.html @@ -1,4 +1,4 @@ - + AI Chat diff --git a/src/app/chat/chat.component.ts b/src/app/chat/chat.component.ts index 810f9c1963..15b655eb25 100644 --- a/src/app/chat/chat.component.ts +++ b/src/app/chat/chat.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; @Component({ @@ -7,6 +7,7 @@ import { ActivatedRoute, Router } from '@angular/router'; styleUrls: [ './chat.scss' ] }) export class ChatComponent { + @Input() showToolbar = true; constructor( private route: ActivatedRoute, diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index 2fcc6bd7a6..981da17fba 100644 --- a/src/app/community/community.component.html +++ b/src/app/community/community.component.html @@ -10,6 +10,9 @@

+ + +
diff --git a/src/app/community/community.component.ts b/src/app/community/community.component.ts index 6d822dbd1f..73042e78fc 100644 --- a/src/app/community/community.component.ts +++ b/src/app/community/community.component.ts @@ -48,6 +48,7 @@ export class CommunityComponent implements OnInit, OnDestroy { resizeCalendar: any = false; deviceType: DeviceType; deviceTypes = DeviceType; + showChatToolbar = false; constructor( private dialog: MatDialog, From ba0e9b3751fa21b56248bce4a012e234d4f639a6 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Wed, 29 Nov 2023 18:14:19 +0300 Subject: [PATCH 2/9] Fix slice error --- src/app/chat/chat-sidebar/chat-sidebar.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.html b/src/app/chat/chat-sidebar/chat-sidebar.component.html index 17399c48e2..5137e17b8e 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.html +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.html @@ -38,7 +38,7 @@ - {{ conversation?.title?.slice(0, 25) || conversation.conversations[0].query.slice(0, 25) }} + {{ conversation?.title?.slice(0, 25) }} From 811be119351801723b7658a274c7ddcbea530b22 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Wed, 29 Nov 2023 18:29:42 +0300 Subject: [PATCH 3/9] First iteration community advisor --- .../chat-sidebar/chat-sidebar.component.html | 2 +- .../chat-sidebar/chat-sidebar.component.ts | 5 ++- .../chat/chat-window/chat-window.component.ts | 10 +++-- src/app/chat/chat.component.html | 2 +- src/app/chat/chat.component.ts | 44 ++++++++++++++++--- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.html b/src/app/chat/chat-sidebar/chat-sidebar.component.html index 5137e17b8e..141f9814e3 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.html +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.html @@ -54,6 +54,6 @@ chevron_right
- + diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.ts b/src/app/chat/chat-sidebar/chat-sidebar.component.ts index 41289001f2..211ae0def5 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.ts +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -29,6 +29,8 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { this.recordSearch(); this.filterConversations(); } + @Input() dataPreload; + chatDataPreload: any; constructor( private chatService: ChatService, @@ -38,6 +40,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { ) {} ngOnInit() { + this.chatDataPreload = this.dataPreload; this.titleSearch = ''; this.getChatHistory(); this.subscribeToNewChats(); diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index e620952057..3a9abc79bb 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, ViewChild, ElementRef, ChangeDetectorRef } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input, ViewChild, ElementRef, ChangeDetectorRef } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -27,6 +27,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy { _id: '', _rev: '' }; + @Input() chatDataPreload; @ViewChild('chat') chatContainer: ElementRef; @@ -118,13 +119,14 @@ export class ChatWindowComponent implements OnInit, OnDestroy { } submitPrompt() { - const content = this.promptForm.get('prompt').value; + const query = this.promptForm.get('prompt').value + const content = this.chatDataPreload ? this.chatDataPreload + query : query; this.data.content = content; this.setSelectedConversation(); this.chatService.getPrompt(this.data, true).subscribe( (completion: any) => { - this.conversations.push({ query: content, response: completion?.chat }); + this.conversations.push({ query, response: completion?.chat }); this.selectedConversationId = { '_id': completion.couchDBResponse?.id, '_rev': completion.couchDBResponse?.rev @@ -134,7 +136,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy { }, (error: any) => { this.spinnerOn = false; - this.conversations.push({ query: content, response: 'Error: ' + error.message, error: true }); + this.conversations.push({ query, response: 'Error: ' + error.message, error: true}); this.postSubmit(); } ); diff --git a/src/app/chat/chat.component.html b/src/app/chat/chat.component.html index 678f107d92..c41899a993 100644 --- a/src/app/chat/chat.component.html +++ b/src/app/chat/chat.component.html @@ -5,5 +5,5 @@
- +
diff --git a/src/app/chat/chat.component.ts b/src/app/chat/chat.component.ts index 15b655eb25..d26345a8a3 100644 --- a/src/app/chat/chat.component.ts +++ b/src/app/chat/chat.component.ts @@ -9,13 +9,47 @@ import { ActivatedRoute, Router } from '@angular/router'; export class ChatComponent { @Input() showToolbar = true; - constructor( - private route: ActivatedRoute, - private router: Router, - ) {} + dataPreload = + ` + This is a community overview and community description, take note of it when replying to the question. You don't have to acknowledge that you have receiced the data + + Welcome to Planet Mutugi Community! + + 🌍 About Us: Planet Mutugi is a vibrant online hub dedicated to knowledge sharing and community support. Whether you're a passionate learner, a small business owner, or an enthusiast in various fields, you'll find a welcoming space here. + + 📚 Courses and Resources: Explore a vast array of courses and resources tailored to your interests. From chicken farming to solar panel sales, we've got you covered. Dive into our curated content and enhance your skills with the latest information and best practices. + + 🤝 Teams and Enterprise Section: Connect with like-minded individuals and professionals in our Teams and Enterprise section. Collaborate on projects, share insights, and build a network that fosters growth and innovation. + + 💼 Small Enterprise Assistance: For small enterprises involved in chicken farming, solar panel sales, and beyond, our community provides valuable assistance. Engage in discussions, seek advice, and access resources that can propel your business forward. + + 🔧 Why Join Planet Mutugi? + + Access a wealth of courses and resources. Connect with professionals and enthusiasts. Receive support for small enterprises in specialized areas. Stay updated on industry trends and best practices. Collaborate on projects and explore new opportunities. Join us on Planet Mutugi and embark on a journey of learning, collaboration, and growth! + + Services + Planet Mutugi offers a range of services to cater to the diverse needs of our community members. Here's a list of services provided: + + Course Sharing Platform: + Access a diverse collection of courses spanning various topics, including chicken farming, solar panel sales, and more. + + Resource Repository: + Explore a rich repository of resources such as articles, guides, and tools to enhance your knowledge and skills. + + Teams and Enterprise Collaboration: + Connect with professionals and enthusiasts in dedicated Teams and Enterprise sections to collaborate on projects and share expertise. + + Small Enterprise Assistance: + Receive targeted support and guidance for small enterprises, with a focus on sectors like chicken farming, solar panel sales, and related businesses. + + Discussion Forums: + Engage in vibrant discussions on our forums to exchange ideas, seek advice, and stay updated on industry trends. + `; + + + constructor(private route: ActivatedRoute, private router: Router) {} goBack() { this.router.navigate([ '/' ], { relativeTo: this.route }); } - } From 1d8d6babfcce1f0c7e614ba7d33d759309860684 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Thu, 30 Nov 2023 12:07:43 +0300 Subject: [PATCH 4/9] Configure chatapi to handle data preloads --- chatapi/src/services/chat.service.ts | 2 +- chatapi/src/utils/gpt-chat.utils.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/chatapi/src/services/chat.service.ts b/chatapi/src/services/chat.service.ts index 57c1fac5dc..91df3bd164 100644 --- a/chatapi/src/services/chat.service.ts +++ b/chatapi/src/services/chat.service.ts @@ -30,7 +30,7 @@ export async function chat(data: any): Promise<{ messages.push({ 'role': 'user', content }); try { - const completionText = await gptChat(messages); + const completionText = await gptChat(messages, dbData?.preload ? dbData.preload : null); dbData.conversations[dbData.conversations.length - 1].response = completionText; diff --git a/chatapi/src/utils/gpt-chat.utils.ts b/chatapi/src/utils/gpt-chat.utils.ts index ef5d3515f1..a906b62c3f 100644 --- a/chatapi/src/utils/gpt-chat.utils.ts +++ b/chatapi/src/utils/gpt-chat.utils.ts @@ -6,7 +6,10 @@ import { ChatMessage } from '../models/chat-message.model'; * @param messages - Array of chat messages * @returns Completion text */ -export async function gptChat(messages: ChatMessage[]): Promise { +export async function gptChat(messages: ChatMessage[], dataPreload?: any): Promise { + if(dataPreload) { + messages[0].content = `${dataPreload} \t ${messages[0].content}`; + } const completion = await openai.createChatCompletion({ 'model': 'gpt-3.5-turbo', messages, From 310d0849505c919439b4b6b8f938093438b9b13c Mon Sep 17 00:00:00 2001 From: mutugiii Date: Thu, 30 Nov 2023 12:08:26 +0300 Subject: [PATCH 5/9] Configure the chat component to send the preload data if present --- .../chat-sidebar/chat-sidebar.component.html | 2 +- .../chat-sidebar/chat-sidebar.component.ts | 2 - .../chat/chat-window/chat-window.component.ts | 9 +++-- src/app/chat/chat.component.ts | 39 +------------------ 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.html b/src/app/chat/chat-sidebar/chat-sidebar.component.html index 141f9814e3..c2727d327f 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.html +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.html @@ -54,6 +54,6 @@ chevron_right - + diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.ts b/src/app/chat/chat-sidebar/chat-sidebar.component.ts index 211ae0def5..0c3b2a6baa 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.ts +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.ts @@ -30,7 +30,6 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { this.filterConversations(); } @Input() dataPreload; - chatDataPreload: any; constructor( private chatService: ChatService, @@ -40,7 +39,6 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { ) {} ngOnInit() { - this.chatDataPreload = this.dataPreload; this.titleSearch = ''; this.getChatHistory(); this.subscribeToNewChats(); diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index 3a9abc79bb..f39c1909ed 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -24,10 +24,11 @@ export class ChatWindowComponent implements OnInit, OnDestroy { user: this.userService.get(), time: this.couchService.datePlaceholder, content: '', + preload: null, _id: '', _rev: '' }; - @Input() chatDataPreload; + @Input() dataPreload; @ViewChild('chat') chatContainer: ElementRef; @@ -120,8 +121,10 @@ export class ChatWindowComponent implements OnInit, OnDestroy { submitPrompt() { const query = this.promptForm.get('prompt').value - const content = this.chatDataPreload ? this.chatDataPreload + query : query; - this.data.content = content; + if (this.dataPreload) { + this.data.preload = this.dataPreload + } + this.data.content = query; this.setSelectedConversation(); this.chatService.getPrompt(this.data, true).subscribe( diff --git a/src/app/chat/chat.component.ts b/src/app/chat/chat.component.ts index d26345a8a3..10a5f32c44 100644 --- a/src/app/chat/chat.component.ts +++ b/src/app/chat/chat.component.ts @@ -8,44 +8,7 @@ import { ActivatedRoute, Router } from '@angular/router'; }) export class ChatComponent { @Input() showToolbar = true; - - dataPreload = - ` - This is a community overview and community description, take note of it when replying to the question. You don't have to acknowledge that you have receiced the data - - Welcome to Planet Mutugi Community! - - 🌍 About Us: Planet Mutugi is a vibrant online hub dedicated to knowledge sharing and community support. Whether you're a passionate learner, a small business owner, or an enthusiast in various fields, you'll find a welcoming space here. - - 📚 Courses and Resources: Explore a vast array of courses and resources tailored to your interests. From chicken farming to solar panel sales, we've got you covered. Dive into our curated content and enhance your skills with the latest information and best practices. - - 🤝 Teams and Enterprise Section: Connect with like-minded individuals and professionals in our Teams and Enterprise section. Collaborate on projects, share insights, and build a network that fosters growth and innovation. - - 💼 Small Enterprise Assistance: For small enterprises involved in chicken farming, solar panel sales, and beyond, our community provides valuable assistance. Engage in discussions, seek advice, and access resources that can propel your business forward. - - 🔧 Why Join Planet Mutugi? - - Access a wealth of courses and resources. Connect with professionals and enthusiasts. Receive support for small enterprises in specialized areas. Stay updated on industry trends and best practices. Collaborate on projects and explore new opportunities. Join us on Planet Mutugi and embark on a journey of learning, collaboration, and growth! - - Services - Planet Mutugi offers a range of services to cater to the diverse needs of our community members. Here's a list of services provided: - - Course Sharing Platform: - Access a diverse collection of courses spanning various topics, including chicken farming, solar panel sales, and more. - - Resource Repository: - Explore a rich repository of resources such as articles, guides, and tools to enhance your knowledge and skills. - - Teams and Enterprise Collaboration: - Connect with professionals and enthusiasts in dedicated Teams and Enterprise sections to collaborate on projects and share expertise. - - Small Enterprise Assistance: - Receive targeted support and guidance for small enterprises, with a focus on sectors like chicken farming, solar panel sales, and related businesses. - - Discussion Forums: - Engage in vibrant discussions on our forums to exchange ideas, seek advice, and stay updated on industry trends. - `; - + @Input() dataPreload; constructor(private route: ActivatedRoute, private router: Router) {} From 7696983b7bda93aa8647e1a3843d1d74587ce611 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Thu, 30 Nov 2023 12:10:20 +0300 Subject: [PATCH 6/9] send the preload data from the community --- src/app/community/community.component.html | 2 +- src/app/community/community.component.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index 981da17fba..074d430ffb 100644 --- a/src/app/community/community.component.html +++ b/src/app/community/community.component.html @@ -11,7 +11,7 @@

- +
diff --git a/src/app/community/community.component.ts b/src/app/community/community.component.ts index 73042e78fc..d383119b7e 100644 --- a/src/app/community/community.component.ts +++ b/src/app/community/community.component.ts @@ -49,6 +49,7 @@ export class CommunityComponent implements OnInit, OnDestroy { deviceType: DeviceType; deviceTypes = DeviceType; showChatToolbar = false; + dataPreload: string; constructor( private dialog: MatDialog, @@ -120,6 +121,7 @@ export class CommunityComponent implements OnInit, OnDestroy { ).subscribe(team => { this.team = team; this.servicesDescriptionLabel = this.team.description ? 'Edit' : 'Add'; + this.dataPreload = this.team?.description }); } From 55217fa0da501b4b3dead5168ffc169fa38df7cb Mon Sep 17 00:00:00 2001 From: mutugiii Date: Thu, 30 Nov 2023 12:39:11 +0300 Subject: [PATCH 7/9] remove preload object member when null --- src/app/chat/chat-window/chat-window.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index f39c1909ed..8d1d7eb5af 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -122,7 +122,9 @@ export class ChatWindowComponent implements OnInit, OnDestroy { submitPrompt() { const query = this.promptForm.get('prompt').value if (this.dataPreload) { - this.data.preload = this.dataPreload + this.data.preload = this.dataPreload; + } else { + delete this.data.preload; } this.data.content = query; this.setSelectedConversation(); From f872dfbe152928d3aa24856996c47a6804ca4b5a Mon Sep 17 00:00:00 2001 From: mutugiii Date: Thu, 30 Nov 2023 13:09:15 +0300 Subject: [PATCH 8/9] Linting fixes --- src/app/chat/chat-window/chat-window.component.ts | 4 ++-- src/app/community/community.component.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index 8d1d7eb5af..11803e2091 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -120,7 +120,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy { } submitPrompt() { - const query = this.promptForm.get('prompt').value + const query = this.promptForm.get('prompt').value; if (this.dataPreload) { this.data.preload = this.dataPreload; } else { @@ -141,7 +141,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy { }, (error: any) => { this.spinnerOn = false; - this.conversations.push({ query, response: 'Error: ' + error.message, error: true}); + this.conversations.push({ query, response: 'Error: ' + error.message, error: true }); this.postSubmit(); } ); diff --git a/src/app/community/community.component.ts b/src/app/community/community.component.ts index d383119b7e..50e03cb74c 100644 --- a/src/app/community/community.component.ts +++ b/src/app/community/community.component.ts @@ -121,7 +121,7 @@ export class CommunityComponent implements OnInit, OnDestroy { ).subscribe(team => { this.team = team; this.servicesDescriptionLabel = this.team.description ? 'Edit' : 'Add'; - this.dataPreload = this.team?.description + this.dataPreload = this.team?.description; }); } From 83130d40e01da370b8d1e2f47dc59c39adb6a5a8 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Thu, 30 Nov 2023 22:26:10 +0300 Subject: [PATCH 9/9] Linting fix --- chatapi/src/utils/gpt-chat.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatapi/src/utils/gpt-chat.utils.ts b/chatapi/src/utils/gpt-chat.utils.ts index a906b62c3f..1fbae0fc16 100644 --- a/chatapi/src/utils/gpt-chat.utils.ts +++ b/chatapi/src/utils/gpt-chat.utils.ts @@ -7,7 +7,7 @@ import { ChatMessage } from '../models/chat-message.model'; * @returns Completion text */ export async function gptChat(messages: ChatMessage[], dataPreload?: any): Promise { - if(dataPreload) { + if (dataPreload) { messages[0].content = `${dataPreload} \t ${messages[0].content}`; } const completion = await openai.createChatCompletion({