Skip to content

Commit 6940395

Browse files
authored
[feat] [sdk] bump @cozeloop/ai to 0.0.8 (#16)
* feat(cozeloop-ai): prompt hub with label * feat(example): add with-label * feat(example): upgrade tsx * feat(cozeloop-ai): bump to 0.0.8
1 parent 9d33364 commit 6940395

19 files changed

Lines changed: 243 additions & 205 deletions

File tree

common/config/rush/pnpm-lock.yaml

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

examples/cozeloop-ai-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@types/node": "^20",
2626
"dotenv": "~16.4.7",
2727
"msw": "^2.7.3",
28-
"tsx": "^4.19.3",
28+
"tsx": "^4.20.5",
2929
"typescript": "^5.5.3"
3030
}
3131
}

examples/cozeloop-ai-node/src/api/api-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export async function run() {
3636
});
3737

3838
assert.strictEqual(resp.code, 0);
39+
process.exit(0);
3940
}

examples/cozeloop-ai-node/src/auth/oauth-jwt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export async function run() {
1919
const tokenResp = await authFlow.getToken();
2020

2121
assert.ok(tokenResp.access_token);
22+
process.exit(0);
2223
}

examples/cozeloop-ai-node/src/practice/travel-plan.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async function run() {
9090
console.info(result);
9191
// The trace reporting is asynchronous and has some latency.
9292
// If **running local files directly**, a short delay is required to ensure successful reporting.
93+
process.exit(0);
9394
}
9495

9596
run();
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { run as runMultiPart } from './with-multi-part';
2+
import { run as runWithLabel } from './with-label';
23
import { run as runWithJinja } from './with-jinja';
34
import { run as runBasic } from './hub';
45

56
export async function run() {
6-
await Promise.all([runBasic(), runWithJinja(), runMultiPart()]);
7+
await Promise.all([
8+
runBasic(),
9+
runWithJinja(),
10+
runMultiPart(),
11+
runWithLabel(),
12+
]);
713

814
process.exit(0);
915
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 with label
16+
const key = 'loop';
17+
const version = undefined;
18+
const label = 'beta';
19+
const prompt = await hub.getPrompt(key, version, label);
20+
// {
21+
// workspace_id: '7308703665823416358',
22+
// prompt_key: 'loop',
23+
// version: '0.0.2',
24+
// prompt_template: {
25+
// template_type: 'jinja2',
26+
// messages: [
27+
// {
28+
// role: 'system',
29+
// content: 'You are a helpful bot, the conversation topic is {{var1}}.',
30+
// },
31+
// { role: 'placeholder', content: 'placeholder1' },
32+
// { role: 'user', content: 'My question is {{var2}}' },
33+
// { role: 'placeholder', content: 'placeholder2' },
34+
// { role: 'user', content: '' },
35+
// ],
36+
// variable_defs: [
37+
// { key: 'var1', desc: '', type: 'string' },
38+
// { key: 'var2', desc: '', type: 'string' },
39+
// { desc: '', type: 'multi_part', key: 'img1' },
40+
// { key: 'placeholder1', desc: '', type: 'placeholder' },
41+
// { key: 'placeholder2', desc: '', type: 'placeholder' },
42+
// ],
43+
// },
44+
// llm_config: {
45+
// temperature: 1,
46+
// max_tokens: 4096,
47+
// top_p: 0.7,
48+
// frequency_penalty: 0,
49+
// },
50+
// }
51+
52+
assert.strictEqual(prompt?.prompt_key, key);
53+
assert.strictEqual(prompt.version, '0.0.2');
54+
55+
// 2. formatPrompt with variables
56+
const variables: PromptVariables = {
57+
var1: 'value_of_var1',
58+
var2: 'value_of_var2',
59+
var3: 'value_of_var3',
60+
placeholder1: { role: 'assistant', content: 'user' },
61+
};
62+
const messages = hub.formatPrompt(prompt, variables);
63+
// [
64+
// {
65+
// role: 'system',
66+
// content:
67+
// 'You are a helpful bot, the conversation topic is value_of_var1.',
68+
// },
69+
// { role: 'assistant', content: 'user' },
70+
// { role: 'user', content: 'My question is value_of_var2' },
71+
// { role: 'user', content: '' },
72+
// ]
73+
assert.ok(messages.length);
74+
}
75+
76+
run();

examples/cozeloop-ai-node/src/tracer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ export async function run() {
2828
runLargeText(),
2929
runTransferBetweenServices(),
3030
]);
31+
process.exit(0);
3132
}

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.8
4+
* PromptHub: get prompt with label
5+
36
## 0.0.7
47
* PromptHub: multi-modal variable in template
58

packages/cozeloop-ai/__tests__/__mock__/prompt-hub.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ const multipartPrompt = {
105105
},
106106
};
107107

108+
const betaPrompt = {
109+
query: { prompt_key: 'loop', label: 'beta' },
110+
prompt: {
111+
workspace_id: '7308703665823416358',
112+
prompt_key: 'loop',
113+
version: '0.0.2',
114+
prompt_template: {
115+
template_type: 'normal',
116+
messages: [],
117+
variable_defs: [],
118+
},
119+
llm_config: {
120+
temperature: 1,
121+
max_tokens: 4096,
122+
top_p: 0.7,
123+
frequency_penalty: 0,
124+
},
125+
},
126+
};
127+
108128
export function setupPromptHubMock() {
109129
const mockServer = setupServer(
110130
http.post(/\/v1\/loop\/prompts\/mget/, req => {
@@ -116,6 +136,8 @@ export function setupPromptHubMock() {
116136
return successResp({ items: [normalPrompt] });
117137
case 'multi-part':
118138
return successResp({ items: [multipartPrompt] });
139+
case 'beta-label':
140+
return successResp({ items: [betaPrompt] });
119141
default:
120142
return passthrough();
121143
}

0 commit comments

Comments
 (0)