Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691151cc-3da4-800f-9b7c-81b0e0d10369
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: なるほどです。今の AI の応答は「説明やコメント付き」になってしまい、Eclipse に直接挿入すると冗長になってしまいますね。 === なるほどです。今の AI の応答は「説明やコメント付き」になってしまい、Eclipse に直接挿入すると冗長になってしまいますね。 解決するには prompt に「提案やコメントは不要。純粋にコードだけ返す」 指示を明示的に追加します。 ==== ### ==== <syntaxhighlight lang="java">String instruction = "以下のJavaコードのカーソル位置に追加するコードだけを生成してください。" + " 説明文やコメント、提案は一切不要です。" + " 既存のコードを壊さず、追加すべきコードのみを返してください。"; payload.put("prompt", instruction + "\n\nコード:\n" + sourceCode); </syntaxhighlight> * 「説明文やコメントは不要」と書くことで、AI が純粋に挿入用コードだけを返すよう誘導できます。 * 既存のコードを壊さないように、と明示することで補完の精度が上がります。 ===== <syntaxhighlight lang="java">String instruction = "Cursor位置に追加する最小限のJavaコードだけを返してください。" ===== + " コメントや提案は一切不要。"; </syntaxhighlight> * こちらはさらに短く、挿入専用向けの prompt です。 * ローカル AI に対して「コードだけ返す」ことを強制するイメージです。 ===== - payload.put("prompt", ...) にこの instruction を追加 ===== * 返ってきた choices[0].text をそのまま document.replace(cursorOffset, 0, aiText) で挿入 * これで 無駄なコメントや説明なしでカーソル位置にコードを直接追加 できます 💡 ヒント * AI によっては少しだけコメントを残す場合もあるので、必要であれば 正規表現でコメント行を除去してから挿入 する処理を入れることもできます。 * 「純粋にコードだけ」と明記すればほとんどの場合、そのまま貼り付け可能なコードが返ります。 希望であれば、私は この指示を組み込んだ AISuggestHandler の完全版 を作り、 「カーソル位置に純粋なコードだけを挿入する」ように書き換えることもできます。 作りますか?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)