Skip to content

Commit 0dcd5ee

Browse files
authored
improvement(mem0) (#311)
* improvement(mem0): slider value * improvement: removed unused/unnecessary parameters and reorganized block
1 parent cc6299c commit 0dcd5ee

File tree

8 files changed

+139
-49
lines changed

8 files changed

+139
-49
lines changed

sim/app/w/[id]/components/workflow-block/components/sub-block/components/slider-input.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface SliderInputProps {
88
defaultValue: number
99
blockId: string
1010
subBlockId: string
11+
step?: number
12+
integer?: boolean
1113
}
1214

1315
export function SliderInput({
@@ -16,6 +18,8 @@ export function SliderInput({
1618
defaultValue,
1719
blockId,
1820
subBlockId,
21+
step = 0.1,
22+
integer = false,
1923
}: SliderInputProps) {
2024
const [value, setValue] = useSubBlockValue<number>(blockId, subBlockId)
2125

@@ -26,12 +30,14 @@ export function SliderInput({
2630
// If value exceeds max, scale it down proportionally
2731
if (value > max) {
2832
const prevMax = Math.max(max * 2, value) // Assume previous max was at least the current value
29-
return (value / prevMax) * max
33+
const scaledValue = (value / prevMax) * max
34+
return integer ? Math.round(scaledValue) : scaledValue
3035
}
3136

3237
// Otherwise just clamp it
33-
return Math.min(Math.max(value, min), max)
34-
}, [value, min, max, defaultValue])
38+
const clampedValue = Math.min(Math.max(value, min), max)
39+
return integer ? Math.round(clampedValue) : clampedValue
40+
}, [value, min, max, defaultValue, integer])
3541

3642
// Update the value if it needs normalization
3743
useEffect(() => {
@@ -46,8 +52,8 @@ export function SliderInput({
4652
value={[normalizedValue]}
4753
min={min}
4854
max={max}
49-
step={0.1}
50-
onValueChange={(value) => setValue(value[0])}
55+
step={integer ? 1 : step}
56+
onValueChange={(value) => setValue(integer ? Math.round(value[0]) : value[0])}
5157
className="[&_[role=slider]]:h-4 [&_[role=slider]]:w-4 [&_[class*=SliderTrack]]:h-1"
5258
/>
5359
<div
@@ -62,7 +68,7 @@ export function SliderInput({
6268
top: '24px',
6369
}}
6470
>
65-
{Number(normalizedValue).toFixed(1)}
71+
{integer ? Math.round(normalizedValue).toString() : Number(normalizedValue).toFixed(1)}
6672
</div>
6773
</div>
6874
)

sim/app/w/[id]/components/workflow-block/components/sub-block/sub-block.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { DateInput } from './components/date-input'
1212
import { Dropdown } from './components/dropdown'
1313
import { EvalInput } from './components/eval-input'
1414
import { FileSelectorInput } from './components/file-selector/file-selector-input'
15-
import { ProjectSelectorInput } from './components/project-selector/project-selector-input'
1615
import { FileUpload } from './components/file-upload'
1716
import { FolderSelectorInput } from './components/folder-selector/components/folder-selector-input'
1817
import { LongInput } from './components/long-input'
18+
import { ProjectSelectorInput } from './components/project-selector/project-selector-input'
1919
import { ScheduleConfig } from './components/schedule/schedule-config'
2020
import { ShortInput } from './components/short-input'
2121
import { SliderInput } from './components/slider-input'
@@ -90,6 +90,8 @@ export function SubBlock({ blockId, config, isConnecting }: SubBlockProps) {
9090
min={config.min}
9191
max={config.max}
9292
defaultValue={(config.min || 0) + ((config.max || 100) - (config.min || 0)) / 2}
93+
step={config.step}
94+
integer={config.integer}
9395
/>
9496
)
9597
case 'table':

sim/blocks/blocks/mem0.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,14 @@ export const Mem0Block: BlockConfig<Mem0Response> = {
2424
],
2525
placeholder: 'Select an operation',
2626
},
27-
{
28-
id: 'limit',
29-
title: 'Result Limit',
30-
type: 'slider',
31-
layout: 'full',
32-
min: 1,
33-
max: 50,
34-
condition: {
35-
field: 'operation',
36-
value: ['search', 'get'],
37-
},
38-
},
3927
{
4028
id: 'userId',
4129
title: 'User ID',
4230
type: 'short-input',
43-
layout: 'half',
31+
layout: 'full',
4432
placeholder: 'Enter user identifier',
4533
value: () => 'userid', // Default to the working user ID from curl example
4634
},
47-
{
48-
id: 'version',
49-
title: 'API Version',
50-
type: 'dropdown',
51-
layout: 'half',
52-
options: [
53-
{ label: 'v2 (Default)', id: 'v2' },
54-
{ label: 'v1', id: 'v1' }
55-
],
56-
},
5735
{
5836
id: 'messages',
5937
title: 'Messages',
@@ -118,6 +96,20 @@ export const Mem0Block: BlockConfig<Mem0Response> = {
11896
placeholder: 'Enter your Mem0 API key',
11997
password: true,
12098
},
99+
{
100+
id: 'limit',
101+
title: 'Result Limit',
102+
type: 'slider',
103+
layout: 'full',
104+
min: 1,
105+
max: 50,
106+
step: 1,
107+
integer: true,
108+
condition: {
109+
field: 'operation',
110+
value: ['search', 'get'],
111+
},
112+
},
121113
],
122114
tools: {
123115
access: [

sim/blocks/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export interface SubBlockConfig {
123123
acceptedTypes?: string
124124
multiple?: boolean
125125
maxSize?: number
126+
// Slider-specific properties
127+
step?: number
128+
integer?: boolean
126129
}
127130

128131
// Main block definition

sim/package-lock.json

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

sim/tools/mem0/add_memories.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ export const mem0AddMemoriesTool: ToolConfig = {
2222
required: true,
2323
description: 'Array of message objects with role and content',
2424
},
25-
version: {
26-
type: 'string',
27-
required: false,
28-
default: 'v2',
29-
description: 'API version to use (v1 or v2). Use v2 if unsure.',
30-
},
3125
},
3226
request: {
3327
url: 'https://api.mem0.ai/v1/memories/',
@@ -61,7 +55,7 @@ export const mem0AddMemoriesTool: ToolConfig = {
6155
// Prepare request body
6256
const body: Record<string, any> = {
6357
messages: messagesArray,
64-
version: params.version || 'v2',
58+
version: 'v2',
6559
user_id: params.userId
6660
}
6761

sim/tools/mem0/get_memories.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ export const mem0GetMemoriesTool: ToolConfig = {
3838
default: 10,
3939
description: 'Maximum number of results to return',
4040
},
41-
version: {
42-
type: 'string',
43-
required: false,
44-
default: 'v2',
45-
description: 'API version to use (v1 or v2). Use v2 if unsure.',
46-
},
4741
},
4842
request: {
4943
url: (params: Record<string, any>) => {

sim/tools/mem0/search_memories.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ export const mem0SearchMemoriesTool: ToolConfig = {
2828
default: 10,
2929
description: 'Maximum number of results to return',
3030
},
31-
version: {
32-
type: 'string',
33-
required: false,
34-
default: 'v2',
35-
description: 'API version to use (v1 or v2). Use v2 if unsure.',
36-
},
3731
},
3832
request: {
3933
url: 'https://api.mem0.ai/v2/memories/search/',

0 commit comments

Comments
 (0)