Skip to content

Commit 00252a8

Browse files
committed
fix: add tag based on the PromptOutputType, #2
1 parent e60643b commit 00252a8

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function main() {
2424
apiKey,
2525
basePath,
2626
model: modelName,
27-
tag,
27+
tag: tagName,
2828
} = logseq.settings as unknown as ISettings;
29+
const tag = ` #${tagName}`;
2930

3031
const prompts = getPrompts();
3132
const model = new OpenAI(
@@ -79,7 +80,7 @@ function main() {
7980

8081
switch (output) {
8182
case PromptOutputType.property: {
82-
let content = `${block?.content} #${tag}\n`;
83+
let content = `${block?.content}${tag}\n`;
8384

8485
if (!parser) {
8586
content += `${name.toLowerCase()}:: ${response}`;
@@ -99,18 +100,22 @@ function main() {
99100
break;
100101
}
101102
case PromptOutputType.insert: {
102-
await logseq.Editor.updateBlock(
103-
uuid,
104-
`${block?.content} #${tag}\n`,
105-
);
106103
if (!parser) {
107-
await logseq.Editor.insertBlock(uuid, response);
104+
await logseq.Editor.insertBlock(uuid, `${response}${tag}`);
108105
} else if (structured) {
109106
const record = await parser.parse(response);
107+
await logseq.Editor.updateBlock(
108+
uuid,
109+
`${block?.content}${tag}\n`,
110+
);
110111
for await (const [key, value] of Object.entries(record)) {
111112
await logseq.Editor.insertBlock(uuid, `${key}: ${value}`);
112113
}
113114
} else if (listed) {
115+
await logseq.Editor.updateBlock(
116+
uuid,
117+
`${block?.content}${tag}\n`,
118+
);
114119
const record = (await parser.parse(response)) as string[];
115120
for await (const item of record) {
116121
await logseq.Editor.insertBlock(uuid, item);
@@ -119,7 +124,7 @@ function main() {
119124
break;
120125
}
121126
case PromptOutputType.replace:
122-
await logseq.Editor.updateBlock(uuid, `${response} #${tag}`);
127+
await logseq.Editor.updateBlock(uuid, `${response}${tag}`);
123128
break;
124129
}
125130
},

0 commit comments

Comments
 (0)