refactor: rename conversation to messages
This commit is contained in:
parent
15d6686bf5
commit
9212b56cdf
@ -53,14 +53,22 @@ const AppsPage: FC = () => {
|
||||
<Title level={5} style={{ marginBottom: 0, color: '#00b96b' }}>
|
||||
{assistant.name}
|
||||
</Title>
|
||||
{added && <Button type="primary" shape="circle" size="small" icon={<CheckOutlined />} />}
|
||||
{added && (
|
||||
<Button
|
||||
type="primary"
|
||||
shape="circle"
|
||||
size="small"
|
||||
icon={<CheckOutlined style={{ fontSize: 12 }} />}
|
||||
/>
|
||||
)}
|
||||
{!added && (
|
||||
<Tooltip placement="top" title=" Add to assistant list " arrow>
|
||||
<Button
|
||||
type="default"
|
||||
shape="circle"
|
||||
size="small"
|
||||
icon={<PlusOutlined />}
|
||||
style={{ padding: 0 }}
|
||||
icon={<PlusOutlined style={{ fontSize: 12 }} />}
|
||||
onClick={() => onAddAssistant(assistant)}
|
||||
/>
|
||||
</Tooltip>
|
||||
|
||||
@ -2,7 +2,7 @@ import { Assistant } from '@renderer/types'
|
||||
import { FC } from 'react'
|
||||
import styled from 'styled-components'
|
||||
import Inputbar from './Inputbar'
|
||||
import Conversations from './Conversations'
|
||||
import Messages from './Messages'
|
||||
import { Flex } from 'antd'
|
||||
import TopicList from './TopicList'
|
||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||
@ -23,7 +23,7 @@ const Chat: FC<Props> = (props) => {
|
||||
return (
|
||||
<Container id="chat">
|
||||
<Flex vertical flex={1} justify="space-between">
|
||||
<Conversations assistant={assistant} topic={activeTopic} />
|
||||
<Messages assistant={assistant} topic={activeTopic} />
|
||||
<Inputbar assistant={assistant} setActiveTopic={setActiveTopic} />
|
||||
</Flex>
|
||||
<TopicList assistant={assistant} activeTopic={activeTopic} setActiveTopic={setActiveTopic} />
|
||||
|
||||
@ -52,7 +52,7 @@ const Inputbar: FC<Props> = ({ assistant, setActiveTopic }) => {
|
||||
}, [addTopic, setActiveTopic])
|
||||
|
||||
const clearTopic = () => {
|
||||
EventEmitter.emit(EVENT_NAMES.CLEAR_CONVERSATION)
|
||||
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES)
|
||||
}
|
||||
|
||||
// Command or Ctrl + N create new topic
|
||||
|
||||
@ -6,7 +6,7 @@ import styled from 'styled-components'
|
||||
import MessageItem from './Message'
|
||||
import { reverse } from 'lodash'
|
||||
import hljs from 'highlight.js'
|
||||
import { fetchChatCompletion, fetchConversationSummary } from '@renderer/services/api'
|
||||
import { fetchChatCompletion, fetchMessagesSummary } from '@renderer/services/api'
|
||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||
import { DEFAULT_TOPIC_NAME } from '@renderer/config/constant'
|
||||
import { runAsyncFunction } from '@renderer/utils'
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
topic: Topic
|
||||
}
|
||||
|
||||
const Conversations: FC<Props> = ({ assistant, topic }) => {
|
||||
const Messages: FC<Props> = ({ assistant, topic }) => {
|
||||
const [messages, setMessages] = useState<Message[]>([])
|
||||
const [lastMessage, setLastMessage] = useState<Message | null>(null)
|
||||
const { updateTopic } = useAssistant(assistant.id)
|
||||
@ -47,7 +47,7 @@ const Conversations: FC<Props> = ({ assistant, topic }) => {
|
||||
|
||||
const autoRenameTopic = useCallback(async () => {
|
||||
if (topic.name === DEFAULT_TOPIC_NAME && messages.length >= 2) {
|
||||
const summaryText = await fetchConversationSummary({ messages, assistant })
|
||||
const summaryText = await fetchMessagesSummary({ messages, assistant })
|
||||
summaryText && updateTopic({ ...topic, name: summaryText })
|
||||
}
|
||||
}, [assistant, messages, topic, updateTopic])
|
||||
@ -65,7 +65,7 @@ const Conversations: FC<Props> = ({ assistant, topic }) => {
|
||||
setTimeout(() => EventEmitter.emit(EVENT_NAMES.AI_AUTO_RENAME), 100)
|
||||
}),
|
||||
EventEmitter.on(EVENT_NAMES.AI_AUTO_RENAME, autoRenameTopic),
|
||||
EventEmitter.on(EVENT_NAMES.CLEAR_CONVERSATION, () => {
|
||||
EventEmitter.on(EVENT_NAMES.CLEAR_MESSAGES, () => {
|
||||
setMessages([])
|
||||
updateTopic({ ...topic, messages: [] })
|
||||
LocalStorage.clearTopicMessages(topic.id)
|
||||
@ -105,4 +105,4 @@ const Container = styled.div`
|
||||
}
|
||||
`
|
||||
|
||||
export default Conversations
|
||||
export default Messages
|
||||
@ -1,7 +1,7 @@
|
||||
import PromptPopup from '@renderer/components/Popups/PromptPopup'
|
||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||
import { useShowRightSidebar } from '@renderer/hooks/useStore'
|
||||
import { fetchConversationSummary } from '@renderer/services/api'
|
||||
import { fetchMessagesSummary } from '@renderer/services/api'
|
||||
import { Assistant, Topic } from '@renderer/types'
|
||||
import { Button, Dropdown, MenuProps, Popconfirm } from 'antd'
|
||||
import { FC, useRef } from 'react'
|
||||
@ -29,7 +29,7 @@ const TopicList: FC<Props> = ({ assistant, activeTopic, setActiveTopic }) => {
|
||||
if (currentTopic.current) {
|
||||
const messages = await LocalStorage.getTopicMessages(currentTopic.current.id)
|
||||
if (messages.length >= 2) {
|
||||
const summaryText = await fetchConversationSummary({ messages, assistant })
|
||||
const summaryText = await fetchMessagesSummary({ messages, assistant })
|
||||
if (summaryText) {
|
||||
updateTopic({ ...currentTopic.current, name: summaryText })
|
||||
}
|
||||
@ -124,6 +124,9 @@ const TopicListItem = styled.div`
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
&:hover {
|
||||
background-color: var(--color-background-soft);
|
||||
}
|
||||
|
||||
@ -58,12 +58,12 @@ export async function fetchChatCompletion({ message, topic, assistant, onRespons
|
||||
return _message
|
||||
}
|
||||
|
||||
interface FetchConversationSummaryParams {
|
||||
interface FetchMessagesSummaryParams {
|
||||
messages: Message[]
|
||||
assistant: Assistant
|
||||
}
|
||||
|
||||
export async function fetchConversationSummary({ messages, assistant }: FetchConversationSummaryParams) {
|
||||
export async function fetchMessagesSummary({ messages, assistant }: FetchMessagesSummaryParams) {
|
||||
const provider = getAssistantProvider(assistant)
|
||||
const openaiProvider = getOpenAiProvider(provider)
|
||||
const defaultModel = getDefaultModel()
|
||||
|
||||
@ -6,7 +6,7 @@ export function getDefaultAssistant(): Assistant {
|
||||
return {
|
||||
id: 'default',
|
||||
name: 'Default Assistant',
|
||||
description: "Hello, I'm Default Assistant.",
|
||||
description: "Hello, I'm Default Assistant. You can start chatting with me right away",
|
||||
prompt: '',
|
||||
topics: [getDefaultTopic()]
|
||||
}
|
||||
|
||||
@ -6,6 +6,6 @@ export const EVENT_NAMES = {
|
||||
SEND_MESSAGE: 'SEND_MESSAGE',
|
||||
AI_CHAT_COMPLETION: 'AI_CHAT_COMPLETION',
|
||||
AI_AUTO_RENAME: 'AI_AUTO_RENAME',
|
||||
CLEAR_CONVERSATION: 'CLEAR_CONVERSATION',
|
||||
CLEAR_MESSAGES: 'CLEAR_MESSAGES',
|
||||
ADD_ASSISTANT: 'ADD_ASSISTANT'
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user