Skip to content

Commit 2e0de74

Browse files
committed
fix(CoUnitPromptGenerator): ensure retrofit service creation is consistent #51
To improve code readability and maintainability, the creation of the `CoUnitApi` service instance has been moved outside the `findIntention` and `semanticQuery` methods. Now, the service instance is initialized once and reused throughout the class, which aligns with the principles of software design by reducing code duplication and promoting the single responsibility principle.
1 parent 1ef99e2 commit 2e0de74

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/CoUnitPromptGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class CoUnitPromptGenerator(val project: Project) {
1818
.addConverterFactory(GsonConverterFactory.create())
1919
.build()
2020

21-
var service: CoUnitApi = retrofit.create(CoUnitApi::class.java)
22-
2321
fun findIntention(input: String): String? {
22+
val service: CoUnitApi = retrofit.create(CoUnitApi::class.java)
2423
val body = service.explainQuery(input).execute().body()
2524
return body?.prompt
2625
}
2726

2827
fun semanticQuery(query: ExplainQuery): QueryResult {
28+
val service: CoUnitApi = retrofit.create(CoUnitApi::class.java)
2929
val englishQuery: QueryResponse? = service.query(query.query, PayloadType.OpenApi).execute().body()
3030
val hydeDoc: QueryResponse? = service.query(query.hypotheticalDocument, PayloadType.OpenApi).execute().body()
3131
val naturalLangQuery: QueryResponse? = service.query(query.natureLangQuery, PayloadType.OpenApi).execute().body()

0 commit comments

Comments
 (0)