This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
281 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,105 @@ | ||
|
||
module openai | ||
|
||
import freeflowuniverse.crystallib.core.base | ||
import freeflowuniverse.crystallib.core.playbook | ||
|
||
|
||
__global ( | ||
openai_global map[string]&OpenAIClient | ||
openai_default string | ||
openai_global map[string]&OpenAIClient | ||
openai_default string | ||
) | ||
|
||
/////////FACTORY | ||
|
||
@[params] | ||
pub struct ArgsGet{ | ||
pub struct ArgsGet { | ||
pub mut: | ||
name string = "default" | ||
name string = 'default' | ||
} | ||
|
||
fn args_get (args_ ArgsGet) ArgsGet { | ||
mut args:=args_ | ||
if args.name == ""{ | ||
args.name = openai_default | ||
} | ||
if args.name == ""{ | ||
args.name = "default" | ||
} | ||
return args | ||
fn args_get(args_ ArgsGet) ArgsGet { | ||
mut args := args_ | ||
if args.name == '' { | ||
args.name = openai_default | ||
} | ||
if args.name == '' { | ||
args.name = 'default' | ||
} | ||
return args | ||
} | ||
|
||
pub fn get(args_ ArgsGet) !&OpenAIClient { | ||
mut args := args_get(args_) | ||
if !(args.name in openai_global) { | ||
if ! config_exists(){ | ||
if default{ | ||
config_save()! | ||
} | ||
} | ||
config_load()! | ||
} | ||
return openai_global[args.name] or { | ||
println(openai_global) | ||
panic("bug in get from factory: ") | ||
} | ||
pub fn get(args_ ArgsGet) !&OpenAIClient { | ||
mut args := args_get(args_) | ||
if args.name !in openai_global { | ||
if !config_exists() { | ||
if default { | ||
config_save()! | ||
} | ||
} | ||
config_load()! | ||
} | ||
return openai_global[args.name] or { | ||
println(openai_global) | ||
panic('bug in get from factory: ') | ||
} | ||
} | ||
|
||
|
||
|
||
fn config_exists(args_ ArgsGet) bool { | ||
mut args := args_get(args_) | ||
mut context:=base.context() or { panic("bug") } | ||
return context.hero_config_exists("openai",args.name) | ||
mut args := args_get(args_) | ||
mut context := base.context() or { panic('bug') } | ||
return context.hero_config_exists('openai', args.name) | ||
} | ||
|
||
fn config_load(args_ ArgsGet) ! { | ||
mut args := args_get(args_) | ||
mut context:=base.context()! | ||
mut heroscript := context.hero_config_get("openai",args.name)! | ||
play(heroscript:heroscript)! | ||
mut args := args_get(args_) | ||
mut context := base.context()! | ||
mut heroscript := context.hero_config_get('openai', args.name)! | ||
play(heroscript: heroscript)! | ||
} | ||
|
||
fn config_save(args_ ArgsGet) ! { | ||
mut args := args_get(args_) | ||
mut context:=base.context()! | ||
context.hero_config_set("openai",args.name,heroscript_default()!)! | ||
mut args := args_get(args_) | ||
mut context := base.context()! | ||
context.hero_config_set('openai', args.name, heroscript_default()!)! | ||
} | ||
|
||
|
||
fn set(o OpenAIClient)! { | ||
mut o2:=obj_init(o)! | ||
openai_global["default"] = &o2 | ||
fn set(o OpenAIClient) ! { | ||
mut o2 := obj_init(o)! | ||
openai_global['default'] = &o2 | ||
} | ||
|
||
|
||
@[params] | ||
pub struct PlayArgs { | ||
pub mut: | ||
name string = 'default' | ||
heroscript string //if filled in then plbook will be made out of it | ||
plbook ?playbook.PlayBook | ||
reset bool | ||
start bool | ||
stop bool | ||
restart bool | ||
delete bool | ||
configure bool //make sure there is at least one installed | ||
name string = 'default' | ||
heroscript string // if filled in then plbook will be made out of it | ||
plbook ?playbook.PlayBook | ||
reset bool | ||
start bool | ||
stop bool | ||
restart bool | ||
delete bool | ||
configure bool // make sure there is at least one installed | ||
} | ||
|
||
pub fn play(args_ PlayArgs) ! { | ||
|
||
mut args:=args_ | ||
|
||
if args.heroscript == "" { | ||
args.heroscript = heroscript_default()! | ||
} | ||
mut plbook := args.plbook or { | ||
playbook.new(text: args.heroscript)! | ||
} | ||
|
||
mut install_actions := plbook.find(filter: 'openai.configure')! | ||
if install_actions.len > 0 { | ||
for install_action in install_actions { | ||
mut p := install_action.params | ||
mycfg:=cfg_play(p)! | ||
set(mycfg)! | ||
} | ||
} | ||
|
||
mut args := args_ | ||
|
||
if args.heroscript == '' { | ||
args.heroscript = heroscript_default()! | ||
} | ||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } | ||
|
||
mut install_actions := plbook.find(filter: 'openai.configure')! | ||
if install_actions.len > 0 { | ||
for install_action in install_actions { | ||
mut p := install_action.params | ||
mycfg := cfg_play(p)! | ||
set(mycfg)! | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
//switch instance to be used for openai | ||
// switch instance to be used for openai | ||
pub fn switch(name string) { | ||
openai_default = name | ||
openai_default = name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module openrouter | ||
|
||
//https://openrouter.ai/docs/models | ||
//todo: see also /root/code/github/freeflowuniverse/crystallib/crystallib/clients/openai/models.v | ||
// https://openrouter.ai/docs/models | ||
// todo: see also /root/code/github/freeflowuniverse/crystallib/crystallib/clients/openai/models.v |
Oops, something went wrong.