upgrade to new gojs

This commit is contained in:
StarPro 2024-10-13 11:55:28 +08:00
parent 459a235055
commit f9c67b6d50
7 changed files with 30 additions and 24 deletions

View File

@ -1,2 +1,3 @@
# huoshan # huoshan
To know about js functions, go to [huoshan.ts](https://apigo.cc/ai/huoshan/huoshan.ts)

16
go.mod
View File

@ -3,33 +3,27 @@ module apigo.cc/ai/huoshan
go 1.18 go 1.18
require ( require (
apigo.cc/apigo/gojs v0.1.1 apigo.cc/gojs v0.0.1
github.com/ssgo/config v1.7.7 github.com/ssgo/config v1.7.7
github.com/ssgo/log v1.7.7 github.com/ssgo/log v1.7.7
github.com/ssgo/u v1.7.7 github.com/ssgo/u v1.7.9
github.com/volcengine/volc-sdk-golang v1.0.178 github.com/volcengine/volc-sdk-golang v1.0.178
) )
require ( require (
golang.org/x/net v0.29.0 // indirect golang.org/x/net v0.30.0 // indirect
golang.org/x/text v0.18.0 // indirect golang.org/x/text v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ssgo/dao v0.1.5 // indirect
github.com/ssgo/db v1.7.9 // indirect
github.com/ssgo/httpclient v1.7.7 // indirect
github.com/ssgo/standard v1.7.7 // indirect github.com/ssgo/standard v1.7.7 // indirect
github.com/ssgo/tool v0.4.27 // indirect github.com/ssgo/tool v0.4.27 // indirect
golang.org/x/sys v0.25.0 // indirect golang.org/x/sys v0.26.0 // indirect
) )

View File

@ -1,7 +1,7 @@
package huoshan package huoshan
import ( import (
"apigo.cc/apigo/gojs" "apigo.cc/gojs"
_ "embed" _ "embed"
"github.com/ssgo/config" "github.com/ssgo/config"
"github.com/ssgo/log" "github.com/ssgo/log"
@ -30,13 +30,14 @@ func SetSSKey(key, iv []byte) {
func init() { func init() {
obj := gojs.Map{ obj := gojs.Map{
"name": "huoshan",
"image": RequireImage(), "image": RequireImage(),
} }
config.LoadConfig("huoshan", &conf) config.LoadConfig("huoshan", &conf)
conf.AKey = confAes.DecryptUrlBase64ToString(conf.AKey) conf.AKey = confAes.DecryptUrlBase64ToString(conf.AKey)
conf.SKey = confAes.DecryptUrlBase64ToString(conf.SKey) conf.SKey = confAes.DecryptUrlBase64ToString(conf.SKey)
log.DefaultLogger.Info("Conf", "", conf) log.DefaultLogger.Info("Conf", "", conf)
gojs.Register("huoshan", gojs.Module{ gojs.Register("apigo.cc/ai/huoshan", gojs.Module{
Object: obj, Object: obj,
TsCode: huoshanTS, TsCode: huoshanTS,
Example: "", Example: "",

View File

@ -2,9 +2,19 @@ export default {
image: { image: {
text2image, text2image,
image2image, image2image,
readImage readImage,
base64
} }
} }
//about image
function text2image(prompt:string, option?:Object):string {return ""} function text2image(prompt:string, option?:Object):string {return ""}
function image2image(image:string[], prompt:string, option?:Object):string {return ""} // image2image
// image able with base64, bin(byte[], what you get from "readImage"), urlurl must be written in an array like ["your url"]
function image2image(image, prompt:string, option?:Object):string {return ""}
function readImage(path:string):string {return ""} function readImage(path:string):string {return ""}
// base64 written-in base64 functionyou can use what you want
// data give what you want to give
function base64(data):string {return ""}

View File

@ -1,8 +1,8 @@
package huoshan package huoshan
import ( import (
"apigo.cc/apigo/gojs" "apigo.cc/gojs"
"apigo.cc/apigo/gojs/dop251/goja" "apigo.cc/gojs/goja"
"errors" "errors"
"github.com/ssgo/log" "github.com/ssgo/log"
"github.com/ssgo/u" "github.com/ssgo/u"
@ -62,6 +62,9 @@ func RequireImage() gojs.Map {
panic(vm.NewGoError(err)) panic(vm.NewGoError(err))
} }
}, },
"base64": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
return vm.ToValue(u.Base64(u.Bytes(gojs.MakeArgs(&argsIn, vm).Check(1).Any(0))))
},
} }
} }
@ -90,7 +93,6 @@ func T2IXL(prompt string, option map[string]interface{}, vm *goja.Runtime) []str
} }
// I2IXLbyUrl used t2i_xl_sft // I2IXLbyUrl used t2i_xl_sft
//
// option 会覆盖已有参数可传空return_url不可更改 // option 会覆盖已有参数可传空return_url不可更改
func I2IXLbyUrl(imageUrls []string, prompt string, option map[string]interface{}, vm *goja.Runtime) []string { func I2IXLbyUrl(imageUrls []string, prompt string, option map[string]interface{}, vm *goja.Runtime) []string {
vis := visual.NewInstance() vis := visual.NewInstance()

View File

@ -1,8 +1,7 @@
import {image} from "huoshan" import {image} from 'apigo.cc/ai/huoshan'
import u from "util"
function main() { function main() {
let a = image.image2image(u.base64(image.readImage("img_2.jpeg")), "在吃冰淇淋", { let a = image.image2image(image.base64(image.readImage("img_2.jpeg")), "在吃冰淇淋", {
style_reference_args: { style_reference_args: {
id_weight: 1.0 id_weight: 1.0
} }
@ -12,7 +11,7 @@ function main() {
id_weight: 1.0 id_weight: 1.0
} }
}) })
let c = image.image2image([""], "在吃冰淇淋", { let c = image.image2image(["一个url"], "在吃冰淇淋", {
style_reference_args: { style_reference_args: {
id_weight: 1.0 id_weight: 1.0
} }

View File

@ -1,8 +1,7 @@
package huoshan package huoshan
import ( import (
"apigo.cc/apigo/gojs" "apigo.cc/gojs"
_ "apigo.cc/apigo/gojs/modules"
"fmt" "fmt"
"github.com/ssgo/u" "github.com/ssgo/u"
"testing" "testing"