All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.simiacryptus.skyenet.apps.general.PlanAheadApp.kt Maven / Gradle / Ivy
package com.simiacryptus.skyenet.apps.general
import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ChatClient
import com.simiacryptus.jopenai.models.OpenAITextModel
import com.simiacryptus.jopenai.util.JsonUtil
import com.simiacryptus.skyenet.apps.plan.PlanCoordinator
import com.simiacryptus.skyenet.apps.plan.PlanCoordinator.Companion.initialPlan
import com.simiacryptus.skyenet.apps.plan.PlanSettings
import com.simiacryptus.skyenet.apps.plan.PlanUtil
import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.core.platform.User
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.application.ApplicationSocketManager
import com.simiacryptus.skyenet.webui.session.SocketManager
import org.slf4j.LoggerFactory
import java.io.File
open class PlanAheadApp(
applicationName: String = "Task Planning v1.1",
path: String = "/taskDev",
val rootFile: File? = null,
val planSettings: PlanSettings,
val model: OpenAITextModel,
val parsingModel: OpenAITextModel,
val domainName : String = "localhost",
showMenubar: Boolean = true,
val initialPlan: PlanUtil.TaskBreakdownWithPrompt? = null,
val api: API? = null,
) : ApplicationServer(
applicationName = applicationName,
path = path,
showMenubar = showMenubar,
) {
override val singleInput: Boolean get() = true
override val root: File get() = rootFile ?: super.root
@Suppress("UNCHECKED_CAST")
override fun initSettings(session: Session): T = planSettings.let {
if (null == rootFile) it.copy(workingDir = root.absolutePath) else
it
} as T
override fun newSession(user: User?, session: Session): SocketManager {
val socketManager = super.newSession(user, session)
val ui = (socketManager as ApplicationSocketManager).applicationInterface
if (initialPlan != null) {
socketManager.pool.submit {
try {
val planSettings = getSettings(session, user, PlanSettings::class.java)
if (api is ChatClient) api.budget = planSettings?.budget
val coordinator = PlanCoordinator(
user = user,
session = session,
dataStorage = dataStorage,
ui = ui,
root = dataStorage.getDataDir(user, session).toPath(),
planSettings = planSettings!!
)
coordinator.executeTaskBreakdownWithPrompt(JsonUtil.toJson(initialPlan), api!!)
} catch (e: Throwable) {
ui.newTask().error(ui, e)
log.warn("Error", e)
}
}
}
return socketManager
}
override fun userMessage(
session: Session,
user: User?,
userMessage: String,
ui: ApplicationInterface,
api: API
) {
try {
val planSettings = getSettings(session, user, PlanSettings::class.java)
if (api is ChatClient) api.budget = planSettings?.budget ?: 2.0
val coordinator = PlanCoordinator(
user = user,
session = session,
dataStorage = dataStorage,
ui = ui,
root = dataStorage.getDataDir(user, session).toPath(),
planSettings = planSettings!!
)
val task = coordinator.ui.newTask()
val plan = initialPlan(
codeFiles = coordinator.codeFiles,
files = coordinator.files,
root = coordinator.root,
task = task,
userMessage = userMessage,
ui = coordinator.ui,
planSettings = coordinator.planSettings,
api = api
)
coordinator.executePlan(plan.plan, task, userMessage = userMessage, api = api)
} catch (e: Throwable) {
ui.newTask().error(ui, e)
log.warn("Error", e)
}
}
companion object {
private val log = LoggerFactory.getLogger(PlanAheadApp::class.java)
}
}