Skip to content

Commit b18d773

Browse files
authored
Merge pull request #149 from joreilly/query_update
update query to support list of countries
2 parents 31e3640 + f2f0950 commit b18d773

File tree

6 files changed

+37
-63
lines changed

6 files changed

+37
-63
lines changed

agents/src/main/kotlin/adk/adk_agent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ fun main() {
6161

6262
val prompt =
6363
"""
64-
Get emission data for France and Germany for 2023 and 2024.
64+
Get emission data for EU countries in 2024.
6565
Use units of millions for the emissions data.
66+
Show result in a grid or decreasing order of emissions.
6667
""".trimIndent()
6768

6869
val userMsg = Content.fromParts(Part.fromText(prompt))

agents/src/main/kotlin/koog/koog_agent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import ai.koog.prompt.executor.clients.google.GoogleModels
1010
import ai.koog.prompt.executor.clients.openai.OpenAIModels
1111
import ai.koog.prompt.executor.llms.all.simpleGoogleAIExecutor
1212
import ai.koog.prompt.executor.llms.all.simpleOpenAIExecutor
13+
import kotlinx.coroutines.runBlocking
1314
import kotlin.uuid.ExperimentalUuidApi
1415
import kotlin.uuid.Uuid
1516

1617
val openAIApiKey = ""
1718
val apiKeyGoogle = ""
1819

1920

20-
2121
@OptIn(ExperimentalUuidApi::class)
22-
suspend fun main() {
22+
fun main() = runBlocking {
2323
val agent = AIAgent(
2424
//executor = simpleOpenAIExecutor(openAIApiKey),
2525
executor = simpleGoogleAIExecutor(apiKeyGoogle),

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/data/ClimateTraceRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ClimateTraceRepository(
1515
return countries
1616
}
1717

18-
suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = api.fetchCountryEmissionsInfo(countryCode, year)
18+
suspend fun fetchCountryEmissionsInfo(countryCodeList: List<String>, year: String) = api.fetchCountryEmissionsInfo(countryCodeList, year)
19+
suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = api.fetchCountryEmissionsInfo(listOf(countryCode), year)
1920
suspend fun fetchCountryAssetEmissionsInfo(countryCode: String) = api.fetchCountryAssetEmissionsInfo(countryCode)
2021
}

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/remote/ClimateTraceApi.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,18 @@ class ClimateTraceApi(
7474
suspend fun fetchAssets() = client.get("$baseUrl/assets").body<AssetsResult>()
7575

7676
suspend fun fetchCountryAssets(countryCode: String) = client.get("$baseUrl/assets?countries=$countryCode").body<AssetsResult>()
77-
suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = client.get("$baseUrl/country/emissions?since=$year&to=$year&countries=$countryCode").body<List<CountryEmissionsInfo>>()
77+
//suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = client.get("$baseUrl/country/emissions?since=$year&to=$year&countries=$countryCode").body<List<CountryEmissionsInfo>>()
78+
79+
suspend fun fetchCountryEmissionsInfo(countryCodeList: List<String>, year: String): List<CountryEmissionsInfo> {
80+
return client.get("$baseUrl/country/emissions") {
81+
url {
82+
parameters.append("countries", countryCodeList.joinToString(","))
83+
parameters.append("since", year)
84+
parameters.append("to", year)
85+
}
86+
}.body<List<CountryEmissionsInfo>>()
87+
}
88+
7889

7990
suspend fun fetchCountryAssetEmissionsInfo(countryCode: String) = client.get("$baseUrl/assets/emissions?countries=$countryCode").body<Map<String, List<CountryAssetEmissionsInfo>>>()[countryCode] ?: emptyList()
8091
}
Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
version = "1.7">
4-
<BuildAction
5-
parallelizeBuildables = "YES"
6-
buildImplicitDependencies = "YES">
3+
version = "1.3">
4+
<BuildAction>
75
<BuildActionEntries>
86
<BuildActionEntry
9-
buildForTesting = "YES"
10-
buildForRunning = "YES"
11-
buildForProfiling = "YES"
12-
buildForArchiving = "YES"
13-
buildForAnalyzing = "YES">
7+
buildForRunning = "YES">
148
<BuildableReference
159
BuildableIdentifier = "primary"
1610
BlueprintIdentifier = "7555FF7A242A565900829871"
@@ -21,38 +15,11 @@
2115
</BuildActionEntry>
2216
</BuildActionEntries>
2317
</BuildAction>
24-
<TestAction
25-
buildConfiguration = "Debug"
26-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28-
shouldUseLaunchSchemeArgsEnv = "YES"
29-
shouldAutocreateTestPlan = "YES">
30-
<Testables>
31-
<TestableReference
32-
skipped = "NO"
33-
parallelizable = "YES">
34-
<BuildableReference
35-
BuildableIdentifier = "primary"
36-
BlueprintIdentifier = "1AB84D8E2CA0ABED002A845D"
37-
BuildableName = "ClimateTraceKMPUITests.xctest"
38-
BlueprintName = "ClimateTraceKMPUITests"
39-
ReferencedContainer = "container:iosApp.xcodeproj">
40-
</BuildableReference>
41-
</TestableReference>
42-
</Testables>
43-
</TestAction>
4418
<LaunchAction
45-
buildConfiguration = "Debug"
46-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48-
launchStyle = "0"
4919
useCustomWorkingDirectory = "NO"
50-
ignoresPersistentStateOnLaunch = "NO"
51-
debugDocumentVersioning = "YES"
52-
debugServiceExtension = "internal"
20+
buildConfiguration = "Debug"
5321
allowLocationSimulation = "YES">
54-
<BuildableProductRunnable
55-
runnableDebuggingMode = "0">
22+
<BuildableProductRunnable>
5623
<BuildableReference
5724
BuildableIdentifier = "primary"
5825
BlueprintIdentifier = "7555FF7A242A565900829871"
@@ -62,18 +29,4 @@
6229
</BuildableReference>
6330
</BuildableProductRunnable>
6431
</LaunchAction>
65-
<ProfileAction
66-
buildConfiguration = "Release"
67-
shouldUseLaunchSchemeArgsEnv = "YES"
68-
savedToolIdentifier = ""
69-
useCustomWorkingDirectory = "NO"
70-
debugDocumentVersioning = "YES">
71-
</ProfileAction>
72-
<AnalyzeAction
73-
buildConfiguration = "Debug">
74-
</AnalyzeAction>
75-
<ArchiveAction
76-
buildConfiguration = "Release"
77-
revealArchiveInOrganizer = "YES">
78-
</ArchiveAction>
7932
</Scheme>

mcp-server/src/main/kotlin/server.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlinx.io.buffered
1212
import kotlinx.serialization.json.JsonObject
1313
import kotlinx.serialization.json.JsonPrimitive
1414
import kotlinx.serialization.json.buildJsonObject
15+
import kotlinx.serialization.json.jsonArray
1516
import kotlinx.serialization.json.jsonPrimitive
1617
import kotlinx.serialization.json.putJsonObject
1718

@@ -50,23 +51,30 @@ fun configureServer(): Server {
5051
description = "List emission info for a particular country",
5152
inputSchema = Tool.Input(
5253
properties = buildJsonObject {
53-
putJsonObject("countryCode") { put("type", JsonPrimitive("string")) }
54+
putJsonObject("countryCodeList") {
55+
put("type", JsonPrimitive("array"))
56+
putJsonObject("items") {
57+
put("type", JsonPrimitive("string"))
58+
}
59+
}
5460
putJsonObject("year") { put("type", JsonPrimitive("string")) }
5561
},
56-
required = listOf("countryCode", "year")
62+
required = listOf("countryCodeList", "year")
5763
)
5864

5965
) { request ->
60-
val countryCode = request.arguments["countryCode"]
66+
val countryCodeList = request.arguments["countryCodeList"]
6167
val year = request.arguments["year"]
62-
if (countryCode == null || year == null) {
68+
if (countryCodeList == null || year == null) {
6369
return@addTool CallToolResult(
64-
content = listOf(TextContent("The 'countryCode' and `year` parameters are required."))
70+
content = listOf(TextContent("The 'countryCodeList' and `year` parameters are required."))
6571
)
6672
}
6773

6874
val countryEmissionInfo = climateTraceRepository.fetchCountryEmissionsInfo(
69-
countryCode = countryCode.jsonPrimitive.content,
75+
countryCodeList = countryCodeList
76+
.jsonArray
77+
.map { it.jsonPrimitive.content },
7078
year = year.jsonPrimitive.content
7179
)
7280
CallToolResult(

0 commit comments

Comments
 (0)