Skip to content

Commit

Permalink
gpt question
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandr Karachev committed Nov 15, 2024
1 parent a9cfba9 commit b73f52c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 21 additions & 7 deletions backend/views/test/gpt/_question.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,22 @@
createPrompt(newPromptId, name, prompt, 'question').then(r => {

if (r.success) {
const select = $('#gptquestionupdateform-promptid')
const select = $('.gptPromptId')
select.find('option').map((i, el) => {
if (el.value !== '') {
el.remove()
}
})
r.prompts.map(p => $('<option/>', {value: p.id, text: p.name, selected: p.id === newPromptId}).appendTo(select))
select.blur()
}

$('#prompt-create-modal').modal('hide')
})
})

$('#prompt-update-modal').find('#gpt-prompt-save').on('click', e => {
const id = $('#gptquestionupdateform-promptid').val()
const id = $('.gptPromptId').val()

const name = $('#prompt-update-modal').find('#gpt-prompt-name').val()
if (!name) {
Expand All @@ -94,13 +95,13 @@
return
}
savePrompt(id, name, prompt).then(r => {
$('#gptquestionupdateform-promptid').find('option:selected').text(name)
$('.gptPromptId').find('option:selected').text(name)
$('#prompt-update-modal').modal('hide')
})
})

$('#prompt-update').on('click', e => {
const id = $('#gptquestionupdateform-promptid').val()
const id = $('.gptPromptId').val()
fetchPrompt(id).then(r => {
const modal = $('#prompt-update-modal')
modal.find('#gpt-prompt').html(r.prompt)
Expand Down Expand Up @@ -146,10 +147,14 @@
}

$('#run-job-modal').find('#job-send').on('click', e => {
const promptId = $('#gptquestionupdateform-promptid').val()
const job = $('#gptquestionupdateform-job').html()
const promptId = $('.gptPromptId').val()
const job = $('.gptJob').html()
const userResponse = $('#run-job-modal').find('#gpt-user-response').val()

if (!job || !userResponse) {
return
}

const elem = document.createElement('div')
elem.classList.add('run-job-message-item')
elem.innerText = '...'
Expand All @@ -164,11 +169,20 @@
})

$('#run-job').on('click', e => {
const job = $('#gptquestionupdateform-job').html()
const job = $('.gptJob').html()
$('#run-job-modal')
.find('#run-job-text')
.html(job)
.end()
.modal('show')
})

$('.gptPromptId').on('change', e => {
const value = e.target.value
const ids = ['#prompt-update', '#run-job']
ids.map(id => $(id).hide())
if (value) {
ids.map(id => $(id).show())
}
})
})();
4 changes: 2 additions & 2 deletions backend/views/test/gpt/_question.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<?php
$form = ActiveForm::begin(['id' => 'gpt-question-form']) ?>
<?= $form->field($formModel, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($formModel, 'job')->textarea(['rows' => 10]) ?>
<?= $form->field($formModel, 'job')->textarea(['rows' => 10, 'class' => 'form-control gptJob']) ?>
<div>
<?= $form->field($formModel, 'promptId')->dropDownList($prompts, ['prompt' => 'Выберите промт']) ?>
<?= $form->field($formModel, 'promptId')->dropDownList($prompts, ['prompt' => 'Выберите промт', 'class' => 'form-control gptPromptId']) ?>
<div style="margin-bottom: 30px">
<button id="prompt-update" style="display: <?= empty($formModel->promptId) ? 'none' : 'inline-block' ?>"
type="button" class="btn btn-success btn-sm">Изменить
Expand Down

0 comments on commit b73f52c

Please sign in to comment.