Skip to content

Commit

Permalink
Merge pull request #190 from devchat-ai/local-service
Browse files Browse the repository at this point in the history
Local service
  • Loading branch information
pplam authored Jul 17, 2024
2 parents 7244927 + fca1418 commit ed7d89a
Show file tree
Hide file tree
Showing 18 changed files with 677 additions and 339 deletions.
16 changes: 12 additions & 4 deletions src/main/kotlin/ai/devchat/common/PathUtils.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package ai.devchat.common

import ai.devchat.plugin.currentProject
import java.io.File
import java.io.IOException
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes


object PathUtils {
val workspace: String? = currentProject?.basePath
val workPath: String = Paths.get(System.getProperty("user.home"), ".chat").toString()
val workflowPath: String = Paths.get(workPath, "scripts").toString()
val sitePackagePath: String = Paths.get(workPath, "site-packages").toString()
val pythonPath: String = "$sitePackagePath:$workflowPath"
val mambaWorkPath = Paths.get(workPath, "mamba").toString()
val mambaBinPath = Paths.get(mambaWorkPath, "micromamba").toString()
val toolsPath: String = Paths.get(workPath, "tools").toString()
val localServicePath: String = Paths.get(sitePackagePath, "devchat", "_service", "main.py").toString()
val codeEditorBinary: String = "${when {
OSInfo.OS_ARCH.contains("aarch") || OSInfo.OS_ARCH.contains("arm") -> "aarch64"
else -> "x86_64"
Expand Down Expand Up @@ -73,9 +76,14 @@ object PathUtils {
return targetPath.toString()
}

fun createTempFile(prefix: String, content: String): String {
val tempFile = File.createTempFile(prefix, "")
tempFile.writeText(content)
return tempFile.absolutePath
fun createTempFile(content: String, prefix: String = "devchat-tmp-", suffix: String = ""): String? {
return try {
val tempFile = File.createTempFile(prefix, suffix)
tempFile.writeText(content)
tempFile.absolutePath
} catch (e: IOException) {
Log.error("Failed to create a temporary file: $e")
return null
}
}
}
Loading

0 comments on commit ed7d89a

Please sign in to comment.