mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
update service worker
This commit is contained in:
parent
d6a02dc278
commit
6a0bf4bebb
@ -20,6 +20,7 @@ import (
|
||||
)
|
||||
|
||||
var defaultMaxRetries = 3
|
||||
var midjourneyMaxRetries = 10
|
||||
|
||||
type RequestProps struct {
|
||||
MaxRetries *int
|
||||
|
@ -31,7 +31,8 @@ func (c *ChatInstance) CreateImagineRequest(prompt string) (*ImagineResponse, er
|
||||
return utils.MapToStruct[ImagineResponse](res), nil
|
||||
}
|
||||
|
||||
func getStatusCode(code int) error {
|
||||
func getStatusCode(response *ImagineResponse) error {
|
||||
code := response.Code
|
||||
switch code {
|
||||
case SuccessCode, QueueCode:
|
||||
return nil
|
||||
@ -42,7 +43,7 @@ func getStatusCode(code int) error {
|
||||
case NudeCode:
|
||||
return fmt.Errorf("prompt violates the content policy of midjourney, the request is rejected")
|
||||
default:
|
||||
return fmt.Errorf("unknown error from midjourney")
|
||||
return fmt.Errorf(fmt.Sprintf("unknown error from midjourney (code: %d, description: %s)", code, response.Description))
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ func (c *ChatInstance) CreateStreamImagineTask(prompt string, hook func(progress
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := getStatusCode(res.Code); err != nil {
|
||||
if err := getStatusCode(res); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,11 @@ func isQPSOverLimit(model string, err error) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func getRetries(retries *int) int {
|
||||
func getRetries(model string, retries *int) int {
|
||||
if retries == nil {
|
||||
if globals.IsMidjourneyModel(model) {
|
||||
return midjourneyMaxRetries
|
||||
}
|
||||
return defaultMaxRetries
|
||||
}
|
||||
|
||||
@ -31,7 +34,7 @@ func getRetries(retries *int) int {
|
||||
func NewChatRequest(props *ChatProps, hook globals.Hook) error {
|
||||
err := createChatRequest(props, hook)
|
||||
|
||||
retries := getRetries(props.MaxRetries)
|
||||
retries := getRetries(props.Model, props.MaxRetries)
|
||||
props.Current++
|
||||
|
||||
if IsAvailableError(err) {
|
||||
|
@ -5,8 +5,8 @@
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes" />
|
||||
<title>Chat Nio</title>
|
||||
<meta name="keywords" content="ChatGPT, AI聊天, ChatNio, chatnio">
|
||||
<meta name="description" content="👋 Chat Nio, lightweight Web ChatGPT chat site 👋 Chat Nio, 一个轻量级的联网版 AI 聊天网站">
|
||||
<meta name="keywords" content="ChatGPT, ChatNio, chatnio">
|
||||
<meta name="description" content="👋 Chat Nio, Your Next Powerful AI Chat Platform. Creating Possibilities in the World of AI Chat.">
|
||||
<meta name="author" content="Deeptrain Team">
|
||||
<meta name="theme-color" content="#000000">
|
||||
<meta itemprop="image" content="/favicon.ico">
|
||||
@ -14,10 +14,11 @@
|
||||
<link href="https://open.lightxi.com/fonts/Andika" rel="stylesheet">
|
||||
<link href="https://open.lightxi.com/fonts/Jetbrains-Mono" rel="stylesheet">
|
||||
<link href="https://open.lightxi.com/jsdelivr/npm/katex@0.16.0/dist/katex.min.css" rel="stylesheet">
|
||||
<script src="/workbox.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<noscript>You need to enable JavaScript to run chatnio.</noscript>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
24
app/public/service.js
Normal file
24
app/public/service.js
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
const SERVICE_NAME = "chatnio";
|
||||
|
||||
self.addEventListener('activate', function (event) {
|
||||
console.debug("[service] service worker activated");
|
||||
});
|
||||
|
||||
self.addEventListener('install', function (event) {
|
||||
event.waitUntil(
|
||||
caches.open(SERVICE_NAME)
|
||||
.then(function (cache) {
|
||||
return cache.addAll([]);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(function (response) {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
10
app/public/workbox.js
Normal file
10
app/public/workbox.js
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function () {
|
||||
navigator.serviceWorker.register('/service.js').then(function (registration) {
|
||||
console.debug(`[service] service worker registered with scope: ${registration.scope}`);
|
||||
}, function (err) {
|
||||
console.debug(`[service] service worker registration failed: ${err}`);
|
||||
});
|
||||
});
|
||||
}
|
@ -170,11 +170,11 @@ func CountOutputToken(model string, t int) float32 {
|
||||
case globals.StableDiffusion:
|
||||
return 0.25
|
||||
case globals.Midjourney:
|
||||
return 0.5
|
||||
return 0.1
|
||||
case globals.MidjourneyFast:
|
||||
return 2
|
||||
return 0.5
|
||||
case globals.MidjourneyTurbo:
|
||||
return 5
|
||||
return 1
|
||||
case globals.Dalle3:
|
||||
return 5.6
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user