Commit e061d6a6 authored by Joel's avatar Joel

mrege

parents 54999264 a3638d4b
...@@ -95,6 +95,7 @@ class CompletionConversationApi(Resource): ...@@ -95,6 +95,7 @@ class CompletionConversationApi(Resource):
'status': fields.String, 'status': fields.String,
'from_source': fields.String, 'from_source': fields.String,
'from_end_user_id': fields.String, 'from_end_user_id': fields.String,
'from_end_user_session_id': fields.String(attribute='end_user.session_id'),
'from_account_id': fields.String, 'from_account_id': fields.String,
'read_at': TimestampField, 'read_at': TimestampField,
'created_at': TimestampField, 'created_at': TimestampField,
...@@ -135,6 +136,8 @@ class CompletionConversationApi(Resource): ...@@ -135,6 +136,8 @@ class CompletionConversationApi(Resource):
query = db.select(Conversation).where(Conversation.app_id == app.id, Conversation.mode == 'completion') query = db.select(Conversation).where(Conversation.app_id == app.id, Conversation.mode == 'completion')
query = query.options(joinedload(Conversation.end_user))
if args['keyword']: if args['keyword']:
query = query.join( query = query.join(
Message, Message.conversation_id == Conversation.id Message, Message.conversation_id == Conversation.id
...@@ -246,6 +249,7 @@ class ChatConversationApi(Resource): ...@@ -246,6 +249,7 @@ class ChatConversationApi(Resource):
'status': fields.String, 'status': fields.String,
'from_source': fields.String, 'from_source': fields.String,
'from_end_user_id': fields.String, 'from_end_user_id': fields.String,
'from_end_user_session_id': fields.String(attribute='end_user.session_id'),
'from_account_id': fields.String, 'from_account_id': fields.String,
'summary': fields.String(attribute='summary_or_query'), 'summary': fields.String(attribute='summary_or_query'),
'read_at': TimestampField, 'read_at': TimestampField,
...@@ -288,6 +292,8 @@ class ChatConversationApi(Resource): ...@@ -288,6 +292,8 @@ class ChatConversationApi(Resource):
query = db.select(Conversation).where(Conversation.app_id == app.id, Conversation.mode == 'chat') query = db.select(Conversation).where(Conversation.app_id == app.id, Conversation.mode == 'chat')
query = query.options(joinedload(Conversation.end_user))
if args['keyword']: if args['keyword']:
query = query.join( query = query.join(
Message, Message.conversation_id == Conversation.id Message, Message.conversation_id == Conversation.id
......
...@@ -226,7 +226,7 @@ class Conversation(db.Model): ...@@ -226,7 +226,7 @@ class Conversation(db.Model):
system_instruction_tokens = db.Column(db.Integer, nullable=False, server_default=db.text('0')) system_instruction_tokens = db.Column(db.Integer, nullable=False, server_default=db.text('0'))
status = db.Column(db.String(255), nullable=False) status = db.Column(db.String(255), nullable=False)
from_source = db.Column(db.String(255), nullable=False) from_source = db.Column(db.String(255), nullable=False)
from_end_user_id = db.Column(UUID) from_end_user_id = db.Column(UUID, db.ForeignKey('end_users.id'))
from_account_id = db.Column(UUID) from_account_id = db.Column(UUID)
read_at = db.Column(db.DateTime) read_at = db.Column(db.DateTime)
read_account_id = db.Column(UUID) read_account_id = db.Column(UUID)
...@@ -236,6 +236,8 @@ class Conversation(db.Model): ...@@ -236,6 +236,8 @@ class Conversation(db.Model):
messages = db.relationship("Message", backref="conversation", lazy='select', passive_deletes="all") messages = db.relationship("Message", backref="conversation", lazy='select', passive_deletes="all")
message_annotations = db.relationship("MessageAnnotation", backref="conversation", lazy='select', passive_deletes="all") message_annotations = db.relationship("MessageAnnotation", backref="conversation", lazy='select', passive_deletes="all")
end_user = db.relationship("EndUser", backref="conversations")
is_deleted = db.Column(db.Boolean, nullable=False, server_default=db.text('false')) is_deleted = db.Column(db.Boolean, nullable=False, server_default=db.text('false'))
@property @property
......
...@@ -45,8 +45,12 @@ const Thought: FC<IThoughtProps> = ({ ...@@ -45,8 +45,12 @@ const Thought: FC<IThoughtProps> = ({
return t('explore.universalChat.thought.res.dataset').replace('{datasetName}', `<span class="text-gray-700">${datasetName}</span>`) return t('explore.universalChat.thought.res.dataset').replace('{datasetName}', `<span class="text-gray-700">${datasetName}</span>`)
case 'web_reader': case 'web_reader':
return t(`explore.universalChat.thought.res.webReader.${!input.cursor ? 'normal' : 'hasPageInfo'}`).replace('{url}', `<a href="${input.url}" class="text-[#155EEF]">${input.url}</a>`) return t(`explore.universalChat.thought.res.webReader.${!input.cursor ? 'normal' : 'hasPageInfo'}`).replace('{url}', `<a href="${input.url}" class="text-[#155EEF]">${input.url}</a>`)
default: // google, wikipedia case 'google_search':
return t('explore.universalChat.thought.res.search', { query: input.query }) return t('explore.universalChat.thought.res.google', { query: input.query })
case 'wikipedia':
return t('explore.universalChat.thought.res.wikipedia', { query: input.query })
default:
return `Unknown tool: ${item.tool}`
} }
} }
catch (error) { catch (error) {
......
...@@ -412,7 +412,7 @@ const ConversationList: FC<IConversationList> = ({ logs, appDetail, onRefresh }) ...@@ -412,7 +412,7 @@ const ConversationList: FC<IConversationList> = ({ logs, appDetail, onRefresh })
</thead> </thead>
<tbody className="text-gray-500"> <tbody className="text-gray-500">
{logs.data.map((log) => { {logs.data.map((log) => {
const endUser = log.from_end_user_id?.slice(0, 8) const endUser = log.from_end_user_session_id
const leftValue = get(log, isChatMode ? 'summary' : 'message.query') const leftValue = get(log, isChatMode ? 'summary' : 'message.query')
const rightValue = get(log, isChatMode ? 'message_count' : 'message.answer') const rightValue = get(log, isChatMode ? 'message_count' : 'message.answer')
return <tr return <tr
......
...@@ -47,6 +47,28 @@ const DEFAULT_PLUGIN = { ...@@ -47,6 +47,28 @@ const DEFAULT_PLUGIN = {
web_reader: true, web_reader: true,
wikipedia: true, wikipedia: true,
} }
const CONFIG_KEY = 'universal-chat-config'
type CONFIG = {
modelId: string
plugin: {
google_search: boolean
web_reader: boolean
wikipedia: boolean
}
}
let prevConfig: null | CONFIG = localStorage.getItem(CONFIG_KEY) ? JSON.parse(localStorage.getItem(CONFIG_KEY) as string) as CONFIG : null
const setPrevConfig = (config: CONFIG) => {
prevConfig = config
localStorage.setItem(CONFIG_KEY, JSON.stringify(prevConfig))
}
const getInitConfig = (type: 'model' | 'plugin') => {
if (type === 'model')
return prevConfig?.modelId || DEFAULT_MODEL_ID
if (type === 'plugin')
return prevConfig?.plugin || DEFAULT_PLUGIN
}
export type IMainProps = {} export type IMainProps = {}
const Main: FC<IMainProps> = () => { const Main: FC<IMainProps> = () => {
...@@ -415,6 +437,13 @@ const Main: FC<IMainProps> = () => { ...@@ -415,6 +437,13 @@ const Main: FC<IMainProps> = () => {
const [errorHappened, setErrorHappened] = useState(false) const [errorHappened, setErrorHappened] = useState(false)
const [isResponsingConIsCurrCon, setIsResponsingConCurrCon, getIsResponsingConIsCurrCon] = useGetState(true) const [isResponsingConIsCurrCon, setIsResponsingConCurrCon, getIsResponsingConIsCurrCon] = useGetState(true)
const handleSend = async (message: string) => { const handleSend = async (message: string) => {
if (isNewConversation) {
setPrevConfig({
modelId,
plugin: plugins as any,
})
}
if (isResponsing) { if (isResponsing) {
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') }) notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
return return
...@@ -598,10 +627,10 @@ const Main: FC<IMainProps> = () => { ...@@ -598,10 +627,10 @@ const Main: FC<IMainProps> = () => {
) )
} }
const [modelId, setModeId] = useState(DEFAULT_MODEL_ID) const [modelId, setModeId] = useState<string>(getInitConfig('model') as string)
// const currModel = MODEL_LIST.find(item => item.id === modelId) // const currModel = MODEL_LIST.find(item => item.id === modelId)
const [plugins, setPlugins] = useState<Record<string, boolean>>(DEFAULT_PLUGIN) const [plugins, setPlugins] = useState<Record<string, boolean>>(getInitConfig('plugin') as Record<string, boolean>)
const handlePluginsChange = (key: string, value: boolean) => { const handlePluginsChange = (key: string, value: boolean) => {
setPlugins({ setPlugins({
...plugins, ...plugins,
...@@ -610,8 +639,8 @@ const Main: FC<IMainProps> = () => { ...@@ -610,8 +639,8 @@ const Main: FC<IMainProps> = () => {
} }
const [dataSets, setDateSets] = useState<DataSet[]>([]) const [dataSets, setDateSets] = useState<DataSet[]>([])
const configSetDefaultValue = () => { const configSetDefaultValue = () => {
setModeId(DEFAULT_MODEL_ID) setModeId(getInitConfig('model') as string)
setPlugins(DEFAULT_PLUGIN) setPlugins(getInitConfig('plugin') as any)
setDateSets([]) setDateSets([])
} }
const isCurrConversationPinned = !!pinnedConversationList.find(item => item.id === currConversationId) const isCurrConversationPinned = !!pinnedConversationList.find(item => item.id === currConversationId)
......
...@@ -66,7 +66,8 @@ const translation = { ...@@ -66,7 +66,8 @@ const translation = {
normal: 'Reading {url}', normal: 'Reading {url}',
hasPageInfo: 'Reading next page of {url}', hasPageInfo: 'Reading next page of {url}',
}, },
search: 'Searching {{query}}', google: 'Searching Google {{query}}',
wikipedia: 'Searching Wikipedia {{query}}',
dataset: 'Retrieving dataset {datasetName}', dataset: 'Retrieving dataset {datasetName}',
}, },
}, },
......
...@@ -66,7 +66,8 @@ const translation = { ...@@ -66,7 +66,8 @@ const translation = {
normal: '解析链接 {url}', normal: '解析链接 {url}',
hasPageInfo: '解析链接 {url} 的下一页', hasPageInfo: '解析链接 {url} 的下一页',
}, },
search: '搜索 {{query}}', google: '搜索谷歌 {{query}}',
wikipedia: '搜索维基百科 {{query}}',
dataset: '检索数据集 {datasetName}', dataset: '检索数据集 {datasetName}',
}, },
}, },
......
...@@ -79,6 +79,7 @@ export type CompletionConversationGeneralDetail = { ...@@ -79,6 +79,7 @@ export type CompletionConversationGeneralDetail = {
status: 'normal' | 'finished' status: 'normal' | 'finished'
from_source: 'api' | 'console' from_source: 'api' | 'console'
from_end_user_id: string from_end_user_id: string
from_end_user_session_id: string
from_account_id: string from_account_id: string
read_at: Date read_at: Date
created_at: number created_at: number
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment