Skip to content

Commit

Permalink
feat(custom-agent): use agent-specific url for requests #51
Browse files Browse the repository at this point in the history
The `CustomAgentExecutor` now uses the specific `url` provided in the `CustomAgentConfig` instead of the hardcoded `serverAddress`. This change ensures that the agent can be configured to connect to different endpoints, providing more flexibility in deployment scenarios.
  • Loading branch information
phodal committed Mar 5, 2024
1 parent 05ecb7a commit 65e9e5e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 15 deletions.
Expand Up @@ -19,8 +19,6 @@ class CustomAgentExecutor(val project: Project) {
private var client = OkHttpClient()

fun execute(input: String, agent: CustomAgentConfig): String? {
val serverAddress = project.customAgentSetting.serverAddress ?: return null

val customRequest = CustomRequest(listOf(Message("user", input)))
val request = Json.encodeToString<CustomRequest>(customRequest)

Expand All @@ -38,7 +36,7 @@ class CustomAgentExecutor(val project: Project) {
}

client = client.newBuilder().build()
val call = client.newCall(builder.url(serverAddress).post(body).build())
val call = client.newCall(builder.url(agent.url).post(body).build())

call.execute().use { response ->
if (!response.isSuccessful) {
Expand Down
Expand Up @@ -12,7 +12,6 @@ class CoUnitProjectSettingsService(
val project: Project,
) : SimplePersistentStateComponent<CoUnitProjectSettingsService.CoUnitProjectSettings>(CoUnitProjectSettings()) {
val enableCustomRag: Boolean get() = state.enableCustomRag
val serverAddress: String get() = state.serverAddress
val ragsJsonConfig: String get() = state.agentJsonConfig

fun modify(action: (CoUnitProjectSettings) -> Unit) {
Expand All @@ -25,7 +24,6 @@ class CoUnitProjectSettingsService(

class CoUnitProjectSettings : AdProjectSettingsBase<CoUnitProjectSettings>() {
var enableCustomRag by property(false)
var serverAddress by property("http://localhost:8765/api/agent/") { it.isEmpty() }
var agentJsonConfig by property("") { it.isEmpty() }

override fun copy(): CoUnitProjectSettings {
Expand Down
Expand Up @@ -25,15 +25,6 @@ class CoUnitToolConfigurable(val project: Project) : BoundConfigurable(AutoDevBu
checkBox(AutoDevBundle.message("counit.agent.enable.label")).bindSelected(state::enableCustomRag)
}

row(AutoDevBundle.message("counit.agent.server.address.label")) {
fullWidthCell(serverAddress)
.bind(
componentGet = { it.text },
componentSet = { component, value -> component.text = value },
prop = state::serverAddress.toMutableProperty()
)
}

row {
val languageField = JsonLanguageField(
project,
Expand All @@ -51,7 +42,6 @@ class CoUnitToolConfigurable(val project: Project) : BoundConfigurable(AutoDevBu
onApply {
settings.modify {
it.enableCustomRag = state.enableCustomRag
it.serverAddress = state.serverAddress
it.agentJsonConfig = state.agentJsonConfig
}
}
Expand Down

0 comments on commit 65e9e5e

Please sign in to comment.