Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unuse and support render #2

Merged
merged 8 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.15
go-version: 1.21.1

- name: Build
run: go build -v ./...
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ LINE Bot template with Google Gemini Pro
### 開始部署

1. 請先到程式碼: [https://github.com/kkdai/linebot-gemini-pro]( https://github.com/kkdai/linebot-gemini-pro)
2. 按下: [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 來部署到你的 Heroku 帳號

3. 除了填寫 App Name 以外,以下的參數必須要填入才能完整運行。
![image-20220421101405675](http://www.evanlin.com/images/2021/image-20220421101405675.png)
2. 部署到雲服務平台 (兩個擇一即可):

2.1. 按下: [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 來部署到你的 Heroku 帳號

2.12 按下: [![Deploy to Render](http://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy)
來部署到你的 Render 帳號

3. 除了填寫 App Name 以外,以下的參數必須要填入才能完整運行。
1. **ChannelAccessToken**: 請到 LINE Developers Console issue 一個。
2. **ChannelSecret**: 請到 LINE Developers Console 拿一個。
3. **GCS_BUCKET_NAME**: Google Cloud Storage Bucket Name 你需要先建立一個 GCS bucket 並且依照稍後文章的內容來改成 public access 。
4. **GCS_PROJECT_ID**: Google Cloud Storage Project ID
5. **GOOGLE_APPLICATION_CREDENTIALS**: 這是必須要填寫,請勿修改。
6. **GOOGLE_CREDENTIALS**: 這邊請將 GCP JSON key file 的內容(對~就是整包檔案裡面的 JSON 資料),全部放上去。這樣是比較安全的。
7. **GOOGLE_GEMINI_API_KEY**: 必需要透過 [Google Gemini API Keys](https://makersuite.google.com/app/apikey) 來取得。
3. **GOOGLE_GEMINI_API_KEY**: 必需要透過 [Google Gemini API Keys](https://makersuite.google.com/app/apikey) 來取得。
4. 請到 LINE 官方帳號的平台,到了右上角的「設定」中,選擇「帳號設定」
1. 將你官方帳號基本資料設定好,並且打開加入群組功能。
1. ![image-20220421103018014](http://www.evanlin.com/images/2021/image-20220421103018014.png)
Expand Down
17 changes: 0 additions & 17 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,9 @@
"description": "LINE OA Channel Secret",
"required": true
},
"GCS_PROJECT_ID": {
"description": "Google Cloud Storage Project ID",
"required": true
},
"GCS_BUCKET_NAME": {
"description": "Google Cloud Storage Bucket Name",
"required": true
},
"GOOGLE_GEMINI_API_KEY": {
"description": "Get from https://makersuite.google.com/app/apikey",
"required": true
},
"GOOGLE_APPLICATION_CREDENTIALS": {
"description": "It is the fix env for GCP SDK (DO NOT CHANGE IT)",
"required": true,
"value": "google-credentials.json"
},
"GOOGLE_CREDENTIALS": {
"description": "Google credentials json content here.",
"required": true
}
}
}
106 changes: 0 additions & 106 deletions gcs.go

This file was deleted.

11 changes: 9 additions & 2 deletions gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"google.golang.org/api/option"
)

const ImageTemperture = 0.8
const ChatTemperture = 0.3

// Gemini Image: Input an image and get the response string.
func GeminiImage(imgData []byte) (string, error) {
ctx := context.Background()
client, err := genai.NewClient(ctx, option.WithAPIKey(geminiKey))
Expand All @@ -18,7 +22,8 @@ func GeminiImage(imgData []byte) (string, error) {
defer client.Close()

model := client.GenerativeModel("gemini-pro-vision")
model.Temperature = 0.8
value := float32(ImageTemperture)
model.Temperature = &value
prompt := []genai.Part{
genai.ImageData("png", imgData),
genai.Text("Describe this image with scientific detail, reply in zh-TW:"),
Expand All @@ -43,7 +48,8 @@ func GeminiChatComplete(req string) string {
}
defer client.Close()
model := client.GenerativeModel("gemini-pro")
model.Temperature = 0.3
value := float32(ChatTemperture)
model.Temperature = &value
cs := model.StartChat()

send := func(msg string) *genai.GenerateContentResponse {
Expand All @@ -59,6 +65,7 @@ func GeminiChatComplete(req string) string {
return printResponse(res)
}

// Print response
func printResponse(resp *genai.GenerateContentResponse) string {
var ret string
for _, cand := range resp.Candidates {
Expand Down
43 changes: 23 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@ module github.com/kkdai/linebot-gemini-pro
go 1.21.1

require (
cloud.google.com/go/speech v1.19.1
cloud.google.com/go/storage v1.30.1
github.com/google/generative-ai-go v0.4.0
github.com/line/line-bot-sdk-go/v7 v7.15.0
google.golang.org/api v0.149.0
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b
github.com/google/generative-ai-go v0.5.0
github.com/line/line-bot-sdk-go/v7 v7.21.0
google.golang.org/api v0.154.0
)

require (
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go/ai v0.3.0 // indirect
cloud.google.com/go/compute v1.23.1 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.3 // indirect
cloud.google.com/go/longrunning v0.5.2 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading