Skip to content

Commit

Permalink
feat: update addition feature storage and frontend features
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Mar 9, 2024
1 parent 9f41572 commit 6bf12df
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ screenshot
config.yaml
config.dev.yaml

# current in ~/storage
addition/generation/data/*
!addition/generation/data/.gitkeep

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ _🚀 **Next Generation AI One-Stop Solution**_
-p 8000:8094 \
-v ~/config:/config \
-v ~/logs:/logs \
-v ~/storage:/storage \
-e MYSQL_HOST=localhost \
-e MYSQL_PORT=3306 \
-e MYSQL_DATABASE=chatnio \
Expand All @@ -160,7 +161,7 @@ _🚀 **Next Generation AI One-Stop Solution**_
> - *-p 8000:8094* 指映射宿主机端口为 8000, 可自行修改冒号前的端口号
> - SECRET: JWT 密钥, 自行生成随机字符串修改
> - SERVE_STATIC: 是否启用静态文件服务 (正常情况下不需要更改此项, 详见下方常见问题解答)
> - *-v ~/config:/config* *-v ~/logs:/logs* 指挂载配置文件和日志文件的宿主机目录, 可自行修改
> - *-v ~/config:/config* 挂载配置文件, *-v ~/logs:/logs* 挂载日志文件的宿主机目录, *-v ~/storage:/storage* 挂载附加功能的生成文件
> - 需配置 MySQL 和 Redis 服务, 请自行参考上方信息修改环境变量

版本更新 (_开启 Watchtower 后无需手动更新, 执行后按照上述步骤重新运行即可_):
Expand Down
4 changes: 2 additions & 2 deletions addition/article/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ type WebsocketArticleResponse struct {
func ProjectTarDownloadAPI(c *gin.Context) {
hash := strings.TrimSpace(c.Query("hash"))
c.Writer.Header().Add("Content-Disposition", "attachment; filename=article.tar.gz")
c.File(fmt.Sprintf("addition/article/data/out/%s.tar.gz", hash))
c.File(fmt.Sprintf("storage/article/%s.tar.gz", hash))
}

func ProjectZipDownloadAPI(c *gin.Context) {
hash := strings.TrimSpace(c.Query("hash"))
c.Writer.Header().Add("Content-Disposition", "attachment; filename=article.zip")
c.File(fmt.Sprintf("addition/article/data/out/%s.zip", hash))
c.File(fmt.Sprintf("storage/article/%s.zip", hash))
}

func GenerateAPI(c *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions addition/article/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func CreateWorker(c *gin.Context, user *auth.User, model string, prompt string,

hook(StreamProgressResponse{Current: current, Total: total, Quota: 0})

path := fmt.Sprintf("addition/article/data/%s", hash)
if _, _, err := utils.GenerateCompressTask(hash, "addition/article/data/out", path, path); err != nil {
path := fmt.Sprintf("storage/article/data/%s", hash)
if _, _, err := utils.GenerateCompressTask(hash, "storage/article", path, path); err != nil {
globals.Debug(fmt.Sprintf("[article] error during generate compress task: %s", err.Error()))
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion addition/article/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GenerateDocxFile(target, title, content string) error {
}

func CreateArticleFile(hash, title, content string) string {
target := fmt.Sprintf("addition/article/data/%s/%s.docx", hash, title)
target := fmt.Sprintf("storage/article/data/%s/%s.docx", hash, title)
utils.FileDirSafe(target)
if err := GenerateDocxFile(target, title, content); err != nil {
globals.Debug(fmt.Sprintf("[article] error during generate article %s: %s", title, err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions addition/generation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type WebsocketGenerationForm struct {
func ProjectTarDownloadAPI(c *gin.Context) {
hash := strings.TrimSpace(c.Query("hash"))
c.Writer.Header().Add("Content-Disposition", "attachment; filename=code.tar.gz")
c.File(fmt.Sprintf("addition/generation/data/out/%s.tar.gz", hash))
c.File(fmt.Sprintf("storage/generation/%s.tar.gz", hash))
}

func ProjectZipDownloadAPI(c *gin.Context) {
hash := strings.TrimSpace(c.Query("hash"))
c.Writer.Header().Add("Content-Disposition", "attachment; filename=code.zip")
c.File(fmt.Sprintf("addition/generation/data/out/%s.zip", hash))
c.File(fmt.Sprintf("storage/generation/%s.zip", hash))
}

func GenerateAPI(c *gin.Context) {
Expand Down
2 changes: 1 addition & 1 deletion addition/generation/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func GetFolder(hash string) string {
return fmt.Sprintf("addition/generation/data/%s", hash)
return fmt.Sprintf("storage/generation/data/%s", hash)
}

func GetFolderByHash(model string, prompt string) (string, string) {
Expand Down
2 changes: 1 addition & 1 deletion addition/generation/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CreateGenerationWithCache(group, model, prompt string, hook func(buffer *ut
}
}

if _, _, err := utils.GenerateCompressTask(hash, "addition/generation/data/out", path, path); err != nil {
if _, _, err := utils.GenerateCompressTask(hash, "storage/generation", path, path); err != nil {
return "", fmt.Errorf("error during generate compress task: %s", err.Error())
}

Expand Down
5 changes: 4 additions & 1 deletion app/src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ function MarkdownContent({
<DialogClose asChild>
<Button variant={`outline`}>{t("cancel")}</Button>
</DialogClose>
<DialogClose onClick={async () => await sendAction(message)} asChild>
<DialogClose
onClick={async () => await sendAction(message)}
asChild
>
<Button variant={`default`}>{t("confirm")}</Button>
</DialogClose>
</DialogFooter>
Expand Down
16 changes: 13 additions & 3 deletions app/src/routes/Article.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@/assets/pages/article.less";
import { Button } from "@/components/ui/button.tsx";
import router from "@/router.tsx";
import { Check, ChevronLeft, Files, Globe, Loader2 } from "lucide-react";
import { Check, ChevronLeft, Cloud, Files, Globe, Loader2 } from "lucide-react";
import { Textarea } from "@/components/ui/textarea.tsx";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
Expand Down Expand Up @@ -31,7 +31,7 @@ type ProgressProps = {
total: number;
};

function GenerateProgress({ current, total }: ProgressProps) {
function GenerateProgress({ current, total, quota }: ProgressProps & { quota: number }) {
const { t } = useTranslation();

return (
Expand All @@ -56,6 +56,12 @@ function GenerateProgress({ current, total }: ProgressProps) {
)}
</p>
<Progress value={(100 * current) / total} />
<div
className={`article-quota flex flex-row mt-4 border border-input rounded-md py-1 px-3 select-none w-max items-center mx-auto`}
>
<Cloud className={`h-4 w-4 mr-2`} />
<p>{quota.toFixed(2)}</p>
</div>
</div>
);
}
Expand All @@ -72,13 +78,15 @@ function ArticleContent() {
const [progress, setProgress] = useState(false);

const [state, setState] = useState<ProgressProps>({ current: 0, total: 0 });
const [quota, setQuota] = useState<number>(0);
const [hash, setHash] = useState("");

function clear() {
setPrompt("");
setTitle("");
setHash("");
setProgress(false);
setQuota(0);
setState({ current: 0, total: 0 });
}

Expand All @@ -100,6 +108,8 @@ function ArticleContent() {

connection.onmessage = (e) => {
const data = JSON.parse(e.data);

data.data && data.data.quota && setQuota(quota + data.data.quota);
if (!data.hash) setState(data.data as ProgressProps);
else {
toast({
Expand All @@ -123,7 +133,7 @@ function ArticleContent() {

return progress ? (
<>
<GenerateProgress {...state} />
<GenerateProgress {...state} quota={quota} />
{hash && (
<div className={`article-action flex flex-row items-center my-4 gap-4`}>
<Button
Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/Generation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function Wrapper({ onSend }: WrapperProps) {
{quota > 0 && (
<div className={`quota-box`}>
<Cloud className={`h-4 w-4 mr-2`} />
{quota}
{quota.toFixed(2)}
</div>
)}
<pre className={`message-box`}>
Expand Down
1 change: 1 addition & 0 deletions docker-compose.stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ services:
volumes:
- ./config:/config
- ./logs:/logs
- ./storage:/storage
networks:
- chatnio-network

Expand Down
1 change: 1 addition & 0 deletions docker-compose.watch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ services:
volumes:
- ./config:/config
- ./logs:/logs
- ./storage:/storage
networks:
- chatnio-network

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ services:
volumes:
- ./config:/config
- ./logs:/logs
- ./storage:/storage
networks:
- chatnio-network

Expand Down

0 comments on commit 6bf12df

Please sign in to comment.