generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 增加自定义请求。可修改请求 Header 及 reqeust body
- Loading branch information
Showing
8 changed files
with
111 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/cc/unitmesh/devti/llms/custom/JSONBodyResponseCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cc.unitmesh.devti.llms.custom | ||
|
||
import com.nfeld.jsonpathkt.JsonPath | ||
import com.nfeld.jsonpathkt.extension.read | ||
import io.kotest.common.runBlocking | ||
import okhttp3.Call | ||
import okhttp3.Callback | ||
import okhttp3.Response | ||
import java.io.IOException | ||
|
||
class JSONBodyResponseCallback(private val responseFormat: String,private val callback: suspend (String)->Unit): Callback { | ||
override fun onFailure(call: Call, e: IOException) { | ||
runBlocking { | ||
callback("error. ${e.message}") | ||
} | ||
} | ||
|
||
override fun onResponse(call: Call, response: Response) { | ||
val responseContent: String = JsonPath.parse(response.body?.string())?.read(responseFormat) ?: "" | ||
|
||
runBlocking() { | ||
callback(responseContent) | ||
} | ||
|
||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters