Merge remote-tracking branch 'upstream/main'

This commit is contained in:
wozulong 2024-03-25 15:49:12 +08:00
commit bfe9e5d25a
7 changed files with 51 additions and 14 deletions

View File

@ -75,26 +75,44 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*d
err := json.Unmarshal(common.StringToByteSlice(streamResp), &streamResponses)
if err != nil {
common.SysError("error unmarshalling stream response: " + err.Error())
return // just ignore the error
for _, item := range streamItems {
var streamResponse dto.ChatCompletionsStreamResponseSimple
err := json.Unmarshal(common.StringToByteSlice(item), &streamResponse)
if err == nil {
for _, choice := range streamResponse.Choices {
responseTextBuilder.WriteString(choice.Delta.Content)
}
}
}
} else {
for _, streamResponse := range streamResponses {
for _, choice := range streamResponse.Choices {
responseTextBuilder.WriteString(choice.Delta.Content)
}
}
}
case relayconstant.RelayModeCompletions:
var streamResponses []dto.CompletionsStreamResponse
err := json.Unmarshal(common.StringToByteSlice(streamResp), &streamResponses)
if err != nil {
common.SysError("error unmarshalling stream response: " + err.Error())
return // just ignore the error
for _, item := range streamItems {
var streamResponse dto.CompletionsStreamResponse
err := json.Unmarshal(common.StringToByteSlice(item), &streamResponse)
if err == nil {
for _, choice := range streamResponse.Choices {
responseTextBuilder.WriteString(choice.Text)
}
}
}
} else {
for _, streamResponse := range streamResponses {
for _, choice := range streamResponse.Choices {
responseTextBuilder.WriteString(choice.Text)
}
}
}
}
if len(dataChan) > 0 {
// wait data out
time.Sleep(2 * time.Second)

View File

@ -322,6 +322,9 @@ const ChannelsTable = () => {
const res = await API.get(
`/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`,
);
if (res === undefined) {
return;
}
const { success, message, data } = res.data;
if (success) {
if (startIdx === 0) {
@ -608,6 +611,9 @@ const ChannelsTable = () => {
let res = await API.get(`/api/group/`);
// add 'all' option
// res.data.data.unshift('all');
if (res === undefined) {
return;
}
setGroupOptions(
res.data.data.map((group) => ({
label: group,

View File

@ -628,7 +628,7 @@ const PersonalSetting = () => {
onCancel={() => setShowWeChatBindModal(false)}
// onOpen={() => setShowWeChatBindModal(true)}
visible={showWeChatBindModal}
size={'mini'}
size={'small'}
>
<Image src={status.wechat_qrcode} />
<div style={{ textAlign: 'center' }}>
@ -678,7 +678,7 @@ const PersonalSetting = () => {
onClick={sendVerificationCode}
disabled={disableButton || loading}
>
{disableButton ? `重新发送(${countdown})` : '获取验证码'}
{disableButton ? `重新发送 (${countdown})` : '获取验证码'}
</Button>
</div>
<div style={{ marginTop: 10 }}>

View File

@ -156,6 +156,9 @@ const SiderBar = () => {
const loadStatus = async () => {
const res = await API.get('/api/status');
if (res === undefined) {
return;
}
const { success, data } = res.data;
if (success) {
localStorage.setItem('status', JSON.stringify(data));

View File

@ -46,7 +46,7 @@ const SystemSetting = () => {
TurnstileSecretKey: '',
RegisterEnabled: '',
EmailDomainRestrictionEnabled: '',
EmailDomainWhitelist: '',
EmailDomainWhitelist: [],
// telegram login
TelegramOAuthEnabled: '',
TelegramBotToken: '',
@ -89,6 +89,7 @@ const SystemSetting = () => {
useEffect(() => {
getOptions().then();
}, []);
useEffect(() => {}, [inputs.EmailDomainWhitelist]);
const updateOption = async (key, value) => {
setLoading(true);

View File

@ -188,6 +188,9 @@ const EditChannel = (props) => {
const loadChannel = async () => {
setLoading(true);
let res = await API.get(`/api/channel/${channelId}`);
if (res === undefined) {
return;
}
const { success, message, data } = res.data;
if (success) {
if (data.models === '') {
@ -223,6 +226,9 @@ const EditChannel = (props) => {
const fetchModels = async () => {
try {
let res = await API.get(`/api/channel/models`);
if (res === undefined) {
return;
}
let localModelOptions = res.data.data.map((model) => ({
label: model.id,
value: model.id,
@ -244,6 +250,9 @@ const EditChannel = (props) => {
const fetchGroups = async () => {
try {
let res = await API.get(`/api/group/`);
if (res === undefined) {
return;
}
setGroupOptions(
res.data.data.map((group) => ({
label: group,

View File

@ -39,7 +39,7 @@ const Setting = () => {
<Layout.Content>
<Tabs type='line' defaultActiveKey='1'>
{panes.map((pane) => (
<TabPane itemKey={pane.itemKey} tab={pane.tab}>
<TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
{pane.content}
</TabPane>
))}