Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Oct 15, 2023
1 parent 85f08a7 commit e594881
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.simiacryptus.skyenet.body

import com.simiacryptus.openai.OpenAIClient
import org.apache.commons.io.FileUtils
import org.eclipse.jetty.webapp.WebAppContext
import java.io.File

open class SkyenetBasicChat(
applicationName: String,
baseURL: String,
oauthConfig: String? = null
) : SkyenetSessionServerBase(
applicationName = applicationName,
baseURL = baseURL,
oauthConfig = oauthConfig,
) {
override val api: OpenAIClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import com.simiacryptus.util.describe.TypeDescriber
import jakarta.servlet.http.HttpServlet
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.apache.commons.io.FileUtils
import org.eclipse.jetty.servlet.ServletHolder
import org.eclipse.jetty.webapp.WebAppContext
import java.io.File

abstract class SkyenetCodingSessionServer(
applicationName: String,
Expand All @@ -21,7 +19,6 @@ abstract class SkyenetCodingSessionServer(
resourceBase: String = "simpleSession",
val maxRetries: Int = 5,
var maxHistoryCharacters: Int = 4000,
baseURL: String = "http://localhost:8080",
temperature: Double = 0.1,
val model: OpenAIClient.Model = OpenAIClient.Models.GPT4,
var useHistory: Boolean = true,
Expand All @@ -31,7 +28,6 @@ abstract class SkyenetCodingSessionServer(
applicationName = applicationName,
oauthConfig = oauthConfig,
resourceBase = resourceBase,
baseURL = baseURL,
temperature = temperature,
) {

Expand All @@ -40,8 +36,8 @@ abstract class SkyenetCodingSessionServer(
abstract fun hands(): java.util.Map<String, Object>
abstract fun heart(hands: java.util.Map<String, Object>): Heart

override fun configure(context: WebAppContext, prefix: String) {
super.configure(context, prefix)
override fun configure(context: WebAppContext, prefix: String, baseUrl: String) {
super.configure(context, prefix, baseUrl)
context.addServlet(descriptorServlet, "/yamlDescriptor")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import com.simiacryptus.util.describe.YamlDescriber
import jakarta.servlet.http.HttpServlet
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.apache.commons.io.FileUtils
import org.eclipse.jetty.servlet.ServletHolder
import org.eclipse.jetty.webapp.WebAppContext
import java.io.File

open class SkyenetInterviewer<T : Any>(
applicationName: String,
baseURL: String,
val dataClass: Class<T>,
val visiblePrompt: String,
val describer: TypeDescriber = YamlDescriber(),
Expand All @@ -23,14 +20,13 @@ open class SkyenetInterviewer<T : Any>(
val apiKey: String
) : SkyenetSessionServerBase(
applicationName = applicationName,
baseURL = baseURL,
oauthConfig = oauthConfig,
) {

override val api: OpenAIClient = OpenAIClient(apiKey)

override fun configure(context: WebAppContext, prefix: String) {
super.configure(context, prefix)
override fun configure(context: WebAppContext, prefix: String, baseUrl: String) {
super.configure(context, prefix, baseUrl)
context.addServlet(
ServletHolder(
"yamlDescriptor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import java.util.function.Consumer

abstract class SkyenetMacroChat(
applicationName: String,
baseURL: String,
oauthConfig: String? = null,
temperature: Double = 0.1,
) : SkyenetSessionServerBase(
applicationName = applicationName,
baseURL = baseURL,
oauthConfig = oauthConfig,
temperature = temperature,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ package com.simiacryptus.skyenet.body

import com.simiacryptus.openai.OpenAIClient
import com.vladsch.flexmark.util.data.MutableDataSet
import org.apache.commons.io.FileUtils
import org.eclipse.jetty.webapp.WebAppContext
import java.awt.Desktop
import java.io.File
import java.net.URI

open class SkyenetMarkupChat(
applicationName: String,
baseURL: String,
oauthConfig: String? = null,
val visiblePrompt: String = """
|Hello! I am here to assist you in a casual conversation!
Expand All @@ -33,7 +29,6 @@ open class SkyenetMarkupChat(
""".trimMargin()
) : SkyenetSessionServerBase(
applicationName = applicationName,
baseURL = baseURL,
oauthConfig = oauthConfig,
) {
override val api: OpenAIClient
Expand Down Expand Up @@ -67,8 +62,7 @@ open class SkyenetMarkupChat(
const val port = 8081
const val baseURL = "http://localhost:$port"
var skyenet = SkyenetMarkupChat(
applicationName = "Chat Demo",
baseURL = baseURL
applicationName = "Chat Demo"
)

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ abstract class SkyenetSessionServerBase(
override val applicationName: String,
val oauthConfig: String? = null,
resourceBase: String = "simpleSession",
val baseURL: String = "http://localhost:8080",
val temperature: Double = 0.1,
) : WebSocketServer(resourceBase) {

Expand All @@ -27,8 +26,8 @@ abstract class SkyenetSessionServerBase(

open val sessionDataStorage = SessionDataStorage(File(File(".skynet"), applicationName))

override fun configure(context: WebAppContext, prefix: String) {
super.configure(context, prefix)
override fun configure(context: WebAppContext, prefix: String, baseURL: String) {
super.configure(context, prefix, baseURL)

if (null != oauthConfig) (AuthenticatedWebsite("$baseURL/oauth2callback", this@SkyenetSessionServerBase.applicationName) {
FileUtils.openInputStream(File(oauthConfig))
Expand Down Expand Up @@ -181,8 +180,7 @@ abstract class SkyenetSessionServerBase(
resp.writer.write(
JsonUtil.objectMapper().writeValueAsString(
mapOf(
"applicationName" to applicationName,
"baseURL" to baseURL,
"applicationName" to applicationName
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ abstract class WebSocketServer(val resourceBase: String) {

abstract fun newSession(sessionId: String): SessionInterface

fun start(port: Int = 8080): Server {
fun start(port: Int = 8080, baseUrl: String = "http://localhost:$port"): Server {
val server = Server(port)
configure(server)
configure(server, baseUrl)
server.start()
return server
}

open fun configure(server: Server) {
open fun configure(server: Server, baseUrl: String) {
val webAppContext = WebAppContext()
webAppContext.baseResource = baseResource
webAppContext.contextPath = "/"
webAppContext.welcomeFiles = arrayOf("index.html")
JettyWebSocketServletContainerInitializer.configure(webAppContext, null)
configure(webAppContext)
configure(webAppContext, baseUrl = baseUrl)
server.handler = webAppContext
}

open val baseResource: Resource? get() = Resource.newResource(javaClass.classLoader.getResource(resourceBase))

open fun configure(webAppContext: WebAppContext, prefix: String = "") {
open fun configure(webAppContext: WebAppContext, prefix: String = "", baseUrl: String) {
webAppContext.addServlet(ServletHolder(javaClass.simpleName + "/default", defaultServlet), prefix + "/")
webAppContext.addServlet(ServletHolder(javaClass.simpleName + "/ws", webSocketHandler), prefix + "/ws/*")
webAppContext.addServlet(ServletHolder(javaClass.simpleName + "/newSession", newSessionServlet),prefix + "/newSession")
Expand Down
5 changes: 3 additions & 2 deletions webui/src/main/resources/simpleSession/chat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

let socket;

function getSessionId() {
if (!window.location.hash) {
fetch('newSession')
Expand All @@ -17,8 +20,6 @@ function getSessionId() {
}
}

let socket;

function send(message) {
console.log('Sending message:', message);
socket.send(message);
Expand Down
Loading

0 comments on commit e594881

Please sign in to comment.