Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Dec 1, 2023
1 parent 8b7db7f commit 752dfe7
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ open class CodingActor(
throw IllegalStateException()
}

open fun execute(code: String): ExecutionResult {
open fun execute(prefix: String, code: String): ExecutionResult {
//language=HTML
log.info("Running $code")
OutputInterceptor.clearGlobalOutput()
val result = try {
interpreter.run(code)
interpreter.run((prefix + code).sortCode())
} catch (e: Exception) {
when {
e is ScriptException -> throw FailedToImplementException(e, errorMessage(e, code), code)
Expand Down Expand Up @@ -174,7 +174,7 @@ open class CodingActor(

override fun getStatus() = _status

private val _code by lazy {
private val _code: String by lazy {
if (null != givenCode) return@lazy givenCode
try {
implement(model)
Expand Down Expand Up @@ -245,13 +245,13 @@ open class CodingActor(
_status = CodeResult.Status.Correcting
}
}
throw FailedToImplementException()
throw IllegalStateException()
}

@JsonIgnore
override fun getCode(): String = _code

private val executionResult by lazy { execute((input.codePrefix + "\n" + getCode()).sortCode()) }
private val executionResult by lazy { execute(input.codePrefix, getCode()) }
override fun result() = executionResult
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ class CodingActorInterceptor(


override fun answer(vararg messages: ChatMessage, input: CodeRequest, api: API) =
functionInterceptor.wrap(messages, input) { messages, input ->
inner.answer(*messages, input=input, api = api)
}
functionInterceptor.wrap(messages, input)
{ messages, input -> inner.answer(*messages, input=input, api = api) }

override fun execute(code: String) = functionInterceptor.wrap(code) {
inner.execute(it)
}
override fun execute(prefix: String, code: String) =
functionInterceptor.wrap(prefix, code)
{ prefix, code -> inner.execute(prefix, code) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.models.OpenAIModel
import com.simiacryptus.skyenet.core.platform.file.*
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
Expand Down Expand Up @@ -81,39 +78,6 @@ interface AuthorizationInterface {
): Boolean
}

data class User(
@get:JsonProperty("email") internal val email: String,
@get:JsonProperty("name") internal val name: String? = null,
@get:JsonProperty("id") internal val id: String? = null,
@get:JsonProperty("picture") internal val picture: String? = null,
) {
override fun toString() = email

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as User

return email == other.email
}

override fun hashCode(): Int {
return email.hashCode()
}

}

data class Session(
internal val sessionId: String
) {
init {
StorageInterface.validateSessionId(this)
}

override fun toString() = sessionId
}

interface StorageInterface {
fun <T> getJson(
user: User?,
Expand Down Expand Up @@ -191,54 +155,17 @@ interface StorageInterface {
}
}

interface UserSettingsInterface {
data class UserSettings(
val apiKey: String = "",
)

class StorageInterfaceTest(val storage: StorageInterface) {


@Test
fun testGetJson() {
// Arrange
val user = User(email = "[email protected]")
val session = Session("G-20230101-12345678")
val filename = "test.json"

// Act
val result = storage.getJson(user, session, filename, Any::class.java)

// Assert
assertNull(result, "Expected null result for non-existing JSON file")
}

@Test
fun testGetMessages() {
// Arrange
val user = User(email = "[email protected]")
val session = Session("G-20230101-12345678")

// Act
val messages = storage.getMessages(user, session)

// Assert
assertTrue(messages is LinkedHashMap<*, *>, "Expected LinkedHashMap type for messages")
}

@Test
fun testGetSessionDir() {
// Arrange
val user = User(email = "[email protected]")
val session = Session("G-20230101-12345678")

// Act
val sessionDir = storage.getSessionDir(user, session)

// Assert
assertTrue(sessionDir is File, "Expected File type for session directory")
}
fun getUserSettings(user: User): UserSettings

// Continue writing tests for each method in StorageInterface...
// ...
fun updateUserSettings(user: User, settings: UserSettings)
}


interface UsageInterface {
fun incrementUsage(session: Session, user: User?, model: OpenAIModel, tokens: ApiModel.Usage)

Expand Down Expand Up @@ -273,14 +200,37 @@ interface UsageInterface {
}


interface UserSettingsInterface {
data class UserSettings(
val apiKey: String = "",
)
data class User(
@get:JsonProperty("email") internal val email: String,
@get:JsonProperty("name") internal val name: String? = null,
@get:JsonProperty("id") internal val id: String? = null,
@get:JsonProperty("picture") internal val picture: String? = null,
) {
override fun toString() = email

fun getUserSettings(user: User): UserSettings
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

fun updateUserSettings(user: User, settings: UserSettings)
other as User

return email == other.email
}

override fun hashCode(): Int {
return email.hashCode()
}

}

data class Session(
internal val sessionId: String
) {
init {
StorageInterface.validateSessionId(this)
}

override fun toString() = sessionId
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test
import java.util.*

open class AuthenticationInterfaceTest(
val authInterface: AuthenticationInterface
private val authInterface: AuthenticationInterface
) {

private val validAccessToken = UUID.randomUUID().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

open class AuthorizationInterfaceTest(
val authInterface: AuthorizationInterface
private val authInterface: AuthorizationInterface
) {

open val user = User(email = "[email protected]", name = "Jane Smith", id = "2", picture = "http://example.com/newpicture.jpg")
Expand Down
Loading

0 comments on commit 752dfe7

Please sign in to comment.