Browse Source

情绪大模型取消对话数限制,并且查询同一只股票不再去重;

dev
宋杰 2 days ago
parent
commit
7f5d3ce5a6
  1. 35
      src/store/emotion.ts

35
src/store/emotion.ts

@ -6,9 +6,7 @@ export const useEmotionStore = defineStore('emotion', {
history: [] as HistoryItem[], // 历史记录数组
stockList: [] as StockData[], // 当前显示的股票列表
activeStockIndex: 0, // 当前激活的股票索引
maxStocks: 10, // 最大股票数量限制
conversations: [] as ConversationMessage[], // 对话消息数组
maxConversations: 100, // 最大对话数量限制
}),
persist: {
key: 'emotion-store',
@ -22,12 +20,8 @@ export const useEmotionStore = defineStore('emotion', {
},
// 获取股票数量
stockCount: (state) => state.stockList.length,
// 是否达到最大股票数量
isMaxStocks: (state) => state.stockList.length >= state.maxStocks,
// 获取对话数量
conversationCount: (state) => state.conversations.length,
// 是否达到最大对话数量
isMaxConversations: (state) => state.conversations.length >= state.maxConversations,
// 获取最近的对话消息
recentConversations: (state) => {
return state.conversations.slice(-20); // 返回最近20条对话
@ -44,28 +38,9 @@ export const useEmotionStore = defineStore('emotion', {
},
// 添加新股票
addStock(stockData: StockData) {
// 检查是否已存在相同的股票
const existingIndex = this.stockList.findIndex(
stock => stock.stockInfo.code === stockData.stockInfo.code &&
stock.stockInfo.market === stockData.stockInfo.market
);
if (existingIndex !== -1) {
// 如果股票已存在,更新数据并切换到该股票
this.stockList[existingIndex] = stockData;
this.activeStockIndex = existingIndex;
} else {
// 如果达到最大数量,移除最旧的股票
if (this.stockList.length >= this.maxStocks) {
this.stockList.shift();
if (this.activeStockIndex > 0) {
this.activeStockIndex--;
}
}
// 添加新股票并设为当前激活
this.stockList.push(stockData);
this.activeStockIndex = this.stockList.length - 1;
}
// 添加新股票并设为当前激活
this.stockList.push(stockData);
this.activeStockIndex = this.stockList.length - 1;
// 同时添加到历史记录
// this.addHistory({
@ -130,10 +105,6 @@ export const useEmotionStore = defineStore('emotion', {
},
// 添加对话消息
addConversation(message: ConversationMessage) {
// 如果达到最大数量,移除最旧的消息
if (this.conversations.length >= this.maxConversations) {
this.conversations.shift();
}
// 添加新消息到数组末尾
this.conversations.push({
...message,

Loading…
Cancel
Save