Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ad6f7d99d | ||
|
|
68abcd48ab | ||
|
|
0c175b4e44 | ||
|
|
4e31c3991d | ||
|
|
5b8a826cf9 |
@@ -32,7 +32,6 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
|
||||
if channel.BaseURL != "" {
|
||||
requestURL = channel.BaseURL
|
||||
}
|
||||
requestURL += "/api/chat-process"
|
||||
} else {
|
||||
if channel.BaseURL != "" {
|
||||
requestURL = channel.BaseURL
|
||||
@@ -123,29 +122,29 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
|
||||
var done = false
|
||||
var streamResponseText = ""
|
||||
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||
if atEOF && len(data) == 0 {
|
||||
if channel.Type != common.ChannelTypeChatGPTWeb {
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||
if atEOF && len(data) == 0 {
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
if i := strings.Index(string(data), "\n"); i >= 0 {
|
||||
return i + 2, data[0:i], nil
|
||||
}
|
||||
|
||||
if atEOF {
|
||||
return len(data), data, nil
|
||||
}
|
||||
|
||||
return 0, nil, nil
|
||||
}
|
||||
})
|
||||
for scanner.Scan() {
|
||||
data := scanner.Text()
|
||||
if len(data) < 6 { // must be something wrong!
|
||||
continue
|
||||
}
|
||||
|
||||
if i := strings.Index(string(data), "\n\n"); i >= 0 {
|
||||
return i + 2, data[0:i], nil
|
||||
}
|
||||
|
||||
if atEOF {
|
||||
return len(data), data, nil
|
||||
}
|
||||
|
||||
return 0, nil, nil
|
||||
})
|
||||
for scanner.Scan() {
|
||||
data := scanner.Text()
|
||||
if len(data) < 6 { // must be something wrong!
|
||||
common.SysError("invalid stream response: " + data)
|
||||
continue
|
||||
}
|
||||
if channel.Type != common.ChannelTypeChatGPTWeb {
|
||||
// If data has event: event content inside, remove it, it can be prefix or inside the data
|
||||
if strings.HasPrefix(data, "event:") || strings.Contains(data, "event:") {
|
||||
// Remove event: event in the front or back
|
||||
@@ -186,36 +185,28 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
|
||||
done = true
|
||||
break
|
||||
}
|
||||
} else if channel.Type == common.ChannelTypeChatGPTWeb {
|
||||
// data may contain multiple json objects, so we need to split them
|
||||
// they are "{....}{....}{....}" or "{....}\n{....}\n{....}" or "{....}"
|
||||
|
||||
// remove all spaces and newlines outside of json objects
|
||||
jsonObjs := strings.Split(data, "\n") // Split the data into multiple JSON objects
|
||||
for _, jsonObj := range jsonObjs {
|
||||
if jsonObj == "" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else if channel.Type == common.ChannelTypeChatGPTWeb {
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
|
||||
go func() {
|
||||
for scanner.Scan() {
|
||||
var chatResponse ChatGptWebChatResponse
|
||||
err = json.Unmarshal([]byte(jsonObj), &chatResponse)
|
||||
err = json.Unmarshal(scanner.Bytes(), &chatResponse)
|
||||
|
||||
if err != nil {
|
||||
// Print the body in string
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(resp.Body)
|
||||
common.SysError("error unmarshalling chat response: " + err.Error() + " " + buf.String())
|
||||
return err
|
||||
log.Println("error unmarshal chat response: " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
// if response role is assistant and contains delta, append the content to streamResponseText
|
||||
if chatResponse.Role == "assistant" && chatResponse.Detail != nil {
|
||||
for _, choice := range chatResponse.Detail.Choices {
|
||||
log.Print(choice.Delta.Content)
|
||||
streamResponseText += choice.Delta.Content
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -121,8 +121,6 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
} else if channelType == common.ChannelTypeChatGPTWeb {
|
||||
// remove /v1/chat/completions from request url
|
||||
requestURL := strings.Split(requestURL, "/v1/chat/completions")[0]
|
||||
requestURL += "/api/chat-process"
|
||||
|
||||
fullRequestURL = fmt.Sprintf("%s%s", baseURL, requestURL)
|
||||
} else if channelType == common.ChannelTypePaLM {
|
||||
err := relayPaLM(textRequest, c)
|
||||
|
||||
16
i18n/en.json
16
i18n/en.json
@@ -237,7 +237,8 @@
|
||||
"保存首页内容": "Save Home Page Content",
|
||||
"在此输入新的关于内容,支持 Markdown & HTML 代码。如果输入的是一个链接,则会使用该链接作为 iframe 的 src 属性,这允许你设置任意网页作为关于页面": "Enter new about content here, supports Markdown & HTML code. If a link is entered, it will be used as the src attribute of the iframe, allowing you to set any webpage as the about page.",
|
||||
"保存关于": "Save About",
|
||||
"移除 One API 的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目": "Removal of One API copyright mark must first be authorized. Project maintenance requires a lot of effort. If this project is meaningful to you, please actively support it.",
|
||||
"移除 One API": "Removal of One API",
|
||||
"的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。": " copyright mark must first be authorized. Project maintenance requires a lot of effort. If this project is meaningful to you, please actively support it.",
|
||||
"页脚": "Footer",
|
||||
"在此输入新的页脚,留空则使用默认页脚,支持 HTML 代码": "Enter the new footer here, leave blank to use the default footer, supports HTML code.",
|
||||
"设置页脚": "Set Footer",
|
||||
@@ -525,5 +526,16 @@
|
||||
"无法启用 Discord OAuth,请先填入 Discord Client ID 以及 Discord Client Secret!": "Unable to enable Discord OAuth, please fill in the Discord Client ID and Discord Client Secret first!",
|
||||
"兑换失败,": "Redemption failed, ",
|
||||
"请选择此密钥支持的模型": "Please select the models supported by this key",
|
||||
"将IP随机地址传递给HTTP头": "Pass the IP random address to the HTTP header"
|
||||
"将IP随机地址传递给HTTP头": "Pass the IP random address to the HTTP header",
|
||||
"失败重试次数": "Number of failed retries",
|
||||
"消费": "Consumption",
|
||||
"管理": "Management",
|
||||
"系统": "System",
|
||||
"未知": "Unknown",
|
||||
"One API 会把请求体中的 model": "One API will take the model in the request body",
|
||||
",因为": ", because",
|
||||
"参数替换为你的部署名称(模型名称中的点会被剔除),": "Replace the parameter with your deployment name (dots in the model name will be removed), ",
|
||||
"注意,此处生成的令牌用于系统管理,而非用于请求 OpenAI": "Note that the generated token here is used for system management, not for requesting OpenAI",
|
||||
"相关的服务,请知悉。": "related services, please be aware.",
|
||||
"填入": "Fill in"
|
||||
}
|
||||
|
||||
@@ -59,19 +59,19 @@ const EditChannel = () => {
|
||||
data.models = [];
|
||||
} else {
|
||||
data.models = data.models.split(',');
|
||||
setTimeout(() => {
|
||||
let localModelOptions = [...modelOptions];
|
||||
data.models.forEach((model) => {
|
||||
if (!localModelOptions.find((option) => option.key === model)) {
|
||||
localModelOptions.push({
|
||||
key: model,
|
||||
text: model,
|
||||
value: model,
|
||||
});
|
||||
}
|
||||
});
|
||||
setModelOptions(localModelOptions);
|
||||
}, 1000);
|
||||
// setTimeout(() => {
|
||||
// let localModelOptions = [...modelOptions];
|
||||
// data.models.forEach((model) => {
|
||||
// if (!localModelOptions.find((option) => option.key === model)) {
|
||||
// localModelOptions.push({
|
||||
// key: model,
|
||||
// text: model,
|
||||
// value: model,
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// setModelOptions(localModelOptions);
|
||||
// }, 1000);
|
||||
}
|
||||
if (data.group === '') {
|
||||
data.groups = [];
|
||||
|
||||
Reference in New Issue
Block a user