Skip to content

Commit 0e82772

Browse files
committed
Code formating + autofocus on prompt form
1 parent 2be315a commit 0e82772

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

Diff for: src/templates/functions.twig

+29-30
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,35 @@ $('#my-awesome-modal').attr('data-layout-element', that.attr('data-layout-elemen
6666
});*/
6767

6868
function sendRequest(prompt, query, textField, hash) {
69-
70-
$.ajax({
71-
type: "POST",
72-
url: "https://api.openai.com/v1/chat/completions",
73-
//url: "https://api.openai.com/v1/edits",
74-
beforeSend: function (xhr) {
75-
xhr.setRequestHeader("Authorization", "Bearer {{ settings.getAccessToken }}");
76-
},
77-
data: JSON.stringify({
78-
"model": "gpt-3.5-turbo",
79-
"messages": [{"role": "user", "content": prompt + query }],
80-
"temperature": 0.7,
81-
"max_tokens": {{ settings.maxTokens }},
82-
"top_p": 1,
83-
"frequency_penalty": 0,
84-
"presence_penalty": 0
85-
}),
86-
success: function(data) {
87-
let result = data.choices[0].message.content;
88-
let state = data.choices[0].finish_reason;
89-
90-
if ($('button[data-hash="' + hash + '"]').closest('.field').attr('data-type') == 'craft\\redactor\\Field') {
91-
let textareaId = textField.attr('id');
92-
$R('#' + textareaId, 'source.setCode', result);
93-
} else {
94-
$(textField).val(result);
95-
}
96-
if(state == 'length') {
97-
alert({{ 'The reply has exceeded the specified maximum length. To fix this, either increase the value of the max_token setting or try telling chat-gpt to limit itself to a certain number of words.'|t('chatgpt-integration') }});
98-
}}
69+
$.ajax({
70+
type: "POST",
71+
url: "https://api.openai.com/v1/chat/completions",
72+
//url: "https://api.openai.com/v1/edits",
73+
beforeSend: function (xhr) {
74+
xhr.setRequestHeader("Authorization", "Bearer {{ settings.getAccessToken }}");
75+
},
76+
data: JSON.stringify({
77+
"model": "gpt-3.5-turbo",
78+
"messages": [{"role": "user", "content": prompt + query }],
79+
"temperature": 0.7,
80+
"max_tokens": {{ settings.maxTokens }},
81+
"top_p": 1,
82+
"frequency_penalty": 0,
83+
"presence_penalty": 0
84+
}),
85+
success: function(data) {
86+
let result = data.choices[0].message.content;
87+
let state = data.choices[0].finish_reason;
88+
89+
if ($('button[data-hash="' + hash + '"]').closest('.field').attr('data-type') == 'craft\\redactor\\Field') {
90+
let textareaId = textField.attr('id');
91+
$R('#' + textareaId, 'source.setCode', result);
92+
} else {
93+
$(textField).val(result);
94+
}
95+
if(state == 'length') {
96+
alert('{{ 'The reply has exceeded the specified maximum length. To fix this, either increase the value of the max_token setting or try telling chat-gpt to limit itself to a certain number of words.'|t('chatgpt-integration') }}');
97+
}
9998
},
10099
contentType: "application/json; charset=utf-8",
101100
dataType: "json"

Diff for: src/templates/prompts/_includes/promptFormFields.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
errors: prompt.getErrors('label'),
77
required: true,
88
first: true,
9-
value: prompt.label
9+
value: prompt.label,
10+
autofocus: true,
1011
}) }}
1112

1213
{{ forms.textAreaField({

0 commit comments

Comments
 (0)