11package com.github.blarc.ai.commits.intellij.plugin.settings
22
3+ import com.aallam.openai.api.http.Timeout
34import com.aallam.openai.client.OpenAIConfig
45import com.aallam.openai.client.OpenAIHost
56import com.aallam.openai.client.ProxyConfig
@@ -18,22 +19,25 @@ import com.intellij.util.xmlb.Converter
1819import com.intellij.util.xmlb.XmlSerializerUtil
1920import com.intellij.util.xmlb.annotations.OptionTag
2021import java.util.*
22+ import kotlin.time.Duration.Companion.seconds
2123
2224@State(
23- name = AppSettings .SERVICE_NAME ,
24- storages = [Storage (" AICommit.xml" )]
25+ name = AppSettings .SERVICE_NAME ,
26+ storages = [Storage (" AICommit.xml" )]
2527)
2628class AppSettings : PersistentStateComponent <AppSettings > {
2729
2830 private val openAITokenTitle = " OpenAIToken"
2931 private var hits = 0
32+
3033 @OptionTag(converter = LocaleConverter ::class )
3134 var locale: Locale = Locale .ENGLISH
3235
3336 var requestSupport = true
3437 var lastVersion: String? = null
3538 var openAIHost = OpenAIHost .OpenAI .baseUrl
3639 var openAIHosts = mutableSetOf (OpenAIHost .OpenAI .baseUrl)
40+ var openAISocketTimeout = " 30"
3741 var proxyUrl: String? = null
3842
3943 var prompts = initPrompts()
@@ -62,9 +66,10 @@ class AppSettings : PersistentStateComponent<AppSettings> {
6266 fun getOpenAIConfig (): OpenAIConfig {
6367 val token = getOpenAIToken() ? : throw Exception (" OpenAI Token is not set." )
6468 return OpenAIConfig (
65- token,
66- host = openAIHost.takeIf { it.isNotBlank() }?.let { OpenAIHost (it) } ? : OpenAIHost .OpenAI ,
67- proxy = proxyUrl?.takeIf { it.isNotBlank() }?.let { ProxyConfig .Http (it) }
69+ token,
70+ host = openAIHost.takeIf { it.isNotBlank() }?.let { OpenAIHost (it) } ? : OpenAIHost .OpenAI ,
71+ proxy = proxyUrl?.takeIf { it.isNotBlank() }?.let { ProxyConfig .Http (it) },
72+ timeout = Timeout (socket = openAISocketTimeout.toInt().seconds)
6873 )
6974 }
7075
@@ -76,10 +81,10 @@ class AppSettings : PersistentStateComponent<AppSettings> {
7681
7782 private fun getCredentialAttributes (title : String ): CredentialAttributes {
7883 return CredentialAttributes (
79- title,
80- null ,
81- this .javaClass,
82- false
84+ title,
85+ null ,
86+ this .javaClass,
87+ false
8388 )
8489 }
8590
@@ -101,38 +106,44 @@ class AppSettings : PersistentStateComponent<AppSettings> {
101106 }
102107
103108 private fun initPrompts () = mutableMapOf (
104- // Generate UUIDs for game objects in Mine.py and call the function in start_game().
105- " basic" to Prompt (" Basic" ,
106- " Basic prompt that generates a decent commit message." ,
107- " Write an insightful but concise Git commit message in a complete sentence in present tense for the " +
108- " following diff without prefacing it with anything, the response must be in the language {locale} and must " +
109- " NOT be longer than 74 characters. The sent text will be the differences between files, where deleted lines" +
110- " are prefixed with a single minus sign and added lines are prefixed with a single plus sign.\n " +
111- " {diff}" ,
112- false ),
113- // feat: generate unique UUIDs for game objects on Mine game start
114- " conventional" to Prompt (" Conventional" ,
115- " Prompt for commit message in the conventional commit convention." ,
116- " Write a commit message in the conventional commit convention. I'll send you an output " +
117- " of 'git diff --staged' command, and you convert it into a commit message. " +
118- " Lines must not be longer than 74 characters. Use {locale} language to answer. " +
119- " End commit title with issue number if you can get it from the branch name: " +
120- " {branch} in parenthesis.\n " +
121- " {diff}" ,
122- false ),
123- // ✨ feat(mine): Generate objects UUIDs and start team timers on game start
124- " emoji" to Prompt (" Emoji" ,
125- " Prompt for commit message in the conventional commit convention with GitMoji convention." ,
126- " Write a clean and comprehensive commit message in the conventional commit convention. " +
127- " I'll send you an output of 'git diff --staged' command, and you convert " +
128- " it into a commit message. " +
129- " Use GitMoji convention to preface the commit. " +
130- " Do NOT add any descriptions to the commit, only commit message. " +
131- " Use the present tense. " +
132- " Lines must not be longer than 74 characters. " +
133- " Use {locale} language to answer.\n " +
134- " {diff}" ,
135- false )
109+ // Generate UUIDs for game objects in Mine.py and call the function in start_game().
110+ " basic" to Prompt (
111+ " Basic" ,
112+ " Basic prompt that generates a decent commit message." ,
113+ " Write an insightful but concise Git commit message in a complete sentence in present tense for the " +
114+ " following diff without prefacing it with anything, the response must be in the language {locale} and must " +
115+ " NOT be longer than 74 characters. The sent text will be the differences between files, where deleted lines" +
116+ " are prefixed with a single minus sign and added lines are prefixed with a single plus sign.\n " +
117+ " {diff}" ,
118+ false
119+ ),
120+ // feat: generate unique UUIDs for game objects on Mine game start
121+ " conventional" to Prompt (
122+ " Conventional" ,
123+ " Prompt for commit message in the conventional commit convention." ,
124+ " Write a commit message in the conventional commit convention. I'll send you an output " +
125+ " of 'git diff --staged' command, and you convert it into a commit message. " +
126+ " Lines must not be longer than 74 characters. Use {locale} language to answer. " +
127+ " End commit title with issue number if you can get it from the branch name: " +
128+ " {branch} in parenthesis.\n " +
129+ " {diff}" ,
130+ false
131+ ),
132+ // ✨ feat(mine): Generate objects UUIDs and start team timers on game start
133+ " emoji" to Prompt (
134+ " Emoji" ,
135+ " Prompt for commit message in the conventional commit convention with GitMoji convention." ,
136+ " Write a clean and comprehensive commit message in the conventional commit convention. " +
137+ " I'll send you an output of 'git diff --staged' command, and you convert " +
138+ " it into a commit message. " +
139+ " Use GitMoji convention to preface the commit. " +
140+ " Do NOT add any descriptions to the commit, only commit message. " +
141+ " Use the present tense. " +
142+ " Lines must not be longer than 74 characters. " +
143+ " Use {locale} language to answer.\n " +
144+ " {diff}" ,
145+ false
146+ )
136147 )
137148
138149 class LocaleConverter : Converter <Locale >() {
0 commit comments