diff --git a/chatapi/src/services/chat.service.ts b/chatapi/src/services/chat.service.ts index 0aeb030066..b095c88bb3 100644 --- a/chatapi/src/services/chat.service.ts +++ b/chatapi/src/services/chat.service.ts @@ -31,7 +31,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..1fbae0fc16 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, diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.html b/src/app/chat/chat-sidebar/chat-sidebar.component.html index 17399c48e2..c2727d327f 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) }} @@ -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..0c3b2a6baa 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,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { this.recordSearch(); this.filterConversations(); } + @Input() dataPreload; constructor( private chatService: ChatService, diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index e620952057..11803e2091 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'; @@ -24,9 +24,11 @@ export class ChatWindowComponent implements OnInit, OnDestroy { user: this.userService.get(), time: this.couchService.datePlaceholder, content: '', + preload: null, _id: '', _rev: '' }; + @Input() dataPreload; @ViewChild('chat') chatContainer: ElementRef; @@ -118,13 +120,18 @@ export class ChatWindowComponent implements OnInit, OnDestroy { } submitPrompt() { - const content = this.promptForm.get('prompt').value; - this.data.content = content; + const query = this.promptForm.get('prompt').value; + if (this.dataPreload) { + this.data.preload = this.dataPreload; + } else { + delete this.data.preload; + } + this.data.content = query; 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 +141,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 aa93842e40..c41899a993 100644 --- a/src/app/chat/chat.component.html +++ b/src/app/chat/chat.component.html @@ -1,9 +1,9 @@ - + AI Chat
- +
diff --git a/src/app/chat/chat.component.ts b/src/app/chat/chat.component.ts index 810f9c1963..10a5f32c44 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,14 +7,12 @@ import { ActivatedRoute, Router } from '@angular/router'; styleUrls: [ './chat.scss' ] }) export class ChatComponent { + @Input() showToolbar = true; + @Input() dataPreload; - constructor( - private route: ActivatedRoute, - private router: Router, - ) {} + constructor(private route: ActivatedRoute, private router: Router) {} goBack() { this.router.navigate([ '/' ], { relativeTo: this.route }); } - } diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index 2fcc6bd7a6..074d430ffb 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 6c81a417cc..b7f281f379 100644 --- a/src/app/community/community.component.ts +++ b/src/app/community/community.component.ts @@ -48,6 +48,8 @@ export class CommunityComponent implements OnInit, OnDestroy { resizeCalendar: any = false; deviceType: DeviceType; deviceTypes = DeviceType; + showChatToolbar = false; + dataPreload: string; constructor( private dialog: MatDialog, @@ -119,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; }); }