-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EN-7354 openai assistants are configured as active_records
- Loading branch information
1 parent
4ea2e05
commit b82eb09
Showing
13 changed files
with
249 additions
and
16 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/controllers/admin/openai_assistant_configurations_controller.rb
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,45 @@ | ||
module Admin | ||
class OpenaiAssistantConfigurationsController < Admin::BaseController | ||
layout 'admin_large' | ||
|
||
before_action :set_openai_assistant_configuration, only: [:edit, :update] | ||
|
||
def index | ||
@openai_assistant_configurations = OpenaiAssistantConfiguration.all | ||
.order(:version) | ||
.page(page) | ||
.per(per) | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@openai_assistant_configuration.assign_attributes(openai_assistant_configuration_params) | ||
|
||
if @openai_assistant_configuration.save | ||
redirect_to edit_admin_openai_assistant_configuration_path(@openai_assistant_configuration) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_openai_assistant_configuration | ||
@openai_assistant_configuration = OpenaiAssistantConfiguration.find(params[:id]) | ||
end | ||
|
||
def openai_assistant_configuration_params | ||
params.require(:openai_assistant_configuration).permit(:prompt, :days_for_actions, :days_for_outings, :poi_from_file, :resource_from_file) | ||
end | ||
|
||
def page | ||
params[:page] || 1 | ||
end | ||
|
||
def per | ||
params[:per] || 25 | ||
end | ||
end | ||
end |
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,2 @@ | ||
class OpenaiAssistantConfiguration < ApplicationRecord | ||
end |
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
13 changes: 13 additions & 0 deletions
13
app/views/admin/openai_assistant_configurations/_edit_header.html.erb
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,13 @@ | ||
<div class="row"> | ||
<ol class="breadcrumb"> | ||
<li><%= link_to "openai_assistant_configurations", admin_openai_assistant_configurations_path %></li> | ||
<li class="active">Modifier</li> | ||
<li style="float: right;"> | ||
Version <%= @openai_assistant_configuration.version %> | ||
</li> | ||
</ol> | ||
|
||
<h2> | ||
<span class="text-muted"># Version <%= @openai_assistant_configuration.version %></span> | ||
</h2> | ||
</div> |
50 changes: 50 additions & 0 deletions
50
app/views/admin/openai_assistant_configurations/_form.html.erb
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,50 @@ | ||
<style> | ||
.field_with_errors { display: inline-block } | ||
</style> | ||
|
||
<%= render partial: 'common/errors', locals: { obj: @openai_assistant_configuration } %> | ||
|
||
<%= form_for [:admin, @openai_assistant_configuration], html: { role: "form" } do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :prompt %> | ||
<div class="controls"> | ||
<%= f.text_area :prompt, class: "form-control", required: true %> | ||
</div> | ||
<i>{{action_type}} : en fonction de l'action créée par l'utilisateur, sera remplacé par "contribution" ou "solicitation"</i><br/> | ||
<i>{{name}} : nom de l'action créée par l'utilisateur</i><br/> | ||
<i>{{description}} : description de l'action créée par l'utilisateur</i><br/> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :days_for_actions %> | ||
<div class="controls"> | ||
<%= f.number_field :days_for_actions, class: "form-control", required: true %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :days_for_outings %> | ||
<div class="controls"> | ||
<%= f.number_field :days_for_outings, class: "form-control", required: true %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :poi_from_file, "Charger les points d'intérêt depuis un fichier ?" %> | ||
<div class="controls"> | ||
<%= f.radio_button :poi_from_file, true %> Oui | ||
<%= f.radio_button :poi_from_file, false %> Non | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :resource_from_file, "Charger les ressources pédagogiques depuis un fichier ?" %> | ||
<div class="controls"> | ||
<%= f.radio_button :resource_from_file, true %> Oui | ||
<%= f.radio_button :resource_from_file, false %> Non | ||
</div> | ||
</div> | ||
|
||
<%= f.submit 'Enregistrer', class: "btn btn-primary" %> | ||
<%= link_to "Retour", admin_openai_assistant_configurations_path, class: "btn btn-default" %> | ||
<% end %> |
4 changes: 4 additions & 0 deletions
4
app/views/admin/openai_assistant_configurations/edit.html.erb
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,4 @@ | ||
<div class="container"> | ||
<%= render 'edit_header', tab: :edit %> | ||
<%= render partial: 'form' %> | ||
</div> |
36 changes: 36 additions & 0 deletions
36
app/views/admin/openai_assistant_configurations/index.html.erb
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,36 @@ | ||
<div class="container"> | ||
<div style="margin: auto"> | ||
<h1>openai_assistant_configuration</h1> | ||
|
||
<div class="row"> | ||
<% unless @openai_assistant_configurations.none? %> | ||
<table class="table custom-table"> | ||
<thead> | ||
<th>Version</th> | ||
<th>Prompt</th> | ||
<th>poi_from_file</th> | ||
<th>resource_from_file</th> | ||
<th>days_for_actions</th> | ||
<th>days_for_outings</th> | ||
</thead> | ||
<% @openai_assistant_configurations.each_with_index do |openai_assistant_configuration, i| %> | ||
<% parite = i.even? ? 'pair' : 'impair' %> | ||
|
||
<tr class="above-row row-<%= parite %>"> | ||
<td><%= link_to openai_assistant_configuration.version, edit_admin_openai_assistant_configuration_path(openai_assistant_configuration) %></td> | ||
<td><%= link_to openai_assistant_configuration.prompt, edit_admin_openai_assistant_configuration_path(openai_assistant_configuration) %></td> | ||
<td><%= openai_assistant_configuration.poi_from_file %></td> | ||
<td><%= openai_assistant_configuration.resource_from_file %></td> | ||
<td><%= openai_assistant_configuration.days_for_actions %></td> | ||
<td><%= openai_assistant_configuration.days_for_outings %></td> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
</div> | ||
|
||
<%= page_entries_info @openai_assistant_configurations, entry_name: 'openai_assistant_configurations' %> | ||
<div class="container"> | ||
<%= paginate(@openai_assistant_configurations) %> | ||
</div> | ||
</div> | ||
</div> |
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
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
19 changes: 19 additions & 0 deletions
19
db/migrate/20241127115900_create_openai_assistant_configurations.rb
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,19 @@ | ||
class CreateOpenaiAssistantConfigurations < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :openai_assistant_configurations do |t| | ||
t.integer :version, unique: true | ||
t.string :api_key, null: false | ||
t.string :assistant_id, null: false | ||
|
||
t.text :prompt, null: false | ||
|
||
t.boolean :poi_from_file, default: false | ||
t.boolean :resource_from_file, default: false | ||
|
||
t.integer :days_for_actions, default: 30 | ||
t.integer :days_for_outings, default: 30 | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
db/migrate/20241127115901_create_openai_assistant_configuration_instance.rb
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,18 @@ | ||
class CreateOpenaiAssistantConfigurationInstance < ActiveRecord::Migration[6.1] | ||
def change | ||
unless Rails.env.test? | ||
prompt = "I created a {{action_type}} \"{{name}}\" : {{description}}. What are the most relevant recommandations? The following text contains all the possible recommandations." | ||
|
||
OpenaiAssistantConfiguration.new( | ||
version: 1, | ||
api_key: ENV['OPENAI_API_KEY'], | ||
assistant_id: ENV['OPENAI_API_ASSISTANT_ID'], | ||
prompt: prompt, | ||
poi_from_file: true, | ||
resource_from_file: true, | ||
days_for_actions: 30, | ||
days_for_outings: 30 | ||
).save | ||
end | ||
end | ||
end |
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
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