Skip to content

Commit 0fcad62

Browse files
authored
[fix] [prompt] placeholder var name (#15)
* fix(prompt): placeholder var name * doc(intl): readme
1 parent a254696 commit 0fcad62

2 files changed

Lines changed: 13 additions & 75 deletions

File tree

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,3 @@
1-
# @cozeloop/i18n-adapter
1+
# @cozeloop/intl
22

3-
I18n For CozeLoop
4-
5-
## Overview
6-
7-
This package is part of the Coze Loop monorepo and provides internationalization functionality. It includes adapter.
8-
9-
## Getting Started
10-
11-
### Installation
12-
13-
Add this package to your `package.json`:
14-
15-
```json
16-
{
17-
"dependencies": {
18-
"@cozeloop/i18n-adapter": "workspace:*"
19-
}
20-
}
21-
```
22-
23-
Then run:
24-
25-
```bash
26-
rush update
27-
```
28-
29-
### Usage
30-
31-
```typescript
32-
import { /* exported functions/components */ } from '@cozeloop/i18n-adapter';
33-
34-
// Example usage
35-
// TODO: Add specific usage examples
36-
```
37-
38-
## Features
39-
40-
- Adapter
41-
42-
## API Reference
43-
44-
### Exports
45-
46-
- `initIntl, I18n`
47-
48-
49-
For detailed API documentation, please refer to the TypeScript definitions.
50-
51-
## Development
52-
53-
This package is built with:
54-
55-
- TypeScript
56-
- Modern JavaScript
57-
- Vitest for testing
58-
- ESLint for code quality
59-
60-
## Contributing
61-
62-
This package is part of the Coze Loop monorepo. Please follow the monorepo contribution guidelines.
63-
64-
## License
65-
66-
Apache-2.0
3+
Internationalization(intl) runtime for CozeLoop

frontend/packages/cozeloop/prompt-pages/src/utils/prompt.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,22 @@ export const getInputVariablesFromPrompt = (messageList: Message[]) => {
8686

8787
const result = Array.from(resultSet);
8888

89-
const placeholderArray = messageList.filter(
90-
it => it.role === Role.Placeholder,
91-
);
9289
const array: VariableDef[] = result.map(key => ({
9390
key,
9491
type: VariableType.String,
9592
}));
9693

97-
const placeholderContentArray: VariableDef[] = placeholderArray
98-
?.filter(it => {
99-
const key = it?.content?.replace('{{', '')?.replace('}}', '');
100-
return result.every(k => k !== key);
101-
})
102-
?.map(it => ({
103-
key: it?.content?.replace('{{', '')?.replace('}}', ''),
94+
const placeholderArray = messageList.filter(
95+
it => it.role === Role.Placeholder,
96+
);
97+
const placeholderKeys = placeholderArray.map(it => it?.content);
98+
const placeholderKeysSet = new Set(placeholderKeys);
99+
const placeholderKeysArray = Array.from(placeholderKeysSet);
100+
101+
const placeholderContentArray: VariableDef[] = placeholderKeysArray
102+
?.filter(key => key && result.every(k => k !== key))
103+
?.map(key => ({
104+
key,
104105
type: VariableType.Placeholder,
105106
}));
106107

0 commit comments

Comments
 (0)