-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from meta-d/develop
Version 2.5 ChatBI
- Loading branch information
Showing
313 changed files
with
13,949 additions
and
12,375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { inject } from '@angular/core' | ||
import { ExampleVectorStoreRetrieverInput, NgmCopilotService } from '@metad/copilot-angular' | ||
import { CopilotExampleService } from '../services/copilot-example.service' | ||
import { ExampleVectorStoreRetriever } from './example-vector-retriever' | ||
|
||
export function injectExampleRetriever(command: string, fields?: ExampleVectorStoreRetrieverInput) { | ||
const copilotService = inject(NgmCopilotService) | ||
const copilotExampleService = inject(CopilotExampleService) | ||
|
||
return new ExampleVectorStoreRetriever( | ||
{ | ||
...(fields ?? { vectorStore: null }), | ||
vectorStore: null, | ||
command, | ||
role: copilotService.role | ||
}, | ||
copilotExampleService | ||
) | ||
} |
79 changes: 79 additions & 0 deletions
79
apps/cloud/src/app/@core/services/chatbi-conversation.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { HttpClient } from '@angular/common/http' | ||
import { inject, Injectable } from '@angular/core' | ||
import { API_PREFIX, SystemPrivacyFields } from '@metad/cloud/state' | ||
import { CopilotChatMessage } from '@metad/copilot' | ||
import { Indicator } from '@metad/ocap-core' | ||
import { omit } from 'lodash-es' | ||
import { NGXLogger } from 'ngx-logger' | ||
import { BehaviorSubject, map } from 'rxjs' | ||
import { IChatBIConversation } from '../types' | ||
|
||
const API_CHATBI_CONVERSATION = API_PREFIX + '/chatbi-conversation' | ||
|
||
export interface ChatbiConverstion { | ||
id?: string | ||
key: string | ||
name: string | ||
modelId: string | ||
dataSource: string | ||
entity: string | ||
command: string | ||
messages: CopilotChatMessage[] | ||
indicators: Indicator[] | ||
} | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ChatBIConversationService { | ||
readonly #logger = inject(NGXLogger) | ||
readonly httpClient = inject(HttpClient) | ||
|
||
readonly #refresh = new BehaviorSubject<void>(null) | ||
|
||
getMy() { | ||
return this.httpClient | ||
.get<{ items: IChatBIConversation[] }>(API_CHATBI_CONVERSATION + '/my') | ||
.pipe(map(({ items }) => items.map(convertChatBIConversationResult))) | ||
} | ||
|
||
getById(id: string) { | ||
return this.httpClient | ||
.get<IChatBIConversation>(API_CHATBI_CONVERSATION + '/' + id) | ||
.pipe(map(convertChatBIConversationResult)) | ||
} | ||
|
||
upsert(entity: Partial<ChatbiConverstion>) { | ||
return entity.id | ||
? this.httpClient | ||
.put<ChatbiConverstion>(`${API_CHATBI_CONVERSATION}/${entity.id}`, convertChatBIConversation(entity)) | ||
.pipe(map(() => entity as ChatbiConverstion)) | ||
: this.httpClient | ||
.post<ChatbiConverstion>(API_CHATBI_CONVERSATION, convertChatBIConversation(entity)) | ||
.pipe(map((result) => convertChatBIConversationResult(result))) | ||
} | ||
|
||
delete(id: string) { | ||
return this.httpClient.delete(`${API_CHATBI_CONVERSATION}/${id}`) | ||
} | ||
|
||
refresh() { | ||
this.#refresh.next() | ||
} | ||
} | ||
|
||
export function convertChatBIConversation(input: Partial<ChatbiConverstion>) { | ||
return { | ||
...omit(input, 'messages', 'indicators'), | ||
options: { | ||
messages: input.messages, | ||
indicators: input.indicators, | ||
} | ||
} as IChatBIConversation | ||
} | ||
|
||
export function convertChatBIConversationResult(result: IChatBIConversation) { | ||
return { | ||
...omit(result, 'options', ...SystemPrivacyFields), | ||
messages: result.options?.messages || [], | ||
indicators: result.options?.indicators | ||
} as ChatbiConverstion | ||
} |
Oops, something went wrong.