Spaces:
Running
Running
Dropdown for enum parameters.
Browse files- server/lynxscribe_ops.py +1 -1
- server/networkx_ops.py +0 -2
- server/ops.py +10 -1
- server/pytorch_model_ops.py +1 -1
- server/workspace.py +0 -1
- web/src/LynxKiteFlow.svelte +6 -1
- web/src/NodeWithParams.svelte +18 -3
server/lynxscribe_ops.py
CHANGED
|
@@ -4,7 +4,7 @@ from .ops import register_passive_op, Parameter as P
|
|
| 4 |
register_passive_op('Scrape documents', inputs={}, params=[P('url', '')])
|
| 5 |
register_passive_op('Extract graph')
|
| 6 |
register_passive_op('Compute embeddings')
|
| 7 |
-
register_passive_op('Vector DB', params=[P('backend', 'FAISS')])
|
| 8 |
register_passive_op('Chat UI', outputs={})
|
| 9 |
register_passive_op('Chat backend', inputs={})
|
| 10 |
register_passive_op('WhatsApp', inputs={})
|
|
|
|
| 4 |
register_passive_op('Scrape documents', inputs={}, params=[P('url', '')])
|
| 5 |
register_passive_op('Extract graph')
|
| 6 |
register_passive_op('Compute embeddings')
|
| 7 |
+
register_passive_op('Vector DB', params=[P.options('backend', ['FAISS', 'ANN', 'HNSW'])])
|
| 8 |
register_passive_op('Chat UI', outputs={})
|
| 9 |
register_passive_op('Chat backend', inputs={})
|
| 10 |
register_passive_op('WhatsApp', inputs={})
|
server/networkx_ops.py
CHANGED
|
@@ -37,8 +37,6 @@ for (name, func) in nx.__dict__.items():
|
|
| 37 |
# No annotation, no default — we must guess the type.
|
| 38 |
if len(k) == 1:
|
| 39 |
params[k] = 1
|
| 40 |
-
if name == 'ladder_graph':
|
| 41 |
-
print(params)
|
| 42 |
name = "NX › " + name.replace('_', ' ').title()
|
| 43 |
op = ops.Op(wrapped(func), name, params=params, inputs=inputs, outputs={'output': 'yes'}, type='basic')
|
| 44 |
ops.ALL_OPS[name] = op
|
|
|
|
| 37 |
# No annotation, no default — we must guess the type.
|
| 38 |
if len(k) == 1:
|
| 39 |
params[k] = 1
|
|
|
|
|
|
|
| 40 |
name = "NX › " + name.replace('_', ' ').title()
|
| 41 |
op = ops.Op(wrapped(func), name, params=params, inputs=inputs, outputs={'output': 'yes'}, type='basic')
|
| 42 |
ops.ALL_OPS[name] = op
|
server/ops.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
'''API for implementing LynxKite operations.'''
|
| 2 |
import dataclasses
|
|
|
|
| 3 |
import functools
|
| 4 |
import inspect
|
| 5 |
import networkx as nx
|
|
@@ -16,14 +17,22 @@ class Parameter:
|
|
| 16 |
default: any
|
| 17 |
type: PARAM_TYPE = None
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def __post_init__(self):
|
| 20 |
if self.type is None:
|
| 21 |
self.type = type(self.default)
|
| 22 |
def to_json(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return {
|
| 24 |
'name': self.name,
|
| 25 |
'default': self.default,
|
| 26 |
-
'type':
|
| 27 |
}
|
| 28 |
|
| 29 |
@dataclasses.dataclass
|
|
|
|
| 1 |
'''API for implementing LynxKite operations.'''
|
| 2 |
import dataclasses
|
| 3 |
+
import enum
|
| 4 |
import functools
|
| 5 |
import inspect
|
| 6 |
import networkx as nx
|
|
|
|
| 17 |
default: any
|
| 18 |
type: PARAM_TYPE = None
|
| 19 |
|
| 20 |
+
@staticmethod
|
| 21 |
+
def options(name, options):
|
| 22 |
+
return Parameter(name, options[0], enum.Enum(f'OptionsFor{name}', options))
|
| 23 |
+
|
| 24 |
def __post_init__(self):
|
| 25 |
if self.type is None:
|
| 26 |
self.type = type(self.default)
|
| 27 |
def to_json(self):
|
| 28 |
+
if isinstance(self.type, type) and issubclass(self.type, enum.Enum):
|
| 29 |
+
t = {'enum': list(self.type.__members__.keys())}
|
| 30 |
+
else:
|
| 31 |
+
t = str(self.type)
|
| 32 |
return {
|
| 33 |
'name': self.name,
|
| 34 |
'default': self.default,
|
| 35 |
+
'type': t,
|
| 36 |
}
|
| 37 |
|
| 38 |
@dataclasses.dataclass
|
server/pytorch_model_ops.py
CHANGED
|
@@ -32,7 +32,7 @@ def register_layer(name):
|
|
| 32 |
return decorator
|
| 33 |
|
| 34 |
@register_layer('LayerNorm')
|
| 35 |
-
def
|
| 36 |
return 'LayerNorm'
|
| 37 |
|
| 38 |
@register_layer('Dropout')
|
|
|
|
| 32 |
return decorator
|
| 33 |
|
| 34 |
@register_layer('LayerNorm')
|
| 35 |
+
def layernorm():
|
| 36 |
return 'LayerNorm'
|
| 37 |
|
| 38 |
@register_layer('Dropout')
|
server/workspace.py
CHANGED
|
@@ -42,7 +42,6 @@ class Workspace(BaseConfig):
|
|
| 42 |
def execute(ws):
|
| 43 |
# Nodes are responsible for interpreting/executing their child nodes.
|
| 44 |
nodes = [n for n in ws.nodes if not n.parentNode]
|
| 45 |
-
print(nodes)
|
| 46 |
children = {}
|
| 47 |
for n in ws.nodes:
|
| 48 |
if n.parentNode:
|
|
|
|
| 42 |
def execute(ws):
|
| 43 |
# Nodes are responsible for interpreting/executing their child nodes.
|
| 44 |
nodes = [n for n in ws.nodes if not n.parentNode]
|
|
|
|
| 45 |
children = {}
|
| 46 |
for n in ws.nodes:
|
| 47 |
if n.parentNode:
|
web/src/LynxKiteFlow.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
<script lang="ts">
|
|
|
|
| 2 |
import { writable, derived } from 'svelte/store';
|
| 3 |
import {
|
| 4 |
SvelteFlow,
|
|
@@ -139,9 +140,13 @@
|
|
| 139 |
|| e.targetHandle !== connection.targetHandle);
|
| 140 |
});
|
| 141 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
function nodeClick(e) {
|
| 143 |
const node = e.detail.node;
|
| 144 |
-
const meta =
|
| 145 |
if (!meta) return;
|
| 146 |
const sub_nodes = meta.sub_nodes;
|
| 147 |
if (!sub_nodes) return;
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { setContext } from 'svelte';
|
| 3 |
import { writable, derived } from 'svelte/store';
|
| 4 |
import {
|
| 5 |
SvelteFlow,
|
|
|
|
| 140 |
|| e.targetHandle !== connection.targetHandle);
|
| 141 |
});
|
| 142 |
}
|
| 143 |
+
function getMeta(title) {
|
| 144 |
+
return $boxes.find((m) => m.data.title === title);
|
| 145 |
+
}
|
| 146 |
+
setContext('LynxKiteFlow', { getMeta });
|
| 147 |
function nodeClick(e) {
|
| 148 |
const node = e.detail.node;
|
| 149 |
+
const meta = getMeta(node.data.title);
|
| 150 |
if (!meta) return;
|
| 151 |
const sub_nodes = meta.sub_nodes;
|
| 152 |
if (!sub_nodes) return;
|
web/src/NodeWithParams.svelte
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
<script lang="ts">
|
|
|
|
| 2 |
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
| 3 |
import LynxKiteNode from './LynxKiteNode.svelte';
|
| 4 |
type $$Props = NodeProps;
|
| 5 |
export let id: $$Props['id'];
|
| 6 |
export let data: $$Props['data'];
|
| 7 |
const { updateNodeData } = useSvelteFlow();
|
|
|
|
|
|
|
| 8 |
</script>
|
| 9 |
|
| 10 |
<LynxKiteNode {...$$props}>
|
|
@@ -12,10 +15,21 @@
|
|
| 12 |
<div class="param">
|
| 13 |
<label>
|
| 14 |
{name}<br>
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
value={value}
|
| 17 |
on:input={(evt) => updateNodeData(id, { params: { ...data.params, [name]: evt.currentTarget.value } })}
|
| 18 |
-
|
|
|
|
| 19 |
</label>
|
| 20 |
</div>
|
| 21 |
{/each}
|
|
@@ -28,7 +42,8 @@
|
|
| 28 |
font-size: 12px;
|
| 29 |
display: block;
|
| 30 |
}
|
| 31 |
-
.param input
|
|
|
|
| 32 |
width: calc(100% - 8px);
|
| 33 |
}
|
| 34 |
</style>
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { getContext } from 'svelte';
|
| 3 |
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
| 4 |
import LynxKiteNode from './LynxKiteNode.svelte';
|
| 5 |
type $$Props = NodeProps;
|
| 6 |
export let id: $$Props['id'];
|
| 7 |
export let data: $$Props['data'];
|
| 8 |
const { updateNodeData } = useSvelteFlow();
|
| 9 |
+
$: meta = getContext('LynxKiteFlow').getMeta(data.title);
|
| 10 |
+
$: metaParams = Object.fromEntries(meta.data.params.map((p) => [p.name, p]));
|
| 11 |
</script>
|
| 12 |
|
| 13 |
<LynxKiteNode {...$$props}>
|
|
|
|
| 15 |
<div class="param">
|
| 16 |
<label>
|
| 17 |
{name}<br>
|
| 18 |
+
{#if metaParams[name].type.enum}
|
| 19 |
+
<select
|
| 20 |
+
value={value}
|
| 21 |
+
on:change={(evt) => updateNodeData(id, { params: { ...data.params, [name]: evt.currentTarget.value } })}
|
| 22 |
+
>
|
| 23 |
+
{#each metaParams[name].type.enum as option}
|
| 24 |
+
<option value={option}>{option}</option>
|
| 25 |
+
{/each}
|
| 26 |
+
</select>
|
| 27 |
+
{:else}
|
| 28 |
+
<input
|
| 29 |
value={value}
|
| 30 |
on:input={(evt) => updateNodeData(id, { params: { ...data.params, [name]: evt.currentTarget.value } })}
|
| 31 |
+
/>
|
| 32 |
+
{/if}
|
| 33 |
</label>
|
| 34 |
</div>
|
| 35 |
{/each}
|
|
|
|
| 42 |
font-size: 12px;
|
| 43 |
display: block;
|
| 44 |
}
|
| 45 |
+
.param input,
|
| 46 |
+
.param select {
|
| 47 |
width: calc(100% - 8px);
|
| 48 |
}
|
| 49 |
</style>
|