@templmf/temp-solf-lmf 0.0.49 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@templmf/temp-solf-lmf",
3
- "version": "0.0.49",
3
+ "version": "0.0.52",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,80 @@
1
+ # Prompt 编写规范自我评估问卷
2
+
3
+ 你是 [模型名/版本]。
4
+ 我需要你从自身角度总结,针对你的 prompt 编写最佳实践。
5
+ 请直接给出可复用的 prompt 片段,不要只给理论描述。
6
+
7
+ ---
8
+
9
+ ## Part 1:结构偏好
10
+
11
+ 以下四种指令结构,哪种你识别最稳定?请排序并说明原因:
12
+ - XML 标签(<rules>...</rules>)
13
+ - Markdown 标题+列表(## 规则 \n - 条目)
14
+ - 自然语言段落
15
+ - 伪代码(if/elif/else)
16
+
17
+ ---
18
+
19
+ ## Part 2:条件判断规则
20
+
21
+ 场景:我需要你根据条件决定输出格式(例如:超过50行加标记,否则不加)
22
+
23
+ 请用你最容易遵守的写法,改写以下规则:
24
+ > 如果代码超过50行且可独立运行,在lang后加[artifact];如果用户提到保存/下载,也加;否则不加。
25
+
26
+ 给出2-3种写法,标注哪种最优。
27
+
28
+ ---
29
+
30
+ ## Part 3:格式强约束
31
+
32
+ 场景:我需要你只输出 JSON,不能有任何多余内容。
33
+
34
+ 以下哪种写法对你约束力最强?请排序:
35
+ A. 只返回 JSON,不要有任何解释
36
+ B. 禁止输出 JSON 以外的任何内容
37
+ C. 输出格式:{"key": "value"}(无其他内容)
38
+ D. 你自己给出一种更好的写法
39
+
40
+ ---
41
+
42
+ ## Part 4:示例的作用
43
+
44
+ 1. 示例对你的格式遵从有帮助吗?
45
+ 2. 正例和反例都需要吗,还是只要正例?
46
+ 3. 示例放在规则前还是规则后效果更好?
47
+ 4. 给出你认为最有效的示例写法模板
48
+
49
+ ---
50
+
51
+ ## Part 5:文件/文档交付场景
52
+
53
+ 场景:我需要你输出完整可用的文件内容(代码文件、markdown文档、配置文件等)
54
+
55
+ 1. 如何提示你输出完整内容而不省略?
56
+ 2. 如何避免你在文件中间插入解释性文字?
57
+ 3. 如何让你保持文件格式的一致性(缩进、换行等)?
58
+
59
+ 请给出针对每种场景的最优 prompt 片段。
60
+
61
+ ---
62
+
63
+ ## Part 6:你的弱点
64
+
65
+ 1. 什么情况下你最容易忽略格式规则?
66
+ 2. 什么样的用户输入会让你"覆盖"掉 system prompt 的规定?
67
+ 3. 针对这些弱点,你建议我怎么在 prompt 里做防御?
68
+
69
+ ---
70
+
71
+ ## Part 7:综合输出
72
+
73
+ 基于以上所有问题,请给我生成一份针对你的 prompt 编写速查表,格式如下:
74
+
75
+ | 场景 | 推荐写法 | 避免写法 |
76
+ |------|---------|---------|
77
+ | 条件判断 | ... | ... |
78
+ | 格式强约束 | ... | ... |
79
+ | 文件交付 | ... | ... |
80
+ | 文档生成 | ... | ... |
package/api.js DELETED
@@ -1,51 +0,0 @@
1
- /**
2
- * API 配置
3
- * 在项目根目录创建 .env.local,填入以下变量:
4
- *
5
- * # 文本 LLM
6
- * VITE_API_BASE_URL=https://your-api-host.com
7
- * VITE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx
8
- * VITE_MODEL=gpt-4o
9
- *
10
- * # 多模态视觉模型(独立 endpoint / key,不填则复用上面的配置)
11
- * VITE_VL_API_BASE_URL=https://your-vl-api-host.com
12
- * VITE_VL_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx
13
- * VITE_VL_MODEL=qwen3-vl-8b-instruct-k100
14
- */
15
- export const API_CONFIG = {
16
- baseURL: import.meta.env.VITE_API_BASE_URL || 'https://api.openai.com',
17
- apiKey: import.meta.env.VITE_API_KEY || 'sk-your-key-here',
18
- model: import.meta.env.VITE_MODEL || 'gpt-4o',
19
-
20
- vlBaseURL: import.meta.env.VITE_VL_API_BASE_URL || null, // 不填则复用 baseURL
21
- vlApiKey: import.meta.env.VITE_VL_API_KEY || null, // 不填则复用 apiKey
22
- vlModel: import.meta.env.VITE_VL_MODEL || null,
23
- }
24
-
25
- /**
26
- * 根据消息内容判断是否需要视觉模型
27
- */
28
- export function isVisualRequest(messages) {
29
- return messages.some(m => {
30
- const c = m.content
31
- return Array.isArray(c) && c.some(b => b.type === 'image_url' || b.type === 'image')
32
- })
33
- }
34
-
35
- /**
36
- * 根据消息内容选择对应的请求配置(model / baseURL / apiKey)
37
- */
38
- export function selectConfig(messages) {
39
- const useVl = isVisualRequest(messages) && API_CONFIG.vlModel
40
- return useVl
41
- ? {
42
- model: API_CONFIG.vlModel,
43
- baseURL: API_CONFIG.vlBaseURL || API_CONFIG.baseURL,
44
- apiKey: API_CONFIG.vlApiKey || API_CONFIG.apiKey,
45
- }
46
- : {
47
- model: API_CONFIG.model,
48
- baseURL: API_CONFIG.baseURL,
49
- apiKey: API_CONFIG.apiKey,
50
- }
51
- }
package/chatApi.js DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * chatApi.js
3
- * 封装 OpenAI 兼容格式的流式对话接口(/v1/chat/completions)
4
- * 支持多模态 content 数组格式(图片 / 文本混合)
5
- */
6
- import { selectConfig } from '../config/api.js'
7
-
8
- /**
9
- * 发起流式对话请求
10
- * @param {object} options
11
- * @param {Array} options.messages - 消息历史,content 可为字符串或数组(多模态)
12
- * @param {Function} options.onToken - (token: string) => void
13
- * @param {Function} options.onDone - 流结束
14
- * @param {Function} options.onError - (error: Error) => void
15
- * @param {AbortSignal} options.signal
16
- */
17
- export async function streamChat({ messages, onToken, onDone, onError, signal }) {
18
- try {
19
- const { model, baseURL, apiKey } = selectConfig(messages)
20
-
21
- const res = await fetch(`${baseURL}/v1/chat/completions`, {
22
- method: 'POST',
23
- headers: {
24
- 'Content-Type': 'application/json',
25
- 'Authorization': `Bearer ${apiKey}`,
26
- },
27
- body: JSON.stringify({ model, stream: true, messages }),
28
- signal,
29
- })
30
-
31
- if (!res.ok) {
32
- const errBody = await res.text()
33
- throw new Error(`API 请求失败 ${res.status}: ${errBody}`)
34
- }
35
-
36
- const reader = res.body.getReader()
37
- const decoder = new TextDecoder('utf-8')
38
- let buffer = ''
39
-
40
- while (true) {
41
- const { done, value } = await reader.read()
42
- if (done) break
43
- buffer += decoder.decode(value, { stream: true })
44
- const lines = buffer.split('\n')
45
- buffer = lines.pop()
46
-
47
- for (const line of lines) {
48
- const trimmed = line.trim()
49
- if (!trimmed || trimmed === 'data: [DONE]') continue
50
- if (!trimmed.startsWith('data: ')) continue
51
- try {
52
- const json = JSON.parse(trimmed.slice(6))
53
- const token = json.choices?.[0]?.delta?.content
54
- if (token) onToken(token)
55
- } catch { /* 非 JSON 行跳过 */ }
56
- }
57
- }
58
- onDone?.()
59
- } catch (err) {
60
- if (err.name === 'AbortError') return
61
- onError?.(err)
62
- }
63
- }