Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.0.5 #14

Merged
merged 30 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5860a5b
feat: interrupted tool call
meta-d Dec 11, 2024
965dfc9
feat: sensitive tools
meta-d Dec 11, 2024
35d4ea0
feat: Interrupted chat
meta-d Dec 12, 2024
c227eba
feat: human in the loop
meta-d Dec 12, 2024
bedd050
feat: reject INTERRUPTED chat
meta-d Dec 12, 2024
b3ee9c0
feat: mutiple tool calls info
meta-d Dec 12, 2024
0e12a68
feat: sensitive operation tool call
meta-d Dec 13, 2024
44f2c35
Merge branch 'develop' into v3.0.4
meta-d Dec 13, 2024
82aaa73
version 3.0.4
meta-d Dec 13, 2024
6a37d8b
feat: primary agent not sensitive
meta-d Dec 13, 2024
d1c7743
feat: conversation summarize
meta-d Dec 14, 2024
7f3e7c7
feat: long term memory
meta-d Dec 15, 2024
4eb5b4b
feat: feeback to summarize long-term memory
meta-d Dec 16, 2024
2bd4bc2
feat: fix agent primary
meta-d Dec 16, 2024
37eef2c
feat: xpert's memory page
meta-d Dec 17, 2024
8d7d0ff
feat: long term memory of xpert
meta-d Dec 17, 2024
2aa1b8a
feat: use long-term memory in chat
meta-d Dec 18, 2024
ff0cc77
feat: add findMyAll in curd service
meta-d Dec 18, 2024
6ab7736
feat: register user
meta-d Dec 18, 2024
b33162c
feat: long-term memory every user
meta-d Dec 18, 2024
2a97e95
feat: long-term memory
meta-d Dec 18, 2024
49b660e
feat: execution tools events
meta-d Dec 18, 2024
73561a6
feat: fix xpert memory
meta-d Dec 18, 2024
3431705
feat: semantic search for long-term store
meta-d Dec 19, 2024
8dd154f
feat: long-term trigger events
meta-d Dec 19, 2024
803fc7a
feat: memory profile
meta-d Dec 20, 2024
7756017
version 3.0.5
meta-d Dec 20, 2024
867226a
feat: update mysql client to 2
meta-d Dec 20, 2024
c90a8ff
feat: memory of xpert
meta-d Dec 20, 2024
6c0cc56
fix: null memory store
meta-d Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: long term memory
  • Loading branch information
meta-d committed Dec 15, 2024
commit 7f3e7c7459b158611cc09d3bb875449601a7b994
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<mat-slide-toggle [ngModel]="enabledSummarize()" (ngModelChange)="toggleSummarize($event)"
labelPosition="before"
ngm-density="xs"
ngm-density small
[matTooltip]="'PAC.Xpert.SensitiveAgentTip' | translate: {Default: 'Sensitive agents require user confirmation before execution'}"
matTooltipPosition="above"
/>
Expand All @@ -67,4 +67,38 @@
<xpert-studio-features-summary class="w-full px-3 mt-4"></xpert-studio-features-summary>
}
</div>

<div class="bg-gray-50 rounded-xl">
<div class="flex items-center px-3 h-12 overflow-hidden">
<div class="shrink-0 flex items-center justify-center mr-1 w-6 h-6">
<i class="ri-brain-fill shrink-0 text-lg text-lime-600"></i>
</div>
<div class="shrink-0 mr-2 whitespace-nowrap text-gray-800 font-semibold">Long-term Memory</div>
<div class="grow"></div>

<div class="flex items-center">
<button type="button" class="btn flex items-center h-8 rounded-lg"
[class.text-primary-500]="view() === 'memory' && enabledMemory()"
[disabled]="!enabledMemory()"
(click)="toggleView('memory')"
>
<i class="ri-settings-5-line text-lg"></i>
<div class="ml-1 leading-[18px] text-sm font-medium">Settings</div>
</button>
<div class="ml-4 mr-3 w-[1px] h-3.5 bg-gray-200"></div>

<mat-slide-toggle [ngModel]="enabledMemory()" (ngModelChange)="toggleMemory($event)"
labelPosition="before"
ngm-density small
[matTooltip]="'PAC.Xpert.SensitiveAgentTip' | translate: {Default: 'Sensitive agents require user confirmation before execution'}"
matTooltipPosition="above"
/>
</div>
</div>

@if (view() === 'memory' && enabledMemory()) {
<xpert-studio-features-memory class="w-full px-3 mt-4" />
}
</div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { TranslateModule } from '@ngx-translate/core'
import { XpertStudioFeaturesSummaryComponent } from './summary/summary.component'
import { XpertStudioApiService } from '../domain'
import { FormsModule } from '@angular/forms'
import { XpertStudioFeaturesMemoryComponent } from './memory/memory.component'
import { NgmDensityDirective } from '@metad/ocap-angular/core'


@Component({
Expand All @@ -21,7 +23,9 @@ import { FormsModule } from '@angular/forms'
TranslateModule,
MatSlideToggleModule,
MatTooltipModule,
XpertStudioFeaturesSummaryComponent
NgmDensityDirective,
XpertStudioFeaturesSummaryComponent,
XpertStudioFeaturesMemoryComponent
],
templateUrl: './features.component.html',
styleUrl: './features.component.scss',
Expand All @@ -31,16 +35,18 @@ export class XpertStudioFeaturesComponent {
readonly #dialogRef = inject(DialogRef)
readonly apiService = inject(XpertStudioApiService)

readonly view = signal<'summarize' | 'image_upload'>(null)
readonly view = signal<'summarize' | 'image_upload' | 'memory'>(null)
readonly xpert = this.apiService.xpert
readonly summarize = computed(() => this.xpert()?.summarize)
readonly enabledSummarize = computed(() => this.summarize()?.enabled)
readonly memory = computed(() => this.xpert()?.memory)
readonly enabledMemory = computed(() => this.memory()?.enabled)

close() {
this.#dialogRef.close()
}

toggleView(view: 'summarize' | 'image_upload') {
toggleView(view: 'summarize' | 'image_upload' | 'memory') {
this.view.update((state) => state === view ? null : view)
}

Expand All @@ -52,4 +58,13 @@ export class XpertStudioFeaturesComponent {
}
})
}

toggleMemory(enabled?: boolean) {
this.apiService._updateXpert({
memory: {
...(this.memory() ?? {}),
enabled,
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<copilot-prompt-editor class="relative shadow-md ngm-card-border-gradient self-stretch"
[tooltip]="'PAC.Xpert.SystemPromptTooltip' | translate: {Default: 'Prompts guide AI reponses with instructions and contraints. Insert parameters like {{input}}. This prompt won\'t be visible to users.'}"
[(prompt)]="prompt"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
@apply flex flex-col gap-4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { CdkMenuModule } from '@angular/cdk/menu'
import { CommonModule } from '@angular/common'
import { Component, computed, inject } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { MatSliderModule } from '@angular/material/slider'
import { MatTooltipModule } from '@angular/material/tooltip'
import { TLongTermMemory } from '@metad/contracts'
import { OverlayAnimations } from '@metad/core'
import { NgmDensityDirective } from '@metad/ocap-angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { XpertStudioApiService } from '../../domain'
import { CopilotPromptEditorComponent } from '../../../../../@shared/copilot'

@Component({
selector: 'xpert-studio-features-memory',
standalone: true,
imports: [
CommonModule,
FormsModule,
CdkMenuModule,
TranslateModule,
MatSliderModule,
MatTooltipModule,
NgmDensityDirective,

CopilotPromptEditorComponent
],
templateUrl: './memory.component.html',
styleUrl: './memory.component.scss',
animations: [...OverlayAnimations]
})
export class XpertStudioFeaturesMemoryComponent {
readonly apiService = inject(XpertStudioApiService)

readonly xpert = this.apiService.xpert
readonly memory = computed(() => this.xpert()?.memory)

get prompt() {
return this.memory()?.prompt
}
set prompt(value) {
this.updateMemory({ prompt: value })
}

updateMemory(memory: Partial<TLongTermMemory>) {
this.apiService.updateXpert((xpert) => {
return {
...xpert,
memory: {
...(xpert.memory ?? {}),
...memory
}
}
})
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common'
import { Component, computed, effect, input } from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { CopilotChatMessage } from 'apps/cloud/src/app/@core'
import { CopilotBaseMessage } from 'apps/cloud/src/app/@core'
import { MarkdownModule } from 'ngx-markdown'

@Component({
Expand All @@ -12,7 +12,7 @@ import { MarkdownModule } from 'ngx-markdown'
styleUrls: ['message.component.scss']
})
export class XpertPreviewAiMessageComponent {
readonly message = input<CopilotChatMessage>()
readonly message = input<CopilotBaseMessage>()

readonly contents = computed(() => {
if (typeof this.message()?.content === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
<div class="hidden group-hover:block h-[28px] p-0.5 rounded-lg bg-white border-[0.5px] border-gray-100 shadow-sm shrink-0">
<div class="shrink-0 p-1 flex items-center justify-center rounded-[6px] font-medium
bg-components-card-bg text-gray-500 hover:bg-gray-50 cursor-pointer hover:text-gray-700"
[matTooltip]="'Copy'"
matTooltipPosition="above"
(click)="copy(message)"
>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
Expand All @@ -101,7 +103,7 @@
</div>

@if (message.executionId) {
<div class="hidden group-hover:flex items-center w-max h-[28px] p-0.5 rounded-lg bg-white border-[0.5px] border-gray-100 shadow-sm shrink-0">
<div class="hidden group-hover:flex items-center w-max h-[28px] p-1 rounded-lg bg-white border-[0.5px] border-gray-100 shadow-sm shrink-0">
<div class="shrink-0 p-1 flex items-center justify-center rounded-[6px] font-medium text-gray-500 hover:bg-gray-50 cursor-pointer hover:text-gray-700"
(click)="openExecution(message)"
>
Expand All @@ -115,6 +117,21 @@
<div class="mx-1 w-[1px] h-[14px] bg-gray-200"></div>
</div>
}

<div class="hidden group-hover:flex shrink-0 items-center px-1 bg-white border-[0.5px] border-gray-100 shadow-md text-gray-500 rounded-lg">
<div class="flex items-center justify-center mr-0.5 w-6 h-6 rounded-md hover:bg-black/5 hover:text-gray-800 cursor-pointer"
[matTooltip]="'like'"
matTooltipPosition="above"
>
<i class="ri-thumb-up-line"></i>
</div>
<div class="flex items-center justify-center w-6 h-6 rounded-md hover:bg-black/5 hover:text-gray-800 cursor-pointer"
[matTooltip]="'dislike'"
matTooltipPosition="above"
>
<i class="ri-thumb-down-line"></i>
</div>
</div>
<!--
<div class="hidden group-hover:block h-[28px] p-0.5 rounded-lg bg-white border-[0.5px] border-gray-100 shadow-sm shrink-0">
<div class="box-border p-0.5 flex items-center justify-center rounded-md bg-white cursor-pointer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ChatConversationService,
ChatMessageEventTypeEnum,
ChatMessageTypeEnum,
CopilotBaseMessage,
CopilotChatMessage,
ToastrService,
uuid,
Expand Down Expand Up @@ -77,18 +78,18 @@ export class XpertStudioPreviewComponent {

readonly conversation = this.executionService.conversation

readonly currentMessage = signal<CopilotChatMessage>(null)
readonly currentMessage = signal<Partial<CopilotChatMessage>>(null)
readonly messages = computed<CopilotChatMessage[]>(() => {
if (this.currentMessage()) {
const messages = this.executionService.messages()
const lastMessage = messages[messages.length - 1]
// Skip the last interrupted message when continuing the chat conversation
if (lastMessage.status === XpertAgentExecutionStatusEnum.INTERRUPTED) {
return [...messages.slice(0, messages.length - 1), this.currentMessage()]
return [...messages.slice(0, messages.length - 1), this.currentMessage()] as CopilotChatMessage[]
}
return [...this.executionService.messages(), this.currentMessage()]
return [...this.executionService.messages(), this.currentMessage()] as CopilotChatMessage[]
}
return this.executionService.messages()
return this.executionService.messages() as CopilotChatMessage[]
})

readonly lastMessage = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class XpertExecutionService {

readonly conversation = signal<IChatConversation>(null)

readonly #messages = signal<CopilotChatMessage[]>([])
readonly #messages = signal<Partial<CopilotChatMessage>[]>([])

readonly messages = computed(() => {
const messages = this.conversation()?.messages
const messages = this.conversation()?._messages
if (messages) {
return [...messages.filter((_) => !this.#messages().some((m) => m.id === _.id)), ...this.#messages()]
}
Expand Down Expand Up @@ -53,7 +53,7 @@ export class XpertExecutionService {

// Subsribe conversation
private conversationSub = toObservable(this.conversationId).pipe(
switchMap((id) => id ? this.conversationService.getById(this.conversationId(), { relations: [] }) : of(null))
switchMap((id) => id ? this.conversationService.getById(this.conversationId(), { relations: ['_messages'] }) : of(null))
).subscribe((conv) => {
this.conversation.set(conv)
})
Expand All @@ -70,7 +70,7 @@ export class XpertExecutionService {
}, { allowSignalWrites: true })
}

appendMessage(message: CopilotChatMessage) {
appendMessage(message: Partial<CopilotChatMessage>) {
this.#messages.update(
(state) => {
const messages = state?.filter((_) => _.id !== message.id)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@foblex/utils": "^1.1.0",
"@langchain/community": "0.3.11",
"@langchain/core": "0.3.13",
"@langchain/langgraph": "0.2.17",
"@langchain/langgraph": "0.2.33",
"@langchain/ollama": "0.1.0",
"@langchain/openai": "0.3.11",
"@microsoft/fetch-event-source": "^2.0.1",
Expand Down
25 changes: 25 additions & 0 deletions packages/contracts/src/ai/chat-message-feedback.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model'
import { IChatMessage } from './chat-message.model'
import { IChatConversation } from './chat.model'

/**
*
*/
export interface IChatMessageFeedback extends IBasePerTenantAndOrganizationEntityModel {

rating: string

content?: string

// Many to one
/**
* Chat conversation
*/
conversation?: IChatConversation
conversationId?: string | null
/**
* Chat conversation message
*/
message?: IChatMessage
messageId?: string | null
}
17 changes: 17 additions & 0 deletions packages/contracts/src/ai/chat-message.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model'
import { CopilotBaseMessage, IChatConversation } from './chat.model'

/**
*
*/
export interface IChatMessage extends IBasePerTenantAndOrganizationEntityModel, Omit<Omit<CopilotBaseMessage, 'createdAt'>, 'id'> {

// Many to one
/**
* Chat conversation
*/
conversation?: IChatConversation
conversationId?: string | null

executionId?: string
}
4 changes: 3 additions & 1 deletion packages/contracts/src/ai/chat.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { JSONValue } from '../core.model'
import { IXpertAgentExecution, XpertAgentExecutionStatusEnum } from './xpert-agent-execution.model'
import { IXpert } from './xpert.model'
import { I18nObject } from '../types'
import { IChatMessage } from './chat-message.model'

export type TChatConversationOptions = {
knowledgebases?: string[]
Expand Down Expand Up @@ -46,7 +47,8 @@ export interface IChatConversation extends IBasePerTenantAndOrganizationEntityMo

options?: TChatConversationOptions

messages?: CopilotBaseMessage[] | null
messages?: CopilotBaseMessage[]
_messages?: IChatMessage[] | null
/**
* The last operation when interrupted
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/contracts/src/ai/copilot-store.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model'

export interface ICopilotStore extends TCopilotStore, IBasePerTenantAndOrganizationEntityModel {}

export interface ICopilotStoreVector extends TCopilotStoreVector, IBasePerTenantAndOrganizationEntityModel {
}

export type TCopilotStore = {
prefix: string
key: string
value: any
}

export type TCopilotStoreVector = {
prefix: string
key: string
field_name: any
embedding: string
}
Loading