Skip to content

Commit

Permalink
Merge pull request #2446 from FarmBot/staging
Browse files Browse the repository at this point in the history
v15.8.8
  • Loading branch information
gabrielburnworth authored Nov 11, 2023
2 parents b4b8b12 + 1e29434 commit 2ab93e0
Show file tree
Hide file tree
Showing 49 changed files with 975 additions and 107 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faker (3.2.1)
faker (3.2.2)
i18n (>= 1.8.11, < 2)
faraday (1.10.3)
faraday-em_http (~> 1.0)
Expand Down Expand Up @@ -221,7 +221,7 @@ GEM
multipart-post (2.3.0)
mutations (0.9.1)
activesupport
net-imap (0.4.2)
net-imap (0.4.4)
date
net-protocol
net-pop (0.1.2)
Expand Down Expand Up @@ -251,7 +251,7 @@ GEM
faraday_middleware (~> 1.2)
hashie (~> 4.1)
multi_json (~> 1.15)
racc (1.7.1)
racc (1.7.2)
rack (2.2.8)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
Expand Down Expand Up @@ -292,7 +292,7 @@ GEM
method_source
rake (>= 12.2)
thor (~> 1.0)
rake (13.0.6)
rake (13.1.0)
rbtree (0.4.6)
redis (4.8.1)
representable (3.2.0)
Expand Down
16 changes: 12 additions & 4 deletions app/controllers/api/ais_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ def make_request(system_prompt, user_prompt, stream)
url = "https://api.openai.com/v1/chat/completions"
context_key = raw_json[:context_key]
lua_request = context_key == "lua"
model_lua = ENV["OPENAI_MODEL_LUA"] || "gpt-3.5-turbo-16k"
model_other = ENV["OPENAI_MODEL_OTHER"] || "gpt-3.5-turbo"
payload = {
"model" => lua_request ? "gpt-3.5-turbo-16k" : "gpt-3.5-turbo",
"model" => lua_request ? model_lua : model_other,
"messages" => [
{role: "system", content: system_prompt},
{role: "user", content: user_prompt},
Expand All @@ -131,9 +133,11 @@ def make_request(system_prompt, user_prompt, stream)
full = ""
response = conn.post("") do |req|
req.body = payload
buffer = ""
total = 0
missed = false
req.options.on_data = Proc.new do |chunk, size|
buffer += chunk
total += chunk.bytes.length
diff = size - total
if (diff != 0 && !missed) || Rails.env.test?
Expand All @@ -142,9 +146,12 @@ def make_request(system_prompt, user_prompt, stream)
current_device.tell("Response stream incomplete.", ["toast"], "warn")
missed = true
end
data_strings = chunk.split("data: ")[1,999]
for data_str in data_strings
data = JSON.parse(data_str)
boundary = buffer.index("\n\n")
while not boundary.nil?
data_str = buffer.slice(0, boundary)
buffer = buffer.slice(boundary + 2, buffer.length)
json_string = data_str.split("data: ")[1]
data = JSON.parse(json_string)
output = data["choices"][0]
if output["finish_reason"].nil?
content = output["delta"].dig("content") || ""
Expand All @@ -157,6 +164,7 @@ def make_request(system_prompt, user_prompt, stream)
stream.close
return {}
end
boundary = buffer.index("\n\n")
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/api/demo_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def create
private

def create_params
@create_params ||= { secret: raw_json.fetch(:secret) }
@create_params ||= {
secret: raw_json.fetch(:secret),
product_line: raw_json.fetch(:product_line),
}
end
end
end
2 changes: 2 additions & 0 deletions app/models/fbos_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class MissingSerial < StandardError; end
FARMDUINO_K14 = "farmduino_k14",
FARMDUINO_K15 = "farmduino_k15",
FARMDUINO_K16 = "farmduino_k16",
FARMDUINO_K17 = "farmduino_k17",
EXPRESS_K10 = "express_k10",
EXPRESS_K11 = "express_k11",
EXPRESS_K12 = "express_k12",
]
end
13 changes: 12 additions & 1 deletion app/mutations/devices/create_seed_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ class CreateSeedData < Mutations::Command
PRODUCT_LINES = {
"express_1.0" => Devices::Seeders::ExpressOneZero,
"express_1.1" => Devices::Seeders::ExpressOneOne,
"express_1.2" => Devices::Seeders::ExpressOneTwo,
"express_xl_1.0" => Devices::Seeders::ExpressXlOneZero,
"express_xl_1.1" => Devices::Seeders::ExpressXlOneOne,
"express_xl_1.2" => Devices::Seeders::ExpressXlOneTwo,

"genesis_1.2" => Devices::Seeders::GenesisOneTwo,
"genesis_1.3" => Devices::Seeders::GenesisOneThree,
"genesis_1.4" => Devices::Seeders::GenesisOneFour,
"genesis_1.5" => Devices::Seeders::GenesisOneFive,
"genesis_1.6" => Devices::Seeders::GenesisOneSix,
"genesis_1.7" => Devices::Seeders::GenesisOneSeven,
"genesis_xl_1.4" => Devices::Seeders::GenesisXlOneFour,
"genesis_xl_1.5" => Devices::Seeders::GenesisXlOneFive,
"genesis_xl_1.6" => Devices::Seeders::GenesisXlOneSix,
"genesis_xl_1.7" => Devices::Seeders::GenesisXlOneSeven,

"demo_account" => Devices::Seeders::DemoAccountSeeder,
"none" => Devices::Seeders::None,
}

Expand All @@ -24,6 +27,10 @@ class CreateSeedData < Mutations::Command
string :product_line, in: PRODUCT_LINES.keys
end

optional do
boolean :demo
end

def execute
self.delay.run_seeds!
{ done: "Loading resources now." }
Expand All @@ -37,6 +44,10 @@ def run_seeds!
seeder.class::COMMAND_ORDER.map do |cmd|
seeder.send(cmd)
end

if demo
Devices::Seeders::DemoAccountSeeder.new(device).misc(product_line)
end
end
end
end
31 changes: 21 additions & 10 deletions app/mutations/devices/seeders/demo_account_seeder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Devices
module Seeders
class DemoAccountSeeder < ExpressOneZero
class DemoAccountSeeder < AbstractSeeder
BASE_URL = "/app-resources/img/demo_accounts/"
FEEDS = {
"Express XL" => "Express_XL_Demo_Webcam.JPG",
Expand All @@ -10,14 +10,19 @@ class DemoAccountSeeder < ExpressOneZero
}
UNUSED_ALERTS = ["api.seed_data.missing", "api.user.not_welcomed"]

def webcam_feeds
# device.webcam_feeds.destroy_all!
FEEDS.map do |(name, url)|
p = { name: name,
url: (BASE_URL + url),
device: device }
WebcamFeeds::Create.run!(p)
end
def feed(product_line)
feed_name = ""
feed_name += "Genesis" if product_line.include?("genesis")
feed_name += "Express" if product_line.include?("express")
feed_name += " XL" if product_line.include?("xl")
feed_name
end

def create_webcam_feed(product_line)
feed_name = feed(product_line)
WebcamFeeds::Create.run!({ name: feed_name,
url: BASE_URL + FEEDS[feed_name],
device: device })
end

def plants
Expand Down Expand Up @@ -69,7 +74,13 @@ def point_groups_beet
# tester FBOS version `1000.0.0`.
READ_COMMENT_ABOVE = "100.0.0"

def misc
def misc(product_line)
create_webcam_feed(product_line)
plants
point_groups_spinach
point_groups_broccoli
point_groups_beet

device.alerts.where(problem_tag: UNUSED_ALERTS).destroy_all
DEMO_ALERTS
.map { |p| p.merge(device: device) }
Expand Down
11 changes: 11 additions & 0 deletions app/mutations/devices/seeders/express_one_two.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Devices
module Seeders
class ExpressOneTwo < AbstractExpress
def settings_firmware
device
.fbos_config
.update!(firmware_hardware: FbosConfig::EXPRESS_K12)
end
end
end
end
23 changes: 23 additions & 0 deletions app/mutations/devices/seeders/express_xl_one_two.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Devices
module Seeders
class ExpressXlOneTwo < AbstractExpress
def settings_device_name
device.update!(name: Names::EXPRESS_XL)
end

def settings_firmware
device
.fbos_config
.update!(firmware_hardware: FbosConfig::EXPRESS_K12)
end

def settings_default_map_size_x
device.web_app_config.update!(map_size_x: 6_000)
end

def settings_default_map_size_y
device.web_app_config.update!(map_size_y: 2_400)
end
end
end
end
77 changes: 77 additions & 0 deletions app/mutations/devices/seeders/genesis_one_seven.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module Devices
module Seeders
class GenesisOneSeven < AbstractGenesis
def settings_firmware
device
.fbos_config
.update!(firmware_hardware: FbosConfig::FARMDUINO_K17)
end

def settings_change_firmware_config_defaults
end

def peripherals_rotary_tool
add_peripheral(2, ToolNames::ROTARY_TOOL)
end

def peripherals_rotary_tool_reverse
add_peripheral(3, ToolNames::ROTARY_TOOL_REVERSE)
end

def tool_slots_slot_6
add_tool_slot(name: ToolNames::ROTARY_TOOL,
x: 50,
y: 700,
z: -200,
tool: tools_rotary)
end

def tool_slots_slot_7
add_tool_slot(name: ToolNames::SEED_TROUGH_1,
x: 0,
y: 25,
z: -100,
tool: tools_seed_trough_1,
pullout_direction: ToolSlot::NONE,
gantry_mounted: true)
end

def tool_slots_slot_8
add_tool_slot(name: ToolNames::SEED_TROUGH_2,
x: 0,
y: 50,
z: -100,
tool: tools_seed_trough_2,
pullout_direction: ToolSlot::NONE,
gantry_mounted: true)
end

def tool_slots_slot_9; end

def tools_weeder; end

def tools_rotary
@tools_rotary ||=
add_tool(ToolNames::ROTARY_TOOL)
end

def tools_seed_trough_1
@tools_seed_trough_1 ||=
add_tool(ToolNames::SEED_TROUGH_1)
end

def tools_seed_trough_2
@tools_seed_trough_2 ||=
add_tool(ToolNames::SEED_TROUGH_2)
end

def sequences_mow_all_weeds
success = install_sequence_version_by_name(PublicSequenceNames::MOW_ALL_WEEDS)
if !success
s = SequenceSeeds::MOW_ALL_WEEDS.deep_dup
Sequences::Create.run!(s, device: device)
end
end
end
end
end
Loading

0 comments on commit 2ab93e0

Please sign in to comment.