Skip to content

Commit

Permalink
feat: add support for user persona
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokang00010 committed Jul 10, 2024
1 parent ead57d0 commit 6973945
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
32 changes: 29 additions & 3 deletions pages/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,37 @@ import version from '../shared/version';

const Settings = ({ navigation }) => {
const [userName, setUserName] = React.useState('');
const [userPersona, setUserPersona] = React.useState('');
const [password, setPassword] = React.useState('');
const [messageState, setMessageState] = React.useState(false)
const [messageText, setMessageText] = React.useState("")

React.useEffect(() => {
Remote.getUserName().then(d => {
setUserName(d)
Remote.getServiceInfo().then(d => {
if (d.status) {
setUserName(d.data.data.session_username)
setUserPersona(d.data.data.user_persona)}
}).catch(e => {
setMessageState(true)
setMessageText("NetworkError")
})
}, [])

function submitUserPersona(userPersona) {
Remote.updateUserPersona(userPersona).then(d => {
if (d.data.status) {
setMessageState(true)
setMessageText("User persona updated successfully.")
} else {
setMessageState(true)
setMessageText(d.data.data)
}
}).catch(e => {
setMessageState(true)
setMessageText("NetworkError")
})
}

function submitUserName(userName) {
Remote.updateUserName(userName).then(d => {
if (d.data.status) {
Expand Down Expand Up @@ -71,13 +89,21 @@ const Settings = ({ navigation }) => {
<ScrollView>
<List.Section>
<ContentEditDialog
title="User name"
title="User Name"
description="The name you will be used to chat with your waifus."
placeholder="Jerry Chou"
style={{ paddingHorizontal: 10, paddingVertical: 20 }}
defaultValue={userName}
onOk={v => {setUserName(v); submitUserName(v)}}
/>
<ContentEditDialog
title="User Persona"
description="User persona is used to describe your personality and interests so as to enhance your experience by helping waifu understand you better."
placeholder="A high-school student, who loves playing video games and watching anime."
style={{ paddingHorizontal: 10, paddingVertical: 20 }}
defaultValue={userPersona}
onOk={v => {setUserPersona(v); submitUserPersona(v)}}
/>
<PasswordEditConfirmDialog
title="Password"
description="The password you will use to login to your server."
Expand Down
10 changes: 10 additions & 0 deletions shared/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ function splitEmotionAndText(emotions, text) {
return result;
}

function getServiceInfo() {
return axios.get(`${serverUrl}/api/v1/service/info`)
}

function updateUserPersona(persona) {
return axios.post(`${serverUrl}/api/v1/update_persona`, {persona})
}

function createTTSService(name, description, url, ttsInferYamlPath) {
return axios.post(`${serverUrl}/api/v1/tts/service/create`, {
name,
Expand Down Expand Up @@ -314,6 +322,7 @@ export {
editCharacter,
getAvatar,
getCharacterInfo,
getServiceInfo,
getStickerSetInfo,
getTTSServiceInfo,
getTTSServiceList,
Expand All @@ -334,4 +343,5 @@ export {
updatePassword,
updateTTSService,
updateUserName,
updateUserPersona,
};

0 comments on commit 6973945

Please sign in to comment.