Skip to content

Commit 749f4b4

Browse files
fix: fixed url construction
1 parent 504043b commit 749f4b4

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetSelector.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/pirouette/chibichat/MainActivity.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.android.volley.toolbox.Volley
1616
import com.google.gson.Gson
1717
import org.json.JSONObject
1818
import java.io.*
19+
import java.net.URI
1920

2021

2122
class MainActivity : AppCompatActivity() {
@@ -224,7 +225,7 @@ class MainActivity : AppCompatActivity() {
224225

225226
fun OllamaPOST() {
226227
val volleyQueue = Volley.newRequestQueue(this)
227-
val url = "http://" + ipAdd + ":" + port + "/api/chat"
228+
val url = buildChatUrl(ipAdd, port)
228229
val data = OllamaJsonClass(
229230
model = model,
230231
messages = ollamaConv,
@@ -261,6 +262,32 @@ class MainActivity : AppCompatActivity() {
261262

262263
}
263264

265+
fun buildChatUrl(ipAdd: String, port: String?): String {
266+
val base = if (ipAdd.startsWith("http://") || ipAdd.startsWith("https://")) {
267+
ipAdd
268+
} else {
269+
"http://$ipAdd"
270+
}
271+
272+
val uri = try {
273+
URI(base)
274+
} catch (e: Exception) {
275+
throw IllegalArgumentException("Invalid server address")
276+
}
277+
278+
val portInt = port?.toIntOrNull() ?: uri.port
279+
280+
return URI(
281+
uri.scheme,
282+
null,
283+
uri.host,
284+
portInt,
285+
"/api/chat",
286+
null,
287+
null
288+
).toString()
289+
}
290+
264291
fun KoboldPOST() {
265292
val volleyQueue = Volley.newRequestQueue(this)
266293
val url = "http://" + ipAdd + ":" + port + "/api/v1/generate"

0 commit comments

Comments
 (0)