From b8eb387146447992782477cda20444ef46967e31 Mon Sep 17 00:00:00 2001 From: despiegk Date: Tue, 24 Dec 2024 18:59:44 +0100 Subject: [PATCH] github actions should work --- crystallib/clients/httpconnection/factory.v | 3 - crystallib/clients/openai/embeddings.v | 8 +- crystallib/clients/openai/openai_factory_.v | 145 ++++++++---------- crystallib/clients/openai/openai_model.v | 47 +++--- crystallib/clients/openrouter/models.v | 4 +- .../clients/openrouter/openrouter_factory_.v | 145 ++++++++---------- .../clients/openrouter/openrouter_model.v | 61 ++++---- crystallib/clients/openrouter/request.v | 78 +++++----- .../threefold/griddriver/griddriver_actions.v | 6 +- crystallib/threefold/gridproxy/model/node.v | 74 ++++----- examples/clients/openai/openai_example.vsh | 5 +- .../clients/openai/openai_example_full.vsh | 4 +- .../code_generation/main.vsh | 2 + .../code_generation/openrpc.json | 0 examples/core/generate_test.vsh | 5 +- 15 files changed, 281 insertions(+), 306 deletions(-) rename {crystallib/rpc/openrpc/examples => examples}/code_generation/main.vsh (85%) rename {crystallib/rpc/openrpc/examples => examples}/code_generation/openrpc.json (100%) diff --git a/crystallib/clients/httpconnection/factory.v b/crystallib/clients/httpconnection/factory.v index e478a5961..b63aa429b 100644 --- a/crystallib/clients/httpconnection/factory.v +++ b/crystallib/clients/httpconnection/factory.v @@ -3,7 +3,6 @@ module httpconnection import net.http import freeflowuniverse.crystallib.clients.redisclient { RedisURL } - @[params] pub struct HTTPConnectionArgs { pub: @@ -34,6 +33,4 @@ pub fn new(args HTTPConnectionArgs) !&HTTPConnection { base_url: args.url.trim('/') } return &conn - } - diff --git a/crystallib/clients/openai/embeddings.v b/crystallib/clients/openai/embeddings.v index 414891a29..7413ca9d6 100644 --- a/crystallib/clients/openai/embeddings.v +++ b/crystallib/clients/openai/embeddings.v @@ -39,12 +39,12 @@ pub mut: pub fn (mut f OpenAIClient[Config]) create_embeddings(args EmbeddingCreateArgs) !EmbeddingResponse { mut conn := f.connection()! return conn.post_json_generic[EmbeddingResponse]( - method: .post - prefix: 'embeddings' - params: { + method: .post + prefix: 'embeddings' + params: { 'input': args.input.str() 'model': embedding_model_str(args.model) - 'user': args.user + 'user': args.user } dataformat: .json )! diff --git a/crystallib/clients/openai/openai_factory_.v b/crystallib/clients/openai/openai_factory_.v index 836f19098..5ae26ee14 100644 --- a/crystallib/clients/openai/openai_factory_.v +++ b/crystallib/clients/openai/openai_factory_.v @@ -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 } diff --git a/crystallib/clients/openai/openai_model.v b/crystallib/clients/openai/openai_model.v index 2dcc7bca7..fb8e5e415 100644 --- a/crystallib/clients/openai/openai_model.v +++ b/crystallib/clients/openai/openai_model.v @@ -1,4 +1,5 @@ module openai + import freeflowuniverse.crystallib.data.paramsparser import freeflowuniverse.crystallib.clients.httpconnection @@ -7,41 +8,40 @@ const singleton = false const default = true pub fn heroscript_default() !string { - heroscript := " + heroscript := " !!openai.configure name:'openai' openaikey:'your-api-key-here' description:'OpenAI API Client' url:'' //default is openai endpoint " - return heroscript + return heroscript } @[heap] pub struct OpenAIClient { pub mut: - name string = 'default' - openaikey string @[secret] - description string - url string - conn ?&httpconnection.HTTPConnection + name string = 'default' + openaikey string @[secret] + description string + url string + conn ?&httpconnection.HTTPConnection } fn cfg_play(p paramsparser.Params) ! { - mut mycfg := OpenAIClient{ - name: p.get_default('name', 'default')! - openaikey: p.get('openaikey')! - description: p.get_default('description', '')! - url: p.get_default('url', 'https://api.openai.com/v1')! - } - set(mycfg)! -} - -fn obj_init(obj_ OpenAIClient)!OpenAIClient { - mut obj := obj_ - return obj + mut mycfg := OpenAIClient{ + name: p.get_default('name', 'default')! + openaikey: p.get('openaikey')! + description: p.get_default('description', '')! + url: p.get_default('url', 'https://api.openai.com/v1')! + } + set(mycfg)! } +fn obj_init(obj_ OpenAIClient) !OpenAIClient { + mut obj := obj_ + return obj +} pub fn (mut client OpenAIClient) connection() !&httpconnection.HTTPConnection { mut c := client.conn or { @@ -53,8 +53,9 @@ pub fn (mut client OpenAIClient) connection() !&httpconnection.HTTPConnection { )! c2 } - c.default_header.set(.authorization, 'Bearer ${client.openaikey}') - // see https://modules.vlang.io/net.http.html#CommonHeader - client.conn = c - return c + + c.default_header.set(.authorization, 'Bearer ${client.openaikey}') + // see https://modules.vlang.io/net.http.html#CommonHeader + client.conn = c + return c } diff --git a/crystallib/clients/openrouter/models.v b/crystallib/clients/openrouter/models.v index 10fed1a9f..710887110 100644 --- a/crystallib/clients/openrouter/models.v +++ b/crystallib/clients/openrouter/models.v @@ -1,4 +1,4 @@ module openrouter -//https://openrouter.ai/docs/models -//todo: see also /root/code/github/freeflowuniverse/crystallib/crystallib/clients/openai/models.v \ No newline at end of file +// https://openrouter.ai/docs/models +// todo: see also /root/code/github/freeflowuniverse/crystallib/crystallib/clients/openai/models.v diff --git a/crystallib/clients/openrouter/openrouter_factory_.v b/crystallib/clients/openrouter/openrouter_factory_.v index 9056886c3..9f6bb2641 100644 --- a/crystallib/clients/openrouter/openrouter_factory_.v +++ b/crystallib/clients/openrouter/openrouter_factory_.v @@ -1,118 +1,105 @@ - module openrouter import freeflowuniverse.crystallib.core.base import freeflowuniverse.crystallib.core.playbook - __global ( - openrouter_global map[string]&OpenRouterClient - openrouter_default string + openrouter_global map[string]&OpenRouterClient + openrouter_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 = openrouter_default - } - if args.name == ""{ - args.name = "default" - } - return args +fn args_get(args_ ArgsGet) ArgsGet { + mut args := args_ + if args.name == '' { + args.name = openrouter_default + } + if args.name == '' { + args.name = 'default' + } + return args } -pub fn get(args_ ArgsGet) !&OpenRouterClient { - mut args := args_get(args_) - if !(args.name in openrouter_global) { - if ! config_exists(){ - if default{ - config_save()! - } - } - config_load()! - } - return openrouter_global[args.name] or { - println(openrouter_global) - panic("bug in get from factory: ") - } +pub fn get(args_ ArgsGet) !&OpenRouterClient { + mut args := args_get(args_) + if args.name !in openrouter_global { + if !config_exists() { + if default { + config_save()! + } + } + config_load()! + } + return openrouter_global[args.name] or { + println(openrouter_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("openrouter",args.name) + mut args := args_get(args_) + mut context := base.context() or { panic('bug') } + return context.hero_config_exists('openrouter', args.name) } fn config_load(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context:=base.context()! - mut heroscript := context.hero_config_get("openrouter",args.name)! - play(heroscript:heroscript)! + mut args := args_get(args_) + mut context := base.context()! + mut heroscript := context.hero_config_get('openrouter', args.name)! + play(heroscript: heroscript)! } fn config_save(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context:=base.context()! - context.hero_config_set("openrouter",args.name,heroscript_default()!)! + mut args := args_get(args_) + mut context := base.context()! + context.hero_config_set('openrouter', args.name, heroscript_default()!)! } - -fn set(o OpenRouterClient)! { - mut o2:=obj_init(o)! - openrouter_global["default"] = &o2 +fn set(o OpenRouterClient) ! { + mut o2 := obj_init(o)! + openrouter_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: 'openrouter.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: 'openrouter.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 openrouter +// switch instance to be used for openrouter pub fn switch(name string) { - openrouter_default = name + openrouter_default = name } diff --git a/crystallib/clients/openrouter/openrouter_model.v b/crystallib/clients/openrouter/openrouter_model.v index 35369f751..f248a5d89 100644 --- a/crystallib/clients/openrouter/openrouter_model.v +++ b/crystallib/clients/openrouter/openrouter_model.v @@ -1,51 +1,51 @@ module openrouter + import freeflowuniverse.crystallib.data.paramsparser import freeflowuniverse.crystallib.ui.console import freeflowuniverse.crystallib.core.playbook import os pub fn heroscript_default() !string { - heroscript:=" + heroscript := " !!openrouter.configure name: 'default' openrouter_apikey: '' your_site_url: '' your_site_name: '' " - return heroscript + return heroscript } @[heap] pub struct OpenRouterClient { pub mut: - name string = 'default' - openrouter_apikey string @[secret] - your_site_url string - your_site_name string + name string = 'default' + openrouter_apikey string @[secret] + your_site_url string + your_site_name string } pub fn play_openrouter(mut plbook playbook.PlayBook) ! { - actions := plbook.find(filter: 'openrouter.')! - for action in actions { - if action.name == "configure" { - mut p := action.params - mut obj := OpenRouterClient{ - name: p.get_default('name', 'default')! - openrouter_apikey: p.get('openrouter_apikey')! - your_site_url: p.get_default('your_site_url', '')! - your_site_name: p.get_default('your_site_name', '')! - } - //console.print_debug(obj) - } - } + actions := plbook.find(filter: 'openrouter.')! + for action in actions { + if action.name == 'configure' { + mut p := action.params + mut obj := OpenRouterClient{ + name: p.get_default('name', 'default')! + openrouter_apikey: p.get('openrouter_apikey')! + your_site_url: p.get_default('your_site_url', '')! + your_site_name: p.get_default('your_site_name', '')! + } + // console.print_debug(obj) + } + } } -fn obj_init(obj_ OpenRouterClient)!OpenRouterClient { - mut obj := obj_ - return obj +fn obj_init(obj_ OpenRouterClient) !OpenRouterClient { + mut obj := obj_ + return obj } - pub fn (mut client OpenRouterClient) connection() !&httpconnection.HTTPConnection { mut c := client.conn or { mut c2 := httpconnection.new( @@ -56,11 +56,12 @@ pub fn (mut client OpenRouterClient) connection() !&httpconnection.HTTPConnectio )! c2 } - // see https://modules.vlang.io/net.http.html#CommonHeader - // -H "Authorization: Bearer $OPENROUTER_API_KEY" \ - c.default_header.set(.authorization, 'Bearer ${client.openaikey}') - c.default_header.add_custom("HTTP-Referer",client.your_site_url)! - c.default_header.add_custom("X-Title",client.your_site_name)! - client.conn = c - return c + + // see https://modules.vlang.io/net.http.html#CommonHeader + // -H "Authorization: Bearer $OPENROUTER_API_KEY" \ + c.default_header.set(.authorization, 'Bearer ${client.openaikey}') + c.default_header.add_custom('HTTP-Referer', client.your_site_url)! + c.default_header.add_custom('X-Title', client.your_site_name)! + client.conn = c + return c } diff --git a/crystallib/clients/openrouter/request.v b/crystallib/clients/openrouter/request.v index bc1ad19b4..75631ab9a 100644 --- a/crystallib/clients/openrouter/request.v +++ b/crystallib/clients/openrouter/request.v @@ -5,12 +5,12 @@ import net.http import freeflowuniverse.crystallib.clients.httpconnection { Request } // Message represents a single message in the conversation -pub struct Message { -pub mut: - role string - content string - name string // optional -} +// pub struct Message { +// pub mut: +// role string +// content string +// name string // optional +// } // CompletionRequest represents the request body for chat completions pub struct CompletionRequest { @@ -20,7 +20,7 @@ pub mut: temperature f64 = 0.7 max_tokens int // OpenRouter specific fields - transforms []string // optional + transforms []string // optional route string // optional // Site info for rankings (optional) http_referer string @@ -28,61 +28,61 @@ pub mut: } // Choice represents a single completion choice in the response -pub struct Choice { -pub mut: - index int - message Message - finish_reason string -} +// pub struct Choice { +// pub mut: +// index int +// message Message +// finish_reason string +// } // Usage represents token usage information -pub struct Usage { -pub mut: - prompt_tokens int - completion_tokens int - total_tokens int -} +// pub struct Usage { +// pub mut: +// prompt_tokens int +// completion_tokens int +// total_tokens int +// } // CompletionResponse represents the API response for chat completions pub struct CompletionResponse { pub mut: - id string - choices []Choice - created int - model string - usage Usage + id string + choices []Choice + created int + model string + usage Usage system_fingerprint string } // create_completion sends a completion request to OpenRouter API pub fn (mut client OpenRouterClient) create_completion(req CompletionRequest) !CompletionResponse { mut conn := client.connection()! - + // Set required headers mut headers := http.new_header() headers.add_custom('HTTP-Referer', req.http_referer) or {} headers.add_custom('HTTP-User-Agent', req.http_user_agent) or {} - + // Prepare request mut request := Request{ - method: .post - prefix: 'chat/completions' - data: json.encode(req) - header: headers + method: .post + prefix: 'chat/completions' + data: json.encode(req) + header: headers dataformat: .json } - + // Send request and decode response response := conn.do(request)! return json.decode(CompletionResponse, response)! } // Helper method to create a connection -fn (client OpenRouterClient) connection() !httpconnection.Connection { - mut conn := httpconnection.new( - base_url: 'https://openrouter.ai/api/v1' - auth_type: .bearer - auth_token: client.openrouter_apikey - )! - return conn -} +// fn (client OpenRouterClient) connection() !httpconnection.Connection { +// mut conn := httpconnection.new( +// base_url: 'https://openrouter.ai/api/v1' +// auth_type: .bearer +// auth_token: client.openrouter_apikey +// )! +// return conn +// } diff --git a/crystallib/installers/threefold/griddriver/griddriver_actions.v b/crystallib/installers/threefold/griddriver/griddriver_actions.v index 5150dd017..847bef6bb 100644 --- a/crystallib/installers/threefold/griddriver/griddriver_actions.v +++ b/crystallib/installers/threefold/griddriver/griddriver_actions.v @@ -41,9 +41,9 @@ fn build() ! { url := 'https://github.com/threefoldtech/web3gw/tree/development_integration/griddriver' mut repo := gs.get_repo( - url: url + url: url reset: true - pull: true + pull: true )! mut path := repo.get_path()! @@ -59,7 +59,7 @@ fn build() ! { osal.execute_stdout(cmd)! osal.cmd_add( cmdname: 'griddriver' - source: '/tmp/griddriver' + source: '/tmp/griddriver' )! console.print_header('build griddriver OK') } diff --git a/crystallib/threefold/gridproxy/model/node.v b/crystallib/threefold/gridproxy/model/node.v index c5690a144..72f6554e1 100644 --- a/crystallib/threefold/gridproxy/model/node.v +++ b/crystallib/threefold/gridproxy/model/node.v @@ -35,37 +35,37 @@ pub: pub struct Node_ { pub: id string - node_id u64 @[json: nodeId] - farm_id u64 @[json: farmId] - twin_id u64 @[json: twinId] - grid_version u64 @[json: gridVersion] + node_id u64 @[json: nodeId] + farm_id u64 @[json: farmId] + twin_id u64 @[json: twinId] + grid_version u64 @[json: gridVersion] uptime SecondUnit - created UnixTime @[json: created] - farming_policy_id u64 @[json: farmingPolicyId] - updated_at UnixTime @[json: updatedAt] + created UnixTime @[json: created] + farming_policy_id u64 @[json: farmingPolicyId] + updated_at UnixTime @[json: updatedAt] total_resources NodeResources used_resources NodeResources location NodeLocation - public_config PublicConfig @[json: publicConfig] - certification string @[json: certificationType] + public_config PublicConfig @[json: publicConfig] + certification string @[json: certificationType] status string dedicated bool healthy bool - rent_contract_id u64 @[json: rentContractId] - rented_by_twin_id u64 @[json: rentedByTwinId] + rent_contract_id u64 @[json: rentContractId] + rented_by_twin_id u64 @[json: rentedByTwinId] } pub struct Node { pub: id string - node_id u64 @[json: nodeId] - farm_id u64 @[json: farmId] - twin_id u64 @[json: twinId] - grid_version u64 @[json: gridVersion] + node_id u64 @[json: nodeId] + farm_id u64 @[json: farmId] + twin_id u64 @[json: twinId] + grid_version u64 @[json: gridVersion] uptime SecondUnit - created UnixTime @[json: created] - farming_policy_id u64 @[json: farmingPolicyId] - updated_at UnixTime @[json: updatedAt] + created UnixTime @[json: created] + farming_policy_id u64 @[json: farmingPolicyId] + updated_at UnixTime @[json: updatedAt] capacity NodeCapacity location NodeLocation public_config PublicConfig @[json: publicConfig] @@ -73,8 +73,8 @@ pub: status string dedicated bool healthy bool - rent_contract_id u64 @[json: rentContractId] - rented_by_twin_id u64 @[json: rentedByTwinId] + rent_contract_id u64 @[json: rentContractId] + rented_by_twin_id u64 @[json: rentedByTwinId] } fn calc_available_resources(total_resources NodeResources, used_resources NodeResources) NodeResources { @@ -98,26 +98,26 @@ pub fn (n &Node) calc_available_resources() NodeResources { // with_nested_capacity enable the client to have one representation of the node model pub fn (n &Node_) with_nested_capacity() Node { return Node{ - id: n.id - node_id: n.node_id - farm_id: n.farm_id - twin_id: n.twin_id - grid_version: n.grid_version - uptime: n.uptime - created: n.created + id: n.id + node_id: n.node_id + farm_id: n.farm_id + twin_id: n.twin_id + grid_version: n.grid_version + uptime: n.uptime + created: n.created farming_policy_id: n.farming_policy_id - updated_at: n.updated_at - capacity: NodeCapacity{ + updated_at: n.updated_at + capacity: NodeCapacity{ total_resources: n.total_resources - used_resources: n.used_resources + used_resources: n.used_resources } - location: n.location - public_config: n.public_config - certification: n.certification - status: n.status - dedicated: n.dedicated - healthy: n.healthy - rent_contract_id: n.rent_contract_id + location: n.location + public_config: n.public_config + certification: n.certification + status: n.status + dedicated: n.dedicated + healthy: n.healthy + rent_contract_id: n.rent_contract_id rented_by_twin_id: n.rented_by_twin_id } } diff --git a/examples/clients/openai/openai_example.vsh b/examples/clients/openai/openai_example.vsh index ede68512a..726bef8d0 100755 --- a/examples/clients/openai/openai_example.vsh +++ b/examples/clients/openai/openai_example.vsh @@ -3,6 +3,7 @@ import freeflowuniverse.crystallib.clients.openai import freeflowuniverse.crystallib.ui.console import freeflowuniverse.crystallib.core.base +import os console.print_header('OPENAI Example.') @@ -22,14 +23,12 @@ heroscript := " openai.play(heroscript: heroscript)! - mut ai := openai.get()! models := ai.list_models()! println(models) - // mut msg := []openai.Message{} // msg << openai.Message{ // role: openai.RoleType.user @@ -40,5 +39,3 @@ println(models) // } // res := ai.chat_completion(openai.ModelType.gpt_3_5_turbo, msgs)! // print(res) - - diff --git a/examples/clients/openai/openai_example_full.vsh b/examples/clients/openai/openai_example_full.vsh index 87d1ed281..7a60b0690 100644 --- a/examples/clients/openai/openai_example_full.vsh +++ b/examples/clients/openai/openai_example_full.vsh @@ -1,8 +1,9 @@ #!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run -import freeflowuniverse.crystallib.clients.openai as openai +import freeflowuniverse.crystallib.clients.openai import freeflowuniverse.crystallib.ui.console import freeflowuniverse.crystallib.core.base +import os console.print_header('OPENAI Example.') @@ -22,7 +23,6 @@ heroscript := " openai.play(heroscript: heroscript)! - mut ai_cli := openai.get()! mut msg := []openai.Message{} diff --git a/crystallib/rpc/openrpc/examples/code_generation/main.vsh b/examples/code_generation/main.vsh similarity index 85% rename from crystallib/rpc/openrpc/examples/code_generation/main.vsh rename to examples/code_generation/main.vsh index 6756921e3..610278c3a 100644 --- a/crystallib/rpc/openrpc/examples/code_generation/main.vsh +++ b/examples/code_generation/main.vsh @@ -1,3 +1,5 @@ +#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run + import os import json diff --git a/crystallib/rpc/openrpc/examples/code_generation/openrpc.json b/examples/code_generation/openrpc.json similarity index 100% rename from crystallib/rpc/openrpc/examples/code_generation/openrpc.json rename to examples/code_generation/openrpc.json diff --git a/examples/core/generate_test.vsh b/examples/core/generate_test.vsh index 3f63a33af..3e1b26001 100755 --- a/examples/core/generate_test.vsh +++ b/examples/core/generate_test.vsh @@ -2,4 +2,7 @@ import freeflowuniverse.crystallib.core.generator.generic -generic.scan(path: '~/code/github/freeflowuniverse/crystallib/examples/core/generatortest', force: true)! +generic.scan( + path: '~/code/github/freeflowuniverse/crystallib/examples/core/generatortest' + force: true +)!