Skip to content

Commit

Permalink
perf(toolbox): 优化语素识别提示
Browse files Browse the repository at this point in the history
  • Loading branch information
mark9804 committed Jun 23, 2024
1 parent df2bcab commit 7b6d590
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
2 changes: 1 addition & 1 deletion apps/ba-online-toolbox/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default [
content: [
{
type: "text",
text: '[{"word":"青空","furigana":"あおぞら","basic_form":"青空","word_type":"名詞","word_sub_type":"普通名詞","conjungation_type":"*","conjungation_form":"*"},{"word":"に","furigana":"に","basic_form":"に","word_type":"助詞","word_sub_type":"格助詞","conjungation_type":"*","conjungation_form":"*"},{"word":"\\n","furigana":"","basic_form":"","word_type":"未定義語","word_sub_type":"その他","conjungation_type":"*","conjungation_form":"*"},{"word":"たくさん","furigana":"たくさん","basic_form":"たくさん","word_type":"副詞","word_sub_type":"一般","conjungation_type":"*","conjungation_form":"*"},{"word":"の","furigana":"の","basic_form":"の","word_type":"助詞","word_sub_type":"連体化","conjungation_type":"*","conjungation_form":"*"},{"word":"気球","furigana":"ききゅう","basic_form":"気球","word_type":"名詞","word_sub_type":"普通名詞","conjungation_type":"*","conjungation_form":"*"},{"word":"が","furigana":"が","basic_form":"が","word_type":"助詞","word_sub_type":"格助詞","conjungation_type":"*","conjungation_form":"*"},{"word":"\\n","furigana":"","basic_form":"","word_type":"未定義語","word_sub_type":"その他","conjungation_type":"*","conjungation_form":"*"},{"word":"浮か","furigana":"うか","basic_form":"浮く","word_type":"動詞","word_sub_type":"一般","conjungation_type":"五段・カ行イ音便","conjungation_form":"連用形"},{"word":"んで","furigana":"んで","basic_form":"ぬ","word_type":"助動詞","word_sub_type":"*","conjungation_type":"助動詞-ぬ","conjungation_form":"連用形"},{"word":"い","furigana":"い","basic_form":"いる","word_type":"動詞","word_sub_type":"非自立可能","conjungation_type":"上一段-ア行","conjungation_form":"連用形"},{"word":"た","furigana":"た","basic_form":"た","word_type":"助動詞","word_sub_type":"*","conjungation_type":"助動詞-タ","conjungation_form":"基本形"}]',
text: '[{"word":"青空","yomi":"あおぞら","basic_form":"青空","word_type":"名詞・普通名詞","conjugation":"*"},{"word":"に","yomi":"に","basic_form":"に","word_type":"助詞・格助詞","conjugation":"*"},{"word":"、","yomi":"、","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"\\n","yomi":"\\n","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"たくさん","yomi":"たくさん","basic_form":"たくさん","word_type":"副詞","conjugation":"*"},{"word":"の","yomi":"の","basic_form":"の","word_type":"助詞・連体化","conjugation":"*"},{"word":"\\\"","yomi":"\\\"","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"気球","yomi":"きゅう","basic_form":"気球","word_type":"名詞・普通名詞","conjugation":"*"},{"word":"\\\"","yomi":"\\\"","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"が","yomi":"が","basic_form":"が","word_type":"助詞・格助詞","conjugation":"*"},{"word":"、","yomi":"、","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"浮かん","yomi":"うかん","basic_form":"浮かぶ","word_type":"動詞・自立","conjugation":"五段・バ行"},{"word":"で","yomi":"で","basic_form":"で","word_type":"助詞・格助詞","conjugation":"*"},{"word":"い","yomi":"い","basic_form":"いる","word_type":"動詞・非自立可能","conjugation":"母音動詞+基本形"},{"word":"た","yomi":"た","basic_form":"た","word_type":"助動詞","conjugation":"助動詞タ系+基本形"}]',
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ import { computed } from "vue";
const props = defineProps<{ semantic: SemanticUnit }>();
const shouldShowKana = computed(() => {
return props.semantic.furigana !== props.semantic.word;
return props.semantic.yomi !== props.semantic.word;
});
</script>

<template>
<div class="flex flex-col justify-end items-center">
<span class="text-[8px]" v-if="shouldShowKana">{{ semantic.furigana }}</span>
<span class="text-[8px]" v-if="shouldShowKana">{{ semantic.yomi }}</span>
<n-tooltip placement="bottom">
<template #trigger>
<n-tag size="medium">{{ semantic.word }}</n-tag>
</template>
<div>基本形表記: {{ semantic.basic_form }}</div>
<div>品詞: {{ semantic.word_type }}</div>
<div>品詞細分類: {{ semantic.word_sub_type }}</div>
<div>活用型: {{ semantic.conjungation_type }}</div>
<div>活用形: {{ semantic.conjungation_form }}</div>
<div>基本形表記: {{ semantic.basic_form }}</div>
<div>活用型: {{ semantic.conjugation }}</div>
</n-tooltip>
</div>
</template>

<style scoped lang="scss">
</style>
<style scoped lang="scss"></style>
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
export type SemanticUnit = {
word: string;
furigana: string;
yomi: string;
basic_form: string;
word_type: string;
word_sub_type: string;
conjungation_type: string;
conjungation_form: string;
conjugation: string;
};

export enum AnthropicStatusCode {
Expand All @@ -21,4 +19,4 @@ export type SemanticParseResult = {
status: AnthropicStatusCode;
message: string;
tokens: SemanticUnit[];
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ const rag_request = {
temperature: 0,
system:
/* eslint-disable-next-line max-len */
"你是一名日语语言学专家。你需要解析用户给出的句子成分,并将句子成分以json格式返回。将原句中的'\n'解析为'未定義語',并转义原文中的引号。",
"你是一名日语语言学专家。你需要解析用户给出的句子语素,并将语素以JSON格式返回。单独解析换行符元素'\\n',并转义原文中的引号。",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "うちの庭には二羽鶏がいます",
text: 'うちの庭には\n二羽"鶏"がいます',
},
],
},
Expand All @@ -69,7 +69,7 @@ const rag_request = {
content: [
{
type: "text",
text: '[{"word": "うち","furigana": "うち","basic_form": "うち","word_type": "名詞","word_sub_type": "普通名詞","conjungation_type": "*","conjungation_form": "*"},{"word": "の","furigana": "の","basic_form": "の","word_type": "助詞","word_sub_type": "接続助詞","conjungation_type": "*","conjungation_form": "*"},{"word": "庭","furigana": "にわ","basic_form": "庭","word_type": "名詞","word_sub_type": "普通名詞","conjungation_type": "*","conjungation_form": "*"},{"word": "に","furigana": "に","basic_form": "に","word_type": "助詞","word_sub_type": "格助詞","conjungation_type": "*","conjungation_form": "*"},{"word": "は","furigana": "は","basic_form": "は","word_type": "助詞","word_sub_type": "副助詞","conjungation_type": "*","conjungation_form": "*"},{"word": "二","furigana": "に","basic_form": "二","word_type": "名詞","word_sub_type": "数詞","conjungation_type": "*","conjungation_form": "*"},{"word": "羽","furigana": "わ","basic_form": "羽","word_type": "接尾辞","word_sub_type": "名詞性名詞助数辞","conjungation_type": "*","conjungation_form": "*"},{"word": "鶏","furigana": "にわとり","basic_form": "鶏","word_type": "名詞","word_sub_type": "普通名詞","conjungation_type": "*","conjungation_form": "*"},{"word": "が","furigana": "が","basic_form": "が","word_type": "助詞","word_sub_type": "格助詞","conjungation_type": "*","conjungation_form": "*"},{"word": "い","furigana": "い","basic_form": "いる","word_type": "動詞","word_sub_type": "非自立可能","conjungation_type": "母音動詞","conjungation_form": "基本形"},{"word": "ます","furigana": "ます","basic_form": "ます","word_type": "接尾辞","word_sub_type": "動詞性接尾辞","conjungation_type": "動詞性接尾辞ます型","conjungation_form": "基本形"}]',
text: '[{"word":"うち","yomi":"うち","basic_form":"うち","word_type":"名詞・普通名詞","conjugation":"*"},{"word":"の","yomi":"の","basic_form":"の","word_type":"助詞・接続助詞","conjugation":"*"},{"word":"庭","yomi":"にわ","basic_form":"庭","word_type":"名詞・普通名詞","conjugation":"*"},{"word":"に","yomi":"に","basic_form":"に","word_type":"助詞・格助詞","conjugation":"*"},{"word":"は","yomi":"は","basic_form":"は","word_type":"助詞・副助詞","conjugation":"*"},{"word":"\\\\n","yomi":"\\\\n","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"二","yomi":"に","basic_form":"二","word_type":"名詞・数詞","conjugation":"*"},{"word":"羽","yomi":"わ","basic_form":"羽","word_type":"接尾辞・名詞性名詞助数辞","conjugation":"*"},,{"word":"\\"","yomi":"\\"","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"鶏","yomi":"にわとり","basic_form":"鶏","word_type":"名詞・普通名詞","conjugation":"*"},,{"word":"\\"","yomi":"\\"","basic_form":"*","word_type":"補助記号","conjugation":"*"},{"word":"が","yomi":"が","basic_form":"が","word_type":"助詞・格助詞","conjugation":"*"},{"word":"い","yomi":"い","basic_form":"いる","word_type":"動詞・非自立可能","conjugation":"母音動詞+基本形"},{"word":"ます","yomi":"ます","basic_form":"ます","word_type":"接尾辞・動詞性接尾辞","conjugation":"動詞性接尾辞ます型+基本形"}]',
},
],
},
Expand All @@ -78,25 +78,7 @@ const rag_request = {
content: [
{
type: "text",
text: '"\\n',
},
],
},
{
role: "assistant",
content: [
{
type: "text",
text: '[{"word": "\\"","furigana": "\\"","basic_form": "\\"","word_type": "未定義語","word_sub_type": "その他","conjungation_type": "*","conjungation_form": "*"}{"word": "\\n","furigana": "\\n","basic_form": "\\n","word_type": "未定義語","word_sub_type": "その他","conjungation_type": "*","conjungation_form": "*"}]',
},
],
},
{
role: "user",
content: [
{
type: "text",
text: "青空に\nたくさんの気球が\n浮かんでいた",
text: "青空に、\nたくさんの気球が、\n浮かんでいた。",
},
],
},
Expand Down Expand Up @@ -142,22 +124,27 @@ async function parseSemantics(
result.message = "找不到 Anthropic API Key";
}

rag_request.messages[4].content[0].text = distillText(input);
rag_request.messages[2].content[0].text = distillText(input);
await instance
.post("/v1/messages", rag_request)
.then(res => {
const data = res.data as ClaudeMessage;
const response = data.content[0].text;
if (!response) {
result.status = AnthropicStatusCode.JSON_PARSE_ERROR;
result.message = "解析模型返回失败,请告诉开发帕鲁哪一句出了问题";
result.status = AnthropicStatusCode.OTHER;
result.message = "模型未返回结果,请告诉开发帕鲁哪一句出了问题";
return result;
}
result.tokens = JSON.parse(response) as SemanticUnit[];
})
.catch((e: AxiosError) => {
result.status = AnthropicStatusCode.API_ERROR;
result.message = "未知错误:" + e.message;
if (e.message.includes("property value in JSON at position")) {
result.status = AnthropicStatusCode.JSON_PARSE_ERROR;
result.message = "解析模型返回失败,请告诉开发帕鲁哪一句出了问题";
} else {
result.status = AnthropicStatusCode.API_ERROR;
result.message = "未知错误:" + e.message;
}
return result;
});

Expand Down
17 changes: 17 additions & 0 deletions lib/ba-story-player/lib/layers/l2dLayer/l2dConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,4 +1265,21 @@ export const l2dConfig: IL2dConfig = {
},
otherSpine: [],
},
Hoshino_home: {
name: "Hoshino_home",
playQue: [
{
name: "Hoshino_home",
animation: "Start_Idle_01",
fadeTime: 4.7,
fade: true,
},
],
spineSettings: {
Hoshino_home: {
scale: 1.0,
},
},
otherSpine: [],
},
};

0 comments on commit 7b6d590

Please sign in to comment.