-
Notifications
You must be signed in to change notification settings - Fork 5
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
0 parents
commit e183310
Showing
14 changed files
with
2,024 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: Cross Compile Go Project | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
build: | ||
name: Build on ${{ matrix.os }} for ${{ matrix.goarch }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
- os: linux | ||
goarch: amd64 | ||
- os: linux | ||
goarch: 386 | ||
- os: linux | ||
goarch: arm | ||
- os: linux | ||
goarch: arm64 | ||
- os: darwin | ||
goarch: amd64 | ||
- os: darwin | ||
goarch: arm64 | ||
- os: windows | ||
goarch: amd64 | ||
- os: windows | ||
goarch: 386 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.21.1' # Set to specific Go version. | ||
|
||
- name: Create output directory | ||
run: mkdir -p output | ||
|
||
- name: Compile Go for target | ||
env: | ||
GOOS: ${{ matrix.os }} | ||
GOARCH: ${{ matrix.goarch }} | ||
CGO_ENABLED: 0 | ||
run: | | ||
if [ "$GOOS" = "windows" ]; then | ||
go build -o output/gensokyo-hunyuan-${{ matrix.os }}-${{ matrix.goarch }}.exe | ||
else | ||
go build -o output/gensokyo-hunyuan-${{ matrix.os }}-${{ matrix.goarch }} | ||
fi | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: gensokyo-hunyuan-${{ matrix.os }}-${{ matrix.goarch }} | ||
path: output/gensokyo-hunyuan-${{ matrix.os }}-${{ matrix.goarch }}${{ endsWith(matrix.os, 'windows') && '.exe' || '' }} | ||
|
||
prepare_release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download all artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
path: output | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref_name }} | ||
release_name: Release ${{ github.ref_name }} | ||
draft: false | ||
|
||
- name: Upload Release Assets | ||
run: | | ||
for dir in output/*; do | ||
if [ -d "$dir" ]; then | ||
for file in "$dir"/*; do | ||
if [ -f "$file" ]; then | ||
asset_name=$(basename "$file") | ||
echo "Uploading ${asset_name}" | ||
GITHUB_UPLOAD_URL=${{ steps.create_release.outputs.upload_url }} | ||
GITHUB_UPLOAD_URL="${GITHUB_UPLOAD_URL%\{*}" | ||
GITHUB_UPLOAD_URL="${GITHUB_UPLOAD_URL%\?*}" | ||
curl \ | ||
-X POST \ | ||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @"${file}" \ | ||
"${GITHUB_UPLOAD_URL}?name=${asset_name}&label=${asset_name}" | ||
else | ||
echo "Expected a file in ${dir}, but found something else." | ||
fi | ||
done | ||
else | ||
echo "Expected ${dir} to be a directory." | ||
fi | ||
done |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# specific | ||
config.yml | ||
*.sqlite | ||
|
||
# Go specific | ||
*.exe |
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"sync" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var ( | ||
instance *Config | ||
mu sync.Mutex | ||
) | ||
|
||
type Config struct { | ||
Version int `yaml:"version"` | ||
Settings Settings `yaml:"settings"` | ||
} | ||
|
||
type Settings struct { | ||
SecretId string `yaml:"secretId"` | ||
SecretKey string `yaml:"secretKey"` | ||
Region string `yaml:"region"` | ||
UseSse bool `yaml:"useSse"` | ||
Port int `yaml:"port"` | ||
HttpPath string `yaml:"path"` | ||
} | ||
|
||
// LoadConfig 从文件中加载配置并初始化单例配置 | ||
func LoadConfig(path string) (*Config, error) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
// 如果单例已经被初始化了,直接返回 | ||
if instance != nil { | ||
return instance, nil | ||
} | ||
|
||
configData, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
conf := &Config{} | ||
err = yaml.Unmarshal(configData, conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// 设置单例实例 | ||
instance = conf | ||
return instance, nil | ||
} | ||
|
||
// 获取secretId | ||
func GetsecretId() string { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if instance != nil { | ||
return instance.Settings.SecretId | ||
} | ||
return "0" | ||
} | ||
|
||
// 获取secretKey | ||
func GetsecretKey() string { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if instance != nil { | ||
return instance.Settings.SecretKey | ||
} | ||
return "0" | ||
} | ||
|
||
// 获取region | ||
func Getregion() string { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if instance != nil { | ||
return instance.Settings.Region | ||
} | ||
return "0" | ||
} | ||
|
||
// 获取useSse | ||
func GetuseSse() bool { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if instance != nil { | ||
return instance.Settings.UseSse | ||
} | ||
return false | ||
} | ||
|
||
// 获取GetPort | ||
func GetPort() int { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if instance != nil { | ||
return instance.Settings.Port | ||
} | ||
return 46230 | ||
} | ||
|
||
// 获取getHttpPath | ||
func GetHttpPath() string { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if instance != nil { | ||
return instance.Settings.HttpPath | ||
} | ||
return "0" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
import os | ||
|
||
from tencentcloud.common import credential | ||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException | ||
from tencentcloud.hunyuan.v20230901 import hunyuan_client, models | ||
|
||
try: | ||
# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey | ||
cred = credential.Credential( | ||
os.environ.get("TENCENTCLOUD_SECRET_ID"), | ||
os.environ.get("TENCENTCLOUD_SECRET_KEY")) | ||
|
||
client = hunyuan_client.HunyuanClient(cred, "ap-guangzhou") | ||
|
||
req = models.ChatStdRequest() | ||
msg = models.Message() | ||
msg.Role = "user" | ||
msg.Content = "你好,可以讲个笑话吗" | ||
req.Messages = [msg] | ||
|
||
resp = client.ChatStd(req) | ||
|
||
full_content = "" | ||
for event in resp: | ||
print(event) | ||
data = json.loads(event['data']) | ||
for choice in data['Choices']: | ||
full_content += choice['Delta']['Content'] | ||
|
||
print(full_content) | ||
|
||
except TencentCloudSDKException as err: | ||
print(err) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/hoshinonyaruko/gensokyo-hunyuan | ||
|
||
go 1.21.1 | ||
|
||
require ( | ||
github.com/google/uuid v1.5.0 | ||
github.com/mattn/go-sqlite3 v1.14.19 | ||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= | ||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= | ||
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= | ||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839 h1:VGVFNQDaUpDsPkJrh8I9qOxHZ1yj5sJmg9ngsUvTAHM= | ||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
Oops, something went wrong.