Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
f40147ce
Commit
f40147ce
authored
Jan 17, 2024
by
Timothy J. Baek
Browse files
refac: gpt renamed to openai
parent
1f66bbba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
51 deletions
+51
-51
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+4
-4
src/lib/utils/index.ts
src/lib/utils/index.ts
+47
-47
No files found.
src/lib/components/chat/SettingsModal.svelte
View file @
f40147ce
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
import { WEB_UI_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { WEB_UI_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { config, models, settings, user, chats } from '$lib/stores';
import { config, models, settings, user, chats } from '$lib/stores';
import { splitStream, getGravatarURL, getImportOrigin, convert
Gpt
Chats } from '$lib/utils';
import { splitStream, getGravatarURL, getImportOrigin, convert
OpenAI
Chats } from '$lib/utils';
import Advanced from './Settings/Advanced.svelte';
import Advanced from './Settings/Advanced.svelte';
import Modal from '../common/Modal.svelte';
import Modal from '../common/Modal.svelte';
...
@@ -132,11 +132,11 @@
...
@@ -132,11 +132,11 @@
reader.onload = (event) => {
reader.onload = (event) => {
let chats = JSON.parse(event.target.result);
let chats = JSON.parse(event.target.result);
console.log(chats);
console.log(chats);
if (getImportOrigin(chats) == '
gpt
') {
if (getImportOrigin(chats) == '
openai
') {
try {
try {
chats = convert
Gpt
Chats(chats);
chats = convert
OpenAI
Chats(chats);
} catch (error) {
} catch (error) {
console.log(
"
Unable to import chats:
"
, error);
console.log(
'
Unable to import chats:
'
, error);
}
}
}
}
importChats(chats);
importChats(chats);
...
...
src/lib/utils/index.ts
View file @
f40147ce
...
@@ -195,68 +195,68 @@ export const calculateSHA256 = async (file) => {
...
@@ -195,68 +195,68 @@ export const calculateSHA256 = async (file) => {
export
const
getImportOrigin
=
(
_chats
)
=>
{
export
const
getImportOrigin
=
(
_chats
)
=>
{
// Check what external service chat imports are from
// Check what external service chat imports are from
if
(
'
mapping
'
in
_chats
[
0
])
{
if
(
'
mapping
'
in
_chats
[
0
])
{
return
'
gpt
'
;
return
'
openai
'
;
}
}
return
'
webui
'
;
return
'
webui
'
;
}
}
;
const
convert
Gpt
Messages
=
(
convo
)
=>
{
const
convert
OpenAI
Messages
=
(
convo
)
=>
{
// Parse OpenAI chat messages and create chat dictionary for creating new chats
// Parse OpenAI chat messages and create chat dictionary for creating new chats
const
mapping
=
convo
[
"
mapping
"
];
const
mapping
=
convo
[
'
mapping
'
];
const
messages
=
[];
const
messages
=
[];
let
currentId
=
""
;
let
currentId
=
''
;
for
(
let
message_id
in
mapping
)
{
for
(
let
message_id
in
mapping
)
{
const
message
=
mapping
[
message_id
];
const
message
=
mapping
[
message_id
];
currentId
=
message_id
;
currentId
=
message_id
;
if
(
message
[
"
message
"
]
==
null
||
message
[
"
message
"
][
"
content
"
][
"
parts
"
][
0
]
==
""
)
{
if
(
message
[
'
message
'
]
==
null
||
message
[
'
message
'
][
'
content
'
][
'
parts
'
][
0
]
==
''
)
{
// Skip chat messages with no content
// Skip chat messages with no content
continue
;
continue
;
}
else
{
}
else
{
const
new_chat
=
{
const
new_chat
=
{
"
id
"
:
message_id
,
id
:
message_id
,
"
parentId
"
:
messages
.
length
>
0
?
message
[
"
parent
"
]
:
null
,
parentId
:
messages
.
length
>
0
?
message
[
'
parent
'
]
:
null
,
"
childrenIds
"
:
message
[
"
children
"
]
||
[],
childrenIds
:
message
[
'
children
'
]
||
[],
"
role
"
:
message
[
"
message
"
]?.[
"
author
"
]?.[
"
role
"
]
!==
"
user
"
?
"
assistant
"
:
"
user
"
,
role
:
message
[
'
message
'
]?.[
'
author
'
]?.[
'
role
'
]
!==
'
user
'
?
'
assistant
'
:
'
user
'
,
"
content
"
:
message
[
"
message
"
]?.[
"
content
"
]?.[
'
parts
'
]?.[
0
]
||
""
,
content
:
message
[
'
message
'
]?.[
'
content
'
]?.[
'
parts
'
]?.[
0
]
||
''
,
"
model
"
:
''
,
model
:
''
,
"
done
"
:
true
,
done
:
true
,
"
context
"
:
null
,
context
:
null
}
}
;
messages
.
push
(
new_chat
)
messages
.
push
(
new_chat
)
;
}
}
}
}
let
history
=
{};
let
history
=
{};
messages
.
forEach
(
obj
=>
history
[
obj
.
id
]
=
obj
);
messages
.
forEach
(
(
obj
)
=>
(
history
[
obj
.
id
]
=
obj
)
)
;
const
chat
=
{
const
chat
=
{
"
history
"
:
{
history
:
{
"
currentId
"
:
currentId
,
currentId
:
currentId
,
"
messages
"
:
history
,
// Need to convert this to not a list and instead a json object
messages
:
history
// Need to convert this to not a list and instead a json object
},
},
"
models
"
:
[
""
],
models
:
[
''
],
"
messages
"
:
messages
,
messages
:
messages
,
"
options
"
:
{},
options
:
{},
"
timestamp
"
:
convo
[
"
create_time
"
],
timestamp
:
convo
[
'
create_time
'
],
"
title
"
:
convo
[
"
title
"
],
title
:
convo
[
'
title
'
]
}
}
;
return
chat
;
return
chat
;
}
}
;
export
const
convert
Gpt
Chats
=
(
_chats
)
=>
{
export
const
convert
OpenAI
Chats
=
(
_chats
)
=>
{
// Create a list of dictionaries with each conversation from import
// Create a list of dictionaries with each conversation from import
const
chats
=
[];
const
chats
=
[];
for
(
let
convo
of
_chats
)
{
for
(
let
convo
of
_chats
)
{
const
chat
=
{
const
chat
=
{
"
id
"
:
convo
[
"
id
"
],
id
:
convo
[
'
id
'
],
"
user_id
"
:
''
,
user_id
:
''
,
"
title
"
:
convo
[
"
title
"
],
title
:
convo
[
'
title
'
],
"
chat
"
:
convert
Gpt
Messages
(
convo
),
chat
:
convert
OpenAI
Messages
(
convo
),
"
timestamp
"
:
convo
[
"
timestamp
"
],
timestamp
:
convo
[
'
timestamp
'
]
}
}
;
chats
.
push
(
chat
)
chats
.
push
(
chat
)
;
}
}
return
chats
;
return
chats
;
}
}
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment