From 27d2723023395d2ae5130d724d31cb247bf766c1 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sat, 22 Nov 2025 18:32:19 +0100 Subject: [PATCH] .. --- .zed/debug.json | 0 examples/ai/aiclient.vsh | 19 ++++++++++-- lib/ai/flow_calendar/actions.v | 9 ++++++ lib/ai/flow_calendar/start.v | 20 ++++++++++++ lib/ai/flow_calendar/triage.v | 13 ++++++++ lib/core/flows/coordinator.v | 55 +++++++++++++++++++++++++++++++++ lib/core/flows/step.v | 31 +++++++++++++++++++ lib/core/logger/log.v | 9 +++++- lib/data/paramsparser/readme.md | 1 + 9 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 .zed/debug.json create mode 100644 lib/ai/flow_calendar/actions.v create mode 100644 lib/ai/flow_calendar/start.v create mode 100644 lib/ai/flow_calendar/triage.v create mode 100644 lib/core/flows/coordinator.v create mode 100644 lib/core/flows/step.v diff --git a/.zed/debug.json b/.zed/debug.json new file mode 100644 index 00000000..e69de29b diff --git a/examples/ai/aiclient.vsh b/examples/ai/aiclient.vsh index b6811fb2..d194fd22 100755 --- a/examples/ai/aiclient.vsh +++ b/examples/ai/aiclient.vsh @@ -10,8 +10,21 @@ mut cl := client.new()! // max_completion_tokens: 1024 // )! -response := cl.llms.llm_embed_local.embed(input: [ - 'The food was delicious and the waiter..', -])! +response := cl.llms.llm_maverick.chat_completion( + message: 'Explain quantum computing in simple terms' + temperature: 0.5 + max_completion_tokens: 1024 +)! println(response) + +// response := cl.llms.llm_embed_local.embed(input: [ +// 'The food was delicious and the waiter..', +// ])! + +// response2 := cl.llms.llm_embed.embed(input: [ +// 'The food was delicious and the waiter..', +// ])! + + +println(response2) diff --git a/lib/ai/flow_calendar/actions.v b/lib/ai/flow_calendar/actions.v new file mode 100644 index 00000000..1e842789 --- /dev/null +++ b/lib/ai/flow_calendar/actions.v @@ -0,0 +1,9 @@ +module flow_calendar + +import incubaid.herolib.hero.heromodels +import incubaid.herolib.core.flows + +pub fn calendar_delete(mut s flows.Step) ! { + // get heromodels + mut m := heromodels.get('coordinator_${s.coordinator.name}')! +} diff --git a/lib/ai/flow_calendar/start.v b/lib/ai/flow_calendar/start.v new file mode 100644 index 00000000..78ac630f --- /dev/null +++ b/lib/ai/flow_calendar/start.v @@ -0,0 +1,20 @@ +module flow_calendar + +import incubaid.herolib.hero.heromodels +import incubaid.herolib.core.flows + +type CoordinatorProxy = flows.Coordinator + +pub fn (mut c CoordinatorProxy) start(prompt string) ! { + // init the heromodels, define well chosen name, needed to call later + mut m := heromodels.new(redis: c.redis, name: 'coordinator_${c.name}')! + + mut step_triage := c.step_new( + context: { + 'prompt': prompt + } + f: triage + )! + + c.run()! +} diff --git a/lib/ai/flow_calendar/triage.v b/lib/ai/flow_calendar/triage.v new file mode 100644 index 00000000..b803d3db --- /dev/null +++ b/lib/ai/flow_calendar/triage.v @@ -0,0 +1,13 @@ +module flow_calendar + +import incubaid.herolib.hero.heromodels +import incubaid.herolib.core.flows + +pub fn triage(mut s flows.Step) ! { + prompt := s.context['prompt'] or { panic("can't find prompt context in step:\n${s}") } + response := s.coordinator.ai.llms.llm_maverick.chat_completion( + message: 'Explain quantum computing in simple terms' + temperature: 0.5 + max_completion_tokens: 1024 + )! +} diff --git a/lib/core/flows/coordinator.v b/lib/core/flows/coordinator.v new file mode 100644 index 00000000..30cf1d28 --- /dev/null +++ b/lib/core/flows/coordinator.v @@ -0,0 +1,55 @@ +module flows + +// __global ( +// contexts map[u32]&Context +// context_current u32 +// ) +// +// +import incubaid.herolib.core.logger +import incubaid.herolib.ai.client as aiclient +import incubaid.herolib.core.redisclient +import incubaid.herolib.data.paramsparser + +pub struct Coordinator { +pub mut: + name string + steps map[string]Step + logger logger.Logger + ai aiclient.AIClient + redis ?&redisclient.Redis +} + +pub fn new() !Coordinator { + return Coordinator{ + logger: logger.new(path: '/tmp/flowlogger')! + ai: aiclient.new()! + } +} + +@[params] +pub struct StepNewArgs { +pub mut: + name string + description string + f fn (mut s Step) ! @[required] + context map[string]string + error_steps []Step + next_steps []Step + error string + params paramsparser.Params +} + +// add step to it +pub fn (mut c Coordinator) step_new(args StepNewArgs) !Step { + return Step{ + coordinator: &c + name: args.name + description: args.description + main_step: args.f + error_steps: args.error_steps + next_steps: args.next_steps + error: args.error + params: args.params + } +} diff --git a/lib/core/flows/step.v b/lib/core/flows/step.v new file mode 100644 index 00000000..02b08f30 --- /dev/null +++ b/lib/core/flows/step.v @@ -0,0 +1,31 @@ +module flows + +import incubaid.herolib.data.paramsparser +import incubaid.herolib.core.logger + +pub struct Step { +pub mut: + name string + description string + main_step fn (mut s Step) ! @[required] + context map[string]string + error_steps []Step + next_steps []Step + error string + logs []logger.LogItem + params paramsparser.Params + coordinator &Coordinator +} + +pub fn (mut s Step) error_step_add(s2 Step) { + s.error_steps << s2 +} + +pub fn (mut s Step) next_step_add(s2 Step) { + s.next_steps << s2 +} + +pub fn (mut s Step) log(l logger.LogItemArgs) ! { + mut l2 := s.coordinator.logger.log(l)! + s.logs << l2 +} diff --git a/lib/core/logger/log.v b/lib/core/logger/log.v index 003a2e36..5808a21c 100644 --- a/lib/core/logger/log.v +++ b/lib/core/logger/log.v @@ -14,7 +14,7 @@ pub mut: logtype LogType } -pub fn (mut l Logger) log(args_ LogItemArgs) ! { +pub fn (mut l Logger) log(args_ LogItemArgs) !LogItem { mut args := args_ t := args.timestamp or { @@ -67,6 +67,13 @@ pub fn (mut l Logger) log(args_ LogItemArgs) ! { if l.console_output { l.write_to_console(args, t)! } + + return LogItem{ + timestamp: t + cat: args.cat + log: args.log + logtype: args.logtype + } } // Write log message to console with clean formatting diff --git a/lib/data/paramsparser/readme.md b/lib/data/paramsparser/readme.md index ad5d09b3..acb25422 100644 --- a/lib/data/paramsparser/readme.md +++ b/lib/data/paramsparser/readme.md @@ -168,6 +168,7 @@ println(map_representation["key1"]) // Output: value1 Combine two `Params` objects, with values from the merged object overriding existing keys. ```v + mut params1 := paramsparser.new("color:red size:small")! params2 := paramsparser.new("size:large material:wood")!