Skip to content

Commit 9d33364

Browse files
authored
[feat] [sdk] bump @cozeloop/ai to 0.0.7 (#15)
* feat: upgrade zod * feat(cozeloop-ai): multi-part variables in prompt * feat(example): add with-multi-part * feat(cozeloop-ai): bump to 0.0.7 * feat(cozeloop-ai): increment ut
1 parent 7b172ca commit 9d33364

File tree

28 files changed

+1037
-199
lines changed

28 files changed

+1037
-199
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@ dist-storybook/
123123

124124
*.tsbuildinfo
125125
.eslintcache
126+
127+
.coda

common/config/rush/pnpm-lock.yaml

Lines changed: 46 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { run as runMultiPart } from './with-multi-part';
12
import { run as runWithJinja } from './with-jinja';
23
import { run as runBasic } from './hub';
34

45
export async function run() {
5-
await Promise.all([runBasic(), runWithJinja()]);
6+
await Promise.all([runBasic(), runWithJinja(), runMultiPart()]);
67

78
process.exit(0);
89
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import assert from 'node:assert';
2+
3+
import { type PromptVariables, PromptHub } from '@cozeloop/ai';
4+
5+
export async function run() {
6+
const hub = new PromptHub({
7+
/** workspace id, use process.env.COZELOOP_WORKSPACE_ID when unprovided */
8+
// workspaceId: 'your_workspace_id',
9+
apiClient: {
10+
// baseURL: 'api_base_url',
11+
// token: 'your_api_token',
12+
},
13+
});
14+
15+
// 1. getPrompt
16+
const key = 'loop';
17+
const version = '0.0.3';
18+
const prompt = await hub.getPrompt(key, version);
19+
// {
20+
// workspace_id: '7308703665823416358',
21+
// prompt_key: 'loop',
22+
// version: '0.0.3',
23+
// prompt_template: {
24+
// template_type: 'normal',
25+
// messages: [
26+
// {
27+
// role: 'system',
28+
// content: 'You are a helpful bot, the conversation topic is {{var1}}.',
29+
// },
30+
// { role: 'placeholder', content: 'placeholder1' },
31+
// { content: 'My question is {{var2}}', role: 'user' },
32+
// { role: 'placeholder', content: 'placeholder2' },
33+
// {
34+
// role: 'user',
35+
// content: '',
36+
// parts: [
37+
// { type: 'text', text: 'text2{{var2}}\n' },
38+
// { type: 'multi_part_variable', text: 'img1' },
39+
// { type: 'text', text: '\ntext3{{var3}}' },
40+
// ],
41+
// },
42+
// ],
43+
// variable_defs: [
44+
// { key: 'var1', desc: '', type: 'string' },
45+
// { key: 'var2', desc: '', type: 'string' },
46+
// { key: 'var3', desc: '', type: 'string' },
47+
// { key: 'img1', desc: '', type: 'multi_part' },
48+
// { key: 'placeholder1', desc: '', type: 'placeholder' },
49+
// { desc: '', type: 'placeholder', key: 'placeholder2' },
50+
// ],
51+
// },
52+
// llm_config: {
53+
// temperature: 1,
54+
// max_tokens: 4096,
55+
// top_p: 0.7,
56+
// frequency_penalty: 0,
57+
// },
58+
// }
59+
60+
assert.strictEqual(prompt?.prompt_key, key);
61+
assert.strictEqual(prompt.version, version);
62+
63+
// 2. formatPrompt with variables
64+
const variables: PromptVariables = {
65+
var1: 'value_of_var1',
66+
var2: 'value_of_var2',
67+
var3: 'value_of_var3',
68+
placeholder1: { role: 'assistant', content: 'user' },
69+
img1: [
70+
{ type: 'text', text: 'text' },
71+
{
72+
type: 'image_url',
73+
image_url: { url: 'https://expample.com/dot.png' },
74+
},
75+
],
76+
};
77+
const messages = hub.formatPrompt(prompt, variables);
78+
// [
79+
// {
80+
// role: 'system',
81+
// content:
82+
// 'You are a helpful bot, the conversation topic is value_of_var1.',
83+
// },
84+
// {
85+
// role: 'assistant',
86+
// content: 'user',
87+
// },
88+
// {
89+
// role: 'user',
90+
// content: 'My question is value_of_var2',
91+
// },
92+
// {
93+
// role: 'user',
94+
// content: '',
95+
// parts: [
96+
// {
97+
// type: 'text',
98+
// text: 'text2value_of_var2\n',
99+
// },
100+
// {
101+
// type: 'text',
102+
// text: 'text',
103+
// },
104+
// {
105+
// type: 'image_url',
106+
// image_url: {
107+
// url: 'https://expample.com/dot.png',
108+
// },
109+
// },
110+
// {
111+
// type: 'text',
112+
// text: '\ntext3value_of_var3',
113+
// },
114+
// ],
115+
// },
116+
// ]
117+
assert.ok(messages.length);
118+
}
119+
120+
run();

packages/ci-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dependencies": {
3838
"@larksuiteoapi/node-sdk": "^1.50.1",
3939
"commander": "^14.0.0",
40-
"zod": "^3.25.67"
40+
"zod": "^4.1.3"
4141
},
4242
"devDependencies": {
4343
"@loop-infra/eslint-config": "workspace:*",

packages/ci-tools/src/lark/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
22
// SPDX-License-Identifier: MIT
3-
import { z } from 'zod/v4';
3+
import { z } from 'zod';
44
import { AppType, Domain } from '@larksuiteoapi/node-sdk';
55

66
export const larkOptionSchema = z.object({

packages/cozeloop-ai/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 🕗 ChangeLog - @cozeloop/ai
22

3+
## 0.0.7
4+
* PromptHub: multi-modal variable in template
5+
36
## 0.0.6
47
* PromptHub: support prompt with Jinja2 template type
58

0 commit comments

Comments
 (0)