Skip to content

Commit

Permalink
fix(CoUnitPromptGenerator): ensure retrofit service creation is consi…
Browse files Browse the repository at this point in the history
…stent #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.
  • Loading branch information
phodal committed Mar 4, 2024
1 parent 1ef99e2 commit 2e0de74
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -18,14 +18,14 @@ class CoUnitPromptGenerator(val project: Project) {
.addConverterFactory(GsonConverterFactory.create())
.build()

var service: CoUnitApi = retrofit.create(CoUnitApi::class.java)

fun findIntention(input: String): String? {
val service: CoUnitApi = retrofit.create(CoUnitApi::class.java)
val body = service.explainQuery(input).execute().body()
return body?.prompt
}

fun semanticQuery(query: ExplainQuery): QueryResult {
val service: CoUnitApi = retrofit.create(CoUnitApi::class.java)
val englishQuery: QueryResponse? = service.query(query.query, PayloadType.OpenApi).execute().body()
val hydeDoc: QueryResponse? = service.query(query.hypotheticalDocument, PayloadType.OpenApi).execute().body()
val naturalLangQuery: QueryResponse? = service.query(query.natureLangQuery, PayloadType.OpenApi).execute().body()
Expand Down

0 comments on commit 2e0de74

Please sign in to comment.