@@ -32,7 +32,6 @@ public void Initialize(string sourceCode, string resultCode)
3232 _sourceCode = sourceCode ;
3333 _resultCode = resultCode ;
3434 _defaultCommand = $ "- Translate to { resultCode } , keep special characters, and output only the translation.";
35- //_defaultCommand = $"- {_sourceCode} -> {_resultCode} result only";
3635 }
3736
3837 public void InitializeModel ( string model , string apiKey , bool useDefaultModel )
@@ -92,15 +91,10 @@ private async Task<string> InternalTranslateTextAsync(string requestText, string
9291 new { role = "user" , parts = new [ ] { new { text = requestText } } }
9392 } ,
9493
95-
9694 generationConfig = new
9795 {
98- //추론기능 - 0은 끈 상태
99- thinkingConfig = new
100- {
101- thinkingBudget = 0
102- } ,
103- temperature = 0.2f // float 값으로 설정 (0.0f ~ 1.0f 사이)
96+ thinkingConfig = new { thinkingBudget = 0 } ,
97+ temperature = 0.2f
10498 }
10599
106100 /*
@@ -183,40 +177,43 @@ private async Task<string> InternalTranslateTextAsync(string requestText, string
183177 private void InitializeCommand ( )
184178 {
185179 _resultCommand = "" ;
186- bool useCommand = false ;
180+
181+ // 1. 커스텀 명령이 있다면 먼저 추가 (예: "- 무조건 경어로 번역해줘")
187182 if ( ! string . IsNullOrEmpty ( _command ) )
188183 {
189184 _resultCommand += $ "- { _command } ";
190- useCommand = true ;
191185 }
192186
193- if ( ! useCommand || ( useCommand && ! _disableDefaultCommand ) )
187+ // 2. 기본 명령을 추가해야 하는 경우
188+ // 조건: 커스텀 명령이 없거나 (useCommand = false)
189+ // 커스텀 명령이 있고 기본 명령을 비활성화하지 않은 경우
190+ bool useDefault = string . IsNullOrEmpty ( _command ) || ( ! _disableDefaultCommand ) ;
191+
192+ if ( useDefault )
194193 {
195- if ( useCommand )
194+ // 3. 커스텀 명령이 이미 있을 경우에만 공백(' ') 하나를 삽입하여 토큰 낭비 최소화
195+ if ( ! string . IsNullOrEmpty ( _resultCommand ) )
196196 {
197- _resultCommand += System . Environment . NewLine ;
197+ _resultCommand += " " ;
198198 }
199+
200+ // 4. 기본 명령 추가
199201 _resultCommand += $ "{ _defaultCommand } ";
200202 }
201203
202-
203204 _inited = true ;
204205 }
205206
206- private string CombineText ( string text )
207+ private string CombineTextOptimized ( string text )
207208 {
208209 if ( ! string . IsNullOrEmpty ( _command ) && _disableDefaultCommand )
209210 {
210- return _command + System . Environment . NewLine + System . Environment . NewLine + text ;
211+ return _command + " " + text ;
211212 }
212-
213- return "**Command:**" + System . Environment . NewLine + System . Environment . NewLine + _resultCommand + System . Environment . NewLine + System . Environment . NewLine + "**Text to Translate**" + System . Environment . NewLine + System . Environment . NewLine + text ;
213+ return _resultCommand + " " + text ;
214214 }
215215
216216
217-
218-
219-
220217
221218 public async Task < string > TranslateTextAsync ( string text , CancellationToken token )
222219 {
@@ -225,8 +222,7 @@ public async Task<string> TranslateTextAsync(string text, CancellationToken toke
225222 InitializeCommand ( ) ;
226223 }
227224
228-
229- string command = CombineText ( text ) ;
225+ string command = CombineTextOptimized ( text ) ;
230226 string result = await InternalTranslateTextAsync ( command , text , false , token ) ;
231227 return result ;
232228 }
0 commit comments