♻️ refactor: refactor prompts folder to the @lobechat/prompts pacakge (#8810)

* move prompts

* refactor prompts
This commit is contained in:
Arvin Xu
2025-08-17 00:10:28 +08:00
committed by GitHub
parent 3fbbfc6d96
commit d82e7bb9b0
26 changed files with 38 additions and 22 deletions
+1
View File
@@ -145,6 +145,7 @@
"@lobechat/electron-server-ipc": "workspace:*",
"@lobechat/file-loaders": "workspace:*",
"@lobechat/model-runtime": "workspace:*",
"@lobechat/prompts": "workspace:*",
"@lobechat/web-crawler": "workspace:*",
"@lobehub/analytics": "^1.6.0",
"@lobehub/charts": "^2.0.0",
+9
View File
@@ -0,0 +1,9 @@
{
"name": "@lobechat/prompts",
"version": "1.0.0",
"private": true,
"main": "./src/index.ts",
"dependencies": {
"@lobechat/types": "workspace:*"
}
}
@@ -1,7 +1,6 @@
import { ChatMessage } from '@lobechat/types';
import { describe, expect, it } from 'vitest';
import { ChatMessage } from '@/types/message';
import { chatHistoryPrompts } from './index';
describe('chatHistoryPrompts', () => {
@@ -1,4 +1,4 @@
import { ChatMessage } from '@/types/message';
import { ChatMessage } from '@lobechat/types';
const chatMessage = (message: ChatMessage) => {
return `<${message.role}>${message.content}</${message.role}>`;
@@ -1,4 +1,4 @@
import { ChatFileItem } from '@/types/message';
import { ChatFileItem } from '@lobechat/types';
const filePrompt = (item: ChatFileItem, addUrl: boolean) => {
const content = item.content || '';
@@ -1,4 +1,4 @@
import { ChatImageItem } from '@/types/message';
import { ChatImageItem } from '@lobechat/types';
const imagePrompt = (item: ChatImageItem, attachUrl: boolean) =>
attachUrl
@@ -1,4 +1,4 @@
import { ChatFileItem, ChatImageItem } from '@/types/message';
import { ChatFileItem, ChatImageItem } from '@lobechat/types';
import { filePrompts } from './file';
import { imagesPrompts } from './image';
+5
View File
@@ -0,0 +1,5 @@
export * from './chatMessages';
export * from './files';
export * from './knowledgeBaseQA';
export * from './plugin';
export * from './systemRole';
@@ -1,4 +1,4 @@
import { ChatSemanticSearchChunk } from '@/types/chunk';
import { ChatSemanticSearchChunk } from '@lobechat/types';
const chunkPrompt = (item: ChatSemanticSearchChunk) =>
`<chunk fileId="${item.fileId}" fileName="${item.fileName}" similarity="${item.similarity}" ${item.pageNumber ? ` pageNumber="${item.pageNumber}" ` : ''}>${item.text}</chunk>`;
@@ -1,8 +1,8 @@
import { chunkPrompts } from '@/prompts/knowledgeBaseQA/chunk';
import { knowledgePrompts } from '@/prompts/knowledgeBaseQA/knowledge';
import { userQueryPrompt } from '@/prompts/knowledgeBaseQA/userQuery';
import { ChatSemanticSearchChunk } from '@/types/chunk';
import { KnowledgeItem } from '@/types/knowledgeBase';
import { ChatSemanticSearchChunk, KnowledgeItem } from '@lobechat/types';
import { chunkPrompts } from './chunk';
import { knowledgePrompts } from './knowledge';
import { userQueryPrompt } from './userQuery';
export const knowledgeBaseQAPrompts = ({
chunks,
@@ -1,4 +1,4 @@
import { KnowledgeItem } from '@/types/knowledgeBase';
import { KnowledgeItem } from '@lobechat/types';
const knowledgePrompt = (item: KnowledgeItem) =>
`<knowledge id="${item.id}" name="${item.name}" type="${item.type}"${item.fileType ? ` fileType="${item.fileType}" ` : ''}>${item.description || ''}</knowledge>`;
@@ -1,6 +1,5 @@
import { Tool } from '@/prompts/plugin/tools';
import { pluginPrompts } from './index';
import { Tool } from './tools';
describe('pluginPrompts', () => {
it('should generate plugin prompts with tools', () => {
+3
View File
@@ -1,3 +1,6 @@
export * from './artifact';
export * from './chunk';
export * from './fetch';
export * from './knowledgeBase';
export * from './message';
export * from './trace';
+1 -1
View File
@@ -1,4 +1,4 @@
import { UploadFileItem } from '@/types/files';
import { UploadFileItem } from '../files';
export * from './base';
export * from './chat';
+3 -2
View File
@@ -1,5 +1,6 @@
import { chatHistoryPrompts } from '@/prompts/chatMessages';
import { ChatMessage } from '@/types/message';
import { chatHistoryPrompts } from '@lobechat/prompts';
import { ChatMessage } from '@lobechat/types';
import { ChatStreamPayload } from '@/types/openai/chat';
export const chainSummaryHistory = (messages: ChatMessage[]): Partial<ChatStreamPayload> => ({
+1 -2
View File
@@ -4,6 +4,7 @@ import {
ModelProvider,
ModelRuntime,
} from '@lobechat/model-runtime';
import { BuiltinSystemRolePrompts, filesPrompts } from '@lobechat/prompts';
import { ChatErrorType, TracePayload, TraceTagMap } from '@lobechat/types';
import { PluginRequestPayload, createHeadersWithPluginSettings } from '@lobehub/chat-plugin-sdk';
import { produce } from 'immer';
@@ -15,8 +16,6 @@ import { INBOX_SESSION_ID } from '@/const/session';
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
import { isDeprecatedEdition, isDesktop, isServerMode } from '@/const/version';
import { parseDataUri } from '@/libs/model-runtime/utils/uriParser';
import { filesPrompts } from '@/prompts/files';
import { BuiltinSystemRolePrompts } from '@/prompts/systemRole';
import { getAgentStoreState } from '@/store/agent';
import { agentChatConfigSelectors } from '@/store/agent/selectors';
import { aiModelSelectors, aiProviderSelectors, getAiInfraStoreState } from '@/store/aiInfra';
@@ -1,5 +1,6 @@
/* eslint-disable sort-keys-fix/sort-keys-fix, typescript-sort-keys/interface */
// Disable the auto sort key eslint rule to make the code more logic and readable
import { knowledgeBaseQAPrompts } from '@lobechat/prompts';
import { TraceEventType, TraceNameMap } from '@lobechat/types';
import { t } from 'i18next';
import { produce } from 'immer';
@@ -8,7 +9,6 @@ import { StateCreator } from 'zustand/vanilla';
import { LOADING_FLAT, MESSAGE_CANCEL_FLAT } from '@/const/message';
import { isDesktop, isServerMode } from '@/const/version';
import { knowledgeBaseQAPrompts } from '@/prompts/knowledgeBaseQA';
import { chatService } from '@/services/chat';
import { messageService } from '@/services/message';
import { useAgentStore } from '@/store/agent';
+1 -1
View File
@@ -1,6 +1,6 @@
import { pluginPrompts } from '@lobechat/prompts';
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
import { pluginPrompts } from '@/prompts/plugin';
import { MetaData } from '@/types/meta';
import { ChatCompletionTool } from '@/types/openai/chat';
import { LobeToolMeta } from '@/types/tool/tool';