...
This commit is contained in:
1
examples/develop/gittools/.gitignore
vendored
Normal file
1
examples/develop/gittools/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
gittools_example
|
||||
25
examples/develop/gittools/example3.vsh
Executable file
25
examples/develop/gittools/example3.vsh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env -S v -cg -enable-globals run
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.develop.performance
|
||||
|
||||
mut silent := false
|
||||
|
||||
coderoot := if 'CODEROOT' in os.environ() {
|
||||
os.environ()['CODEROOT']
|
||||
} else {os.join_path(os.home_dir(), 'code')}
|
||||
|
||||
mut gs := gittools.get()!
|
||||
if coderoot.len > 0 {
|
||||
//is a hack for now
|
||||
gs = gittools.new(coderoot: coderoot)!
|
||||
}
|
||||
|
||||
mypath := gs.do(
|
||||
recursive: true
|
||||
cmd: 'list'
|
||||
)!
|
||||
|
||||
timer := performance.new('gittools')
|
||||
timer.timeline()
|
||||
19
examples/develop/gittools/gittools_example.vsh
Executable file
19
examples/develop/gittools/gittools_example.vsh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env -S v -cg -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
import time
|
||||
|
||||
|
||||
mut gs_default := gittools.new()!
|
||||
|
||||
println(gs_default)
|
||||
|
||||
// // Initializes the Git structure with the coderoot path.
|
||||
// coderoot := '/tmp/code'
|
||||
// mut gs_tmo := gittools.new(coderoot: coderoot)!
|
||||
|
||||
// // Retrieve the specified repository.
|
||||
// mut repo := gs_default.get_repo(name: 'herolib')!
|
||||
|
||||
// println(repo)
|
||||
104
examples/develop/gittools/gittools_example2.vsh
Executable file
104
examples/develop/gittools/gittools_example2.vsh
Executable file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
import time
|
||||
|
||||
// Creates a new file in the specified repository path and returns its name.
|
||||
fn create_new_file(repo_path string, runtime i64)! string {
|
||||
coded_now := time.now().unix()
|
||||
file_name := 'hello_world_${coded_now}.py'
|
||||
println('Creating a new ${file_name} file.')
|
||||
|
||||
// Create a new file in the repository.
|
||||
osal.execute_silent("echo \"print('Hello, World!')\" > ${repo_path}/${file_name}")!
|
||||
return file_name
|
||||
}
|
||||
|
||||
// Resets all configurations and caches if needed.
|
||||
// gittools.cachereset()!
|
||||
|
||||
// Initializes the Git structure with the coderoot path.
|
||||
coderoot := '~/code'
|
||||
mut gs_default := gittools.new(coderoot: coderoot)!
|
||||
|
||||
// Retrieve the specified repository.
|
||||
mut repo := gs_default.get_repo(name: 'repo3')!
|
||||
|
||||
// In case we need to clone it, will clone the repo2 in a folder named repo3
|
||||
// mut repo := gs_default.get_repo(name: 'repo3' clone: true, url: 'https://github.com/Mahmoud-Emad/repo2.git')!
|
||||
|
||||
runtime := time.now().unix()
|
||||
branch_name := "branch_${runtime}"
|
||||
tag_name := "tag_${runtime}"
|
||||
repo_path := repo.get_path()!
|
||||
mut file_name := create_new_file(repo_path, runtime)!
|
||||
|
||||
// Create a new branch to add our changes on it.
|
||||
// We can simply checkout to the newly created branch, but we need to test the checkout method functionalty.
|
||||
|
||||
println('Creating a new \'${branch_name}\' branch...')
|
||||
repo.create_branch(branch_name: branch_name, checkout: false) or {
|
||||
error("Couldn't create branch due to: ${err}")
|
||||
}
|
||||
|
||||
// Checkout to the created branch
|
||||
println('Checkout to \'${branch_name}\' branch...')
|
||||
repo.checkout(branch_name: branch_name, pull: false) or {
|
||||
error("Couldn't checkout to branch ${branch_name} due to: ${err}")
|
||||
}
|
||||
|
||||
// Check for changes and stage them if present.
|
||||
if repo.has_changes()! {
|
||||
println('Adding the changes...')
|
||||
repo.add_changes() or {
|
||||
error('Cannot add the changes due to: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a commit is needed and commit changes if necessary.
|
||||
if repo.need_commit()! {
|
||||
commit_msg := 'feat: Added ${file_name} file.'
|
||||
println('Committing the changes, Commit message: ${commit_msg}.')
|
||||
repo.commit(msg: commit_msg) or {
|
||||
error('Cannot commit the changes due to: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
// Push changes to the remote repository if necessary.
|
||||
if repo.need_push()! {
|
||||
println('Pushing the changes...')
|
||||
repo.push() or {
|
||||
error('Cannot push the changes due to: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
if repo.need_pull()! {
|
||||
println('Pulling the changes.')
|
||||
repo.pull() or {
|
||||
error('Cannot pull the changes due to: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
// Checkout to the base branch
|
||||
repo.checkout(checkout_to_base_branch: true, pull: true) or {
|
||||
error("Couldn't checkout to branch ${branch_name} due to: ${err}")
|
||||
}
|
||||
|
||||
// Create a new tag and add some changes on it then push it to the remote.
|
||||
println('Creating a new \'${tag_name}\' tag...')
|
||||
repo.create_tag(tag_name: tag_name, checkout: false) or {
|
||||
error("Couldn't create tag due to: ${err}")
|
||||
}
|
||||
|
||||
// Push the created tag.
|
||||
println('Pushing the tag...')
|
||||
repo.push(push_tag: true) or {
|
||||
error('Cannot push the tag due to: ${err}')
|
||||
}
|
||||
|
||||
// Check if the created tag exists.
|
||||
println('Check if the created tag exists...')
|
||||
repo.is_tag_exists(tag_name: tag_name) or {
|
||||
println("Tag isn't exists.")
|
||||
}
|
||||
7
examples/develop/juggler/README.md
Normal file
7
examples/develop/juggler/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
## Juggler Example
|
||||
|
||||
This example demonstrates how juggler is able to trigger DAG's on a remote dagu server, upon webhook triggers from gitea.
|
||||
|
||||
To run example:
|
||||
- configure gitea webhook to call `trigger` endpoint in your locally running juggler server
|
||||
- run `main.vsh` with the appropriate `repo_path` and `dagu server url`
|
||||
1
examples/develop/juggler/hero/example.sh
Normal file
1
examples/develop/juggler/hero/example.sh
Normal file
@@ -0,0 +1 @@
|
||||
hero run -u https://github.com/freeflowuniverse/herolib/tree/development_juggler/examples/develop/juggler/hero/playbook
|
||||
14
examples/develop/juggler/hero/playbook/juggler.md
Normal file
14
examples/develop/juggler/hero/playbook/juggler.md
Normal file
@@ -0,0 +1,14 @@
|
||||
!!juggler.configure
|
||||
url: 'https://git.ourworld.tf/projectmycelium/itenv'
|
||||
username: ''
|
||||
password: ''
|
||||
port: 8000
|
||||
|
||||
!!juggler.start
|
||||
|
||||
!!caddy.add_reverse_proxy
|
||||
from: ':8000'
|
||||
to: juggler.protocol.me
|
||||
|
||||
!!caddy.generate
|
||||
!!caddy.start
|
||||
1
examples/develop/juggler/hero_example.sh
Normal file
1
examples/develop/juggler/hero_example.sh
Normal file
@@ -0,0 +1 @@
|
||||
hero juggler -u https://git.ourworld.tf/projectmycelium/itenv
|
||||
BIN
examples/develop/juggler/v_example
Executable file
BIN
examples/develop/juggler/v_example
Executable file
Binary file not shown.
29
examples/develop/juggler/v_example.vsh
Executable file
29
examples/develop/juggler/v_example.vsh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.develop.juggler
|
||||
import veb
|
||||
|
||||
osal.load_env_file('${os.dir(@FILE)}/.env')!
|
||||
|
||||
mut j := juggler.configure(
|
||||
url: 'https://git.ourworld.tf/projectmycelium/itenv'
|
||||
username: os.getenv('JUGGLER_USERNAME')
|
||||
password: os.getenv('JUGGLER_PASSWORD')
|
||||
reset: true
|
||||
)!
|
||||
|
||||
spawn j.run(8000)
|
||||
println(j.info())
|
||||
|
||||
for{}
|
||||
|
||||
// TODO
|
||||
// - automate caddy install/start
|
||||
// - create server/caddy which only calls install & can set config file from path or url & restart (see dagu server)
|
||||
// - get caddy config from the itenv through (simple driver)
|
||||
// - caddy through startup manager, also for dagu
|
||||
// - expose dagu UI over caddy & make sure we use secret
|
||||
// - have heroscript starting from itenv to start a full env (with secret): 'hero juggler -i -s mysecret --dns juggler2.protocol.me '
|
||||
// - use domain name use https://github.com/Incubaid/dns/blob/main/protocol.me.lua over git ssh
|
||||
BIN
examples/develop/juggler/v_example2
Executable file
BIN
examples/develop/juggler/v_example2
Executable file
Binary file not shown.
21
examples/develop/juggler/v_example2.vsh
Executable file
21
examples/develop/juggler/v_example2.vsh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import os
|
||||
|
||||
mut sm := startupmanager.get()!
|
||||
sm.start(
|
||||
name: 'juggler'
|
||||
cmd: 'hero juggler -secret planetfirst -u https://git.ourworld.tf/projectmycelium/itenv -reset true'
|
||||
env: {'HOME': os.home_dir()}
|
||||
restart: true
|
||||
) or {panic('failed to start sm ${err}')}
|
||||
|
||||
// TODO
|
||||
// - automate caddy install/start
|
||||
// - create server/caddy which only calls install & can set config file from path or url & restart (see dagu server)
|
||||
// - get caddy config from the itenv through (simple driver)
|
||||
// - caddy through startup manager, also for dagu
|
||||
// - expose dagu UI over caddy & make sure we use secret
|
||||
// - have heroscript starting from itenv to start a full env (with secret): 'hero juggler -i -s mysecret --dns juggler2.protocol.me '
|
||||
// - use domain name use https://github.com/Incubaid/dns/blob/main/protocol.me.lua over git ssh
|
||||
28
examples/develop/luadns/example.vsh
Normal file
28
examples/develop/luadns/example.vsh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.luadns
|
||||
|
||||
fn main() {
|
||||
mut lua_dns := luadns.load('https://github.com/Incubaid/dns') or {
|
||||
eprintln('Failed to parse LuaDNS files: $err')
|
||||
return
|
||||
}
|
||||
|
||||
lua_dns.set_domain('test.protocol.me', '65.21.132.119') or {
|
||||
eprintln('Failed to set domain: $err')
|
||||
return
|
||||
}
|
||||
|
||||
lua_dns.set_domain('example.protocol.me', '65.21.132.119') or {
|
||||
eprintln('Failed to set domain: $err')
|
||||
return
|
||||
}
|
||||
|
||||
for config in lua_dns.configs {
|
||||
println(config)
|
||||
}
|
||||
|
||||
for config in lua_dns.configs {
|
||||
println(config)
|
||||
}
|
||||
}
|
||||
1
examples/develop/openai/.gitignore
vendored
Normal file
1
examples/develop/openai/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
openai_example
|
||||
76
examples/develop/openai/openai_example.vsh
Normal file
76
examples/develop/openai/openai_example.vsh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.openai as op
|
||||
|
||||
mut ai_cli := op.new()!
|
||||
mut msg := []op.Message{}
|
||||
msg << op.Message{
|
||||
role: op.RoleType.user
|
||||
content: 'Say this is a test!'
|
||||
}
|
||||
mut msgs := op.Messages{
|
||||
messages: msg
|
||||
}
|
||||
res := ai_cli.chat_completion(op.ModelType.gpt_3_5_turbo, msgs)!
|
||||
print(res)
|
||||
|
||||
models := ai_cli.list_models()!
|
||||
|
||||
model := ai_cli.get_model(models.data[0].id)!
|
||||
print(model)
|
||||
images_created := ai_cli.create_image(op.ImageCreateArgs{
|
||||
prompt: 'Calm weather'
|
||||
num_images: 2
|
||||
size: op.ImageSize.size_512_512
|
||||
format: op.ImageRespType.url
|
||||
})!
|
||||
print(images_created)
|
||||
images_updated := ai_cli.create_edit_image(op.ImageEditArgs{
|
||||
image_path: '/path/to/image.png'
|
||||
mask_path: '/path/to/mask.png'
|
||||
prompt: 'Calm weather'
|
||||
num_images: 2
|
||||
size: op.ImageSize.size_512_512
|
||||
format: op.ImageRespType.url
|
||||
})!
|
||||
print(images_updated)
|
||||
images_variatons := ai_cli.create_variation_image(op.ImageVariationArgs{
|
||||
image_path: '/path/to/image.png'
|
||||
num_images: 2
|
||||
size: op.ImageSize.size_512_512
|
||||
format: op.ImageRespType.url
|
||||
})!
|
||||
print(images_variatons)
|
||||
|
||||
transcription := ai_cli.create_transcription(op.AudioArgs{
|
||||
filepath: '/path/to/audio'
|
||||
})!
|
||||
print(transcription)
|
||||
|
||||
translation := ai_cli.create_tranlation(op.AudioArgs{
|
||||
filepath: '/path/to/audio'
|
||||
})!
|
||||
print(translation)
|
||||
|
||||
file_upload := ai_cli.upload_file(filepath: '/path/to/file.jsonl', purpose: 'fine-tune')
|
||||
print(file_upload)
|
||||
files := ai_cli.list_filess()!
|
||||
print(files)
|
||||
resp := ai_cli.create_fine_tune(training_file: file.id, model: 'curie')!
|
||||
print(resp)
|
||||
|
||||
fine_tunes := ai_cli.list_fine_tunes()!
|
||||
print(fine_tunes)
|
||||
|
||||
fine_tune := ai_cli.get_fine_tune(fine_tunes.data[0].id)!
|
||||
print(fine_tune)
|
||||
|
||||
moderations := ai_cli.create_moderation('Something violent', op.ModerationModel.text_moderation_latest)!
|
||||
print(moderations)
|
||||
|
||||
embeddings := ai_cli.create_embeddings(
|
||||
input: ['sample embedding input']
|
||||
model: op.EmbeddingModel.text_embedding_ada
|
||||
)!
|
||||
print(embeddings)
|
||||
|
||||
Reference in New Issue
Block a user