11import { defineStore } from 'pinia'
22import { getLocalState , setLocalState } from './helper'
3+ import { useUserStore } from '@/store'
34import { router } from '@/router'
4- import { fetchClearChat , fetchCreateChatRoom , fetchDeleteChat , fetchDeleteChatRoom , fetchGetChatHistory , fetchGetChatRooms , fetchRenameChatRoom , fetchUpdateChatRoomUsingContext } from '@/api'
5+ import {
6+ fetchClearChat ,
7+ fetchCreateChatRoom ,
8+ fetchDeleteChat ,
9+ fetchDeleteChatRoom ,
10+ fetchGetChatHistory ,
11+ fetchGetChatRooms ,
12+ fetchRenameChatRoom ,
13+ fetchUpdateChatRoomChatModel ,
14+ fetchUpdateChatRoomUsingContext ,
15+ } from '@/api'
516
617export const useChatStore = defineStore ( 'chat-store' , {
718 state : ( ) : Chat . ChatState => getLocalState ( ) ,
@@ -39,7 +50,7 @@ export const useChatStore = defineStore('chat-store', {
3950 this . chat . unshift ( { uuid : r . uuid , data : [ ] } )
4051 }
4152 if ( uuid == null ) {
42- await this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false , usingContext : true } )
53+ await this . addNewHistory ( )
4354 }
4455 else {
4556 this . active = uuid
@@ -94,12 +105,27 @@ export const useChatStore = defineStore('chat-store', {
94105 this . recordState ( )
95106 } ,
96107
108+ async setChatModel ( chatModel : string , roomId : number ) {
109+ await fetchUpdateChatRoomChatModel ( chatModel , roomId )
110+ } ,
111+
97112 async addHistory ( history : Chat . History , chatData : Chat . Chat [ ] = [ ] ) {
98- await fetchCreateChatRoom ( history . title , history . uuid )
113+ await fetchCreateChatRoom ( history . title , history . uuid , history . chatModel )
99114 this . history . unshift ( history )
100115 this . chat . unshift ( { uuid : history . uuid , data : chatData } )
101116 this . active = history . uuid
102- this . reloadRoute ( history . uuid )
117+ await this . reloadRoute ( history . uuid )
118+ } ,
119+
120+ async addNewHistory ( ) {
121+ const userStore = useUserStore ( )
122+ await this . addHistory ( {
123+ title : 'New Chat' ,
124+ uuid : Date . now ( ) ,
125+ isEdit : false ,
126+ usingContext : true ,
127+ chatModel : userStore . userInfo . config . chatModel ,
128+ } )
103129 } ,
104130
105131 updateHistory ( uuid : number , edit : Partial < Chat . History > ) {
@@ -118,7 +144,7 @@ export const useChatStore = defineStore('chat-store', {
118144 this . chat . splice ( index , 1 )
119145
120146 if ( this . history . length === 0 ) {
121- await this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false , usingContext : true } )
147+ await this . addNewHistory ( )
122148 return
123149 }
124150
0 commit comments