Skip to content

Commit 6b73414

Browse files
authored
Merge pull request #2 from Yesifan/docs
Update Docs
2 parents a2f38a2 + 98e7a64 commit 6b73414

28 files changed

+586
-321
lines changed

darkit/core/predicter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ def from_pretrained(
116116
device: Optional[str] = None,
117117
checkpoint: Optional[str] = None,
118118
):
119+
"""
120+
不可以直接从父 Predicter 类实例化,需要保证 root 路径一致,否则无法根据 name 找到模型
121+
"""
122+
model = cls.get_model(name, checkpoint)
123+
model = cls.inject_script(model, name)
119124
trainer_config = cls.get_trainer_config_json(name)
120125
device = device if device else trainer_config.get("device", "cuda")
121-
model = cls.get_model(name, checkpoint).to(device)
122-
model = cls.inject_script(model, name)
123126
return cls(name, model, device=device)
124127

125128
def _predict(self, ctx):

darkit/core/trainer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __new__(
197197

198198
@property
199199
def root(self) -> Path:
200-
return MODEL_PATH
200+
return MODEL_PATH / "base"
201201

202202
@property
203203
def save_directory(self) -> Optional[Path]:
@@ -305,13 +305,13 @@ def _save_external_config(self):
305305
def _copy_model_code(self):
306306
try:
307307
if self.save_directory:
308-
model_py_path = inspect.getfile(self.model.__class__)
309-
with open(model_py_path, "r", encoding="utf-8") as f:
310-
model_source_code = f.read()
311-
with open(self.model_code_archive_path, "w", encoding="utf-8") as f:
312-
f.write(model_source_code)
308+
model_source_code = inspect.getsource(self.model.__class__)
309+
with open(self.model_code_archive_path, "w", encoding="utf-8") as f:
310+
f.write(model_source_code)
313311
except OSError as e:
314312
print("Save model code failed:", e)
313+
except TypeError as e:
314+
print("Cannot retrieve source code for built-in class:", e)
315315

316316
def save_pretrained(self, check_poinent="complete"):
317317
"""

darkit/core/web/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
static/docs/*
22
src/routes/docs/**/*.md
33
src/routes/docs/navigation.json
4+
src/routes/docs/navigation_zh.json
45

56
# ---- Svelte ----
67
node_modules

darkit/core/web/messages/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"$schema": "https://inlang.com/schema/inlang-message-format",
3+
"h_doc": "Doc",
4+
"h_network": "Network",
35
"not_found_tip": "Sorry, the page you are looking for is not found.",
46
"back_home": "Back to Home",
57
"docs": "Docs",

darkit/core/web/messages/zh.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"$schema": "https://inlang.com/schema/inlang-message-format",
3+
"h_doc": "文档",
4+
"h_network": "网络",
35
"not_found_tip": "抱歉,没有找到您要查找的页面。",
46
"back_home": "返回首页",
57
"docs": "文档",

darkit/core/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@xyflow/svelte": "^0.1.23",
5353
"codejar": "^4.2.0",
5454
"echarts": "^5.5.1",
55+
"front-matter": "^4.0.2",
5556
"mode-watcher": "^0.4.1",
5657
"prismjs": "^1.29.0",
5758
"svelte-sonner": "^0.3.28",

darkit/core/web/pnpm-lock.yaml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

darkit/core/web/src/lib/components/header.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logo from '$lib/images/logo.svg';
55
import DarkModeButton from './dark-mode-button.svelte';
66
import I18nButton from './i18n-button.svelte';
7+
import * as m from '$lib/paraglide/messages';
78
89
let pathname = $derived($page.url.pathname);
910
</script>
@@ -29,9 +30,9 @@
2930
<span class="text-primary px-2 text-lg font-bold"> DarwinKit </span>
3031
</a>
3132
<ul class="flex flex-1 gap-2">
32-
{@render item('Doc', '/docs', '/docs')}
33+
{@render item(m.h_doc(), '/docs', '/docs')}
34+
{@render item(m.h_network(), '/flow', '/flow')}
3335
{@render item('LM', '/lm/train', '/lm')}
34-
{@render item('Build Network', '/flow', '/flow')}
3536
</ul>
3637
<I18nButton class="mr-4" />
3738
<DarkModeButton />

darkit/core/web/src/routes/docs/+layout.svelte

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
<script>
2-
import DocsNavbar from '$lib/components/docs-navbar.svelte';
32
import Navigation from './navigation.json';
3+
import ZhNavigation from './navigation_zh.json';
4+
import { languageTag } from '$lib/paraglide/runtime';
5+
import DocsNavbar from '$lib/components/docs-navbar.svelte';
46
57
let { children } = $props();
68
7-
const docsContents = Navigation.map((item) => {
8-
return {
9-
caption: item.title,
10-
contents: item.children.map((child) => {
11-
return [child.title, child.path];
12-
})
13-
};
14-
});
9+
const navigation = $derived(languageTag() === 'zh' ? ZhNavigation : Navigation);
10+
11+
const docsContents = $derived(
12+
navigation.map((item) => {
13+
return {
14+
caption: item.title,
15+
contents: item.children.map((child) => {
16+
const title = child.metadata.title || child.title;
17+
return [title, child.path];
18+
})
19+
};
20+
})
21+
);
1522
</script>
1623

1724
<DocsNavbar contents={docsContents} />

0 commit comments

Comments
 (0)