Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into simon-cl…
Browse files Browse the repository at this point in the history
…ient

# Conflicts:
#	evaluator-example/src/main/kotlin/com/xebia/functional/xef/evaluator/examples/TestExample.kt
  • Loading branch information
raulraja committed Mar 25, 2024
2 parents 95b30cb + c0e8516 commit 8ba3f01
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 387 deletions.
39 changes: 39 additions & 0 deletions core/src/commonMain/kotlin/com/xebia/functional/xef/AI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.xebia.functional.openai.generated.model.CreateChatCompletionRequestMo
import com.xebia.functional.xef.conversation.AiDsl
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.prompt.Prompt
import kotlin.coroutines.cancellation.CancellationException
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.typeOf
Expand All @@ -17,6 +18,10 @@ import kotlinx.serialization.serializer

sealed interface AI {

interface PromptClassifier {
fun template(input: String, output: String, context: String): String
}

companion object {

fun <A : Any> chat(
Expand Down Expand Up @@ -62,6 +67,40 @@ sealed interface AI {
}
.invoke(prompt)

/**
* Classify a prompt using a given enum.
*
* @param input The input to the model.
* @param output The output to the model.
* @param context The context to the model.
* @param model The model to use.
* @param target The target type to return.
* @param api The chat API to use.
* @param conversation The conversation to use.
* @return The classified enum.
* @throws IllegalArgumentException If no enum values are found.
*/
@AiDsl
@Throws(IllegalArgumentException::class, CancellationException::class)
suspend inline fun <reified E> classify(
input: String,
output: String,
context: String,
model: CreateChatCompletionRequestModel = CreateChatCompletionRequestModel.gpt_4_1106_preview,
target: KType = typeOf<E>(),
api: ChatApi = fromEnvironment(::ChatApi),
conversation: Conversation = Conversation()
): E where E : PromptClassifier, E : Enum<E> {
val value = enumValues<E>().firstOrNull() ?: error("No enum values found")
return invoke(
prompt = value.template(input, output, context),
model = model,
target = target,
api = api,
conversation = conversation
)
}

@AiDsl
suspend inline operator fun <reified A : Any> invoke(
prompt: String,
Expand Down
50 changes: 0 additions & 50 deletions evaluator-example/README.md

This file was deleted.

59 changes: 0 additions & 59 deletions evaluator-example/build.gradle.kts

This file was deleted.

6 changes: 0 additions & 6 deletions evaluator-example/evalTest/.gitignore

This file was deleted.

60 changes: 0 additions & 60 deletions evaluator-example/evalTest/publish/script.js

This file was deleted.

96 changes: 0 additions & 96 deletions evaluator-example/evalTest/py_evaluator/test_evaluator.py

This file was deleted.

13 changes: 0 additions & 13 deletions evaluator-example/evalTest/pyproject.toml

This file was deleted.

Loading

0 comments on commit 8ba3f01

Please sign in to comment.