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

Using gen-ai gem #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

source 'https://rubygems.org'

gem 'gemini-ai', '~> 4.2.0'
gem 'gen-ai', '~> 0.4.2'
gem 'dotenv'
59 changes: 22 additions & 37 deletions lib/main.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,36 @@
# frozen_string_literal: true

require 'dotenv/load'
require 'gen_ai'
require 'dotenv'
require 'gemini-ai'

# With an API key
client = Gemini.new(
credentials: {
service: 'generative-language-api',
api_key: ENV['GOOGLE_GEMINI_TOKEN']
},
options: { model: 'gemini-pro', server_sent_events: true }
)
model = GenAI::Language.new(:gemini, ENV['GOOGLE_GEMINI_TOKEN'])

text_request = <<-TEXT
この日報フォーマットに情報を追加てください。
# text_request = <<-TEXT
# この日報フォーマットに情報を追加てください。

"A様
# "A様

お疲れ様です。ホアンクアンです。
# お疲れ様です。ホアンクアンです。

本日の業務内容を報告していたします。
# 本日の業務内容を報告していたします。

業務内容:
1. プロジェクト1
- タスク1:
進捗状況: %
# 業務内容:
# 1. プロジェクト1
# - タスク1:
# 進捗状況: %

課題
# 課題

明日の予定
1. プロジェクト1
プロジェクト1の予定
# 明日の予定
# 1. プロジェクト1
# プロジェクト1の予定

以上、本日の報告とさせていただきます。"
TEXT
# 以上、本日の報告とさせていただきます。"
# TEXT

Dir.glob('./input/*.txt').each do |file_name|
text_request += File.read(file_name)
end
# Dir.glob('./input/*.txt').each do |file_name|
# text_request += File.read(file_name)
# end

result = client.stream_generate_content({
contents: { role: 'user', parts: { text: text_request } }
})

mail_template = result
.map { |response| response.dig('candidates', 0, 'content', 'parts') }
.map { |parts| parts.map { |part| part['text'] }.join }
.join

puts mail_template
# model.chat(text_request)