From a75f5bb93e9d60bb587c5f4a6139735a8e78a22d Mon Sep 17 00:00:00 2001 From: gabrielburnworth Date: Tue, 3 Dec 2024 13:27:23 -0800 Subject: [PATCH] add model and temperature to ai_feedbacks --- .../api/ai_feedbacks_controller.rb | 5 +++- app/controllers/api/ais_controller.rb | 2 +- ...0241203211516_add_model_to_ai_feedbacks.rb | 11 ++++++++ db/structure.sql | 26 +++++-------------- 4 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 db/migrate/20241203211516_add_model_to_ai_feedbacks.rb diff --git a/app/controllers/api/ai_feedbacks_controller.rb b/app/controllers/api/ai_feedbacks_controller.rb index 071c2628aa..ab5b327553 100644 --- a/app/controllers/api/ai_feedbacks_controller.rb +++ b/app/controllers/api/ai_feedbacks_controller.rb @@ -1,7 +1,10 @@ module Api class AiFeedbacksController < Api::AbstractController def create - render json: AiFeedback.create!(update_params) + render json: AiFeedback.create!(update_params.merge( + model: ENV["OPENAI_MODEL_LUA"], + temperature: ENV["OPENAI_API_TEMPERATURE"] + )) end private diff --git a/app/controllers/api/ais_controller.rb b/app/controllers/api/ais_controller.rb index 901094c2fb..844e597257 100644 --- a/app/controllers/api/ais_controller.rb +++ b/app/controllers/api/ais_controller.rb @@ -111,7 +111,7 @@ 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_lua = ENV["OPENAI_MODEL_LUA"] || "gpt-3.5-turbo" model_other = ENV["OPENAI_MODEL_OTHER"] || "gpt-3.5-turbo" payload = { "model" => lua_request ? model_lua : model_other, diff --git a/db/migrate/20241203211516_add_model_to_ai_feedbacks.rb b/db/migrate/20241203211516_add_model_to_ai_feedbacks.rb new file mode 100644 index 0000000000..4cb3489e61 --- /dev/null +++ b/db/migrate/20241203211516_add_model_to_ai_feedbacks.rb @@ -0,0 +1,11 @@ +class AddModelToAiFeedbacks < ActiveRecord::Migration[6.1] + def up + add_column :ai_feedbacks, :model, :string, limit: 30 + add_column :ai_feedbacks, :temperature, :string, limit: 5 + end + + def down + remove_column :ai_feedbacks, :model + remove_column :ai_feedbacks, :temperature + end +end diff --git a/db/structure.sql b/db/structure.sql index 8b50915e80..c0f963f558 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9,13 +9,6 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; --- --- Name: public; Type: SCHEMA; Schema: -; Owner: - --- - --- *not* creating schema, since initdb creates it - - -- -- Name: hstore; Type: EXTENSION; Schema: -; Owner: - -- @@ -159,7 +152,9 @@ CREATE TABLE public.ai_feedbacks ( prompt character varying(500), reaction character varying(25), created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + updated_at timestamp(6) without time zone NOT NULL, + model character varying(30), + temperature character varying(5) ); @@ -1540,7 +1535,7 @@ CREATE VIEW public.resource_update_steps AS edge_nodes.kind, edge_nodes.value FROM public.edge_nodes - WHERE (((edge_nodes.kind)::text = 'resource_type'::text) AND ((edge_nodes.value)::text = ANY ((ARRAY['"GenericPointer"'::character varying, '"ToolSlot"'::character varying, '"Plant"'::character varying])::text[]))) + WHERE (((edge_nodes.kind)::text = 'resource_type'::text) AND ((edge_nodes.value)::text = ANY (ARRAY[('"GenericPointer"'::character varying)::text, ('"ToolSlot"'::character varying)::text, ('"Plant"'::character varying)::text]))) ), resource_id AS ( SELECT edge_nodes.primary_node_id, edge_nodes.kind, @@ -1715,7 +1710,7 @@ ALTER SEQUENCE public.sequence_publications_id_seq OWNED BY public.sequence_publ -- CREATE VIEW public.sequence_usage_reports AS - SELECT sequences.id AS sequence_id, + SELECT id AS sequence_id, ( SELECT count(*) AS count FROM public.edge_nodes WHERE (((edge_nodes.kind)::text = 'sequence_id'::text) AND ((edge_nodes.value)::integer = sequences.id))) AS edge_node_count, @@ -3709,14 +3704,6 @@ ALTER TABLE ONLY public.plant_templates ADD CONSTRAINT plant_templates_device_id_fk FOREIGN KEY (device_id) REFERENCES public.devices(id); --- --- Name: plant_templates plant_templates_saved_garden_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.plant_templates - ADD CONSTRAINT plant_templates_saved_garden_id_fk FOREIGN KEY (saved_garden_id) REFERENCES public.saved_gardens(id); - - -- -- Name: point_group_items point_group_items_point_group_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -3991,6 +3978,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240207234421'), ('20240405171128'), ('20240625195838'), -('20241203194030'); +('20241203194030'), +('20241203211516');