diff --git a/openai/src/jvmTest/kotlin/openai/OpenAISpec.kt b/openai/src/jvmTest/kotlin/openai/OpenAISpec.kt deleted file mode 100644 index 9d8cc65cb..000000000 --- a/openai/src/jvmTest/kotlin/openai/OpenAISpec.kt +++ /dev/null @@ -1,68 +0,0 @@ -package openai - -import com.xebia.functional.tokenizer.ModelType -import com.xebia.functional.xef.conversation.llm.openai.OpenAI -import com.xebia.functional.xef.conversation.llm.openai.prompt -import com.xebia.functional.xef.conversation.llm.openai.promptMessage -import com.xebia.functional.xef.prompt.Prompt -import com.xebia.functional.xef.prompt.templates.user -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import openai.data.Answer -import openai.data.Question -import openai.data.TestFunctionsModel -import openai.data.TestModel - -class OpenAISpec : - StringSpec({ - """ - | When we are using a OpenAI scope conversation - | the memories should have the correct size in the vector store - | for the conversationId generated inside the conversation - """ { - OpenAI.conversation { - val model = TestModel(modelType = ModelType.ADA, name = "fake-model") - - promptMessage(prompt = Prompt("question 1"), model = model) - - promptMessage(prompt = Prompt("question 2"), model = model) - - val memories = store.memories(conversationId!!, 10000) - - memories.size shouldBe 4 - } - } - - """ - | When we are using a OpenAI scope conversation with functions - | the memories should have the correct size in the vector store - | for the conversationId generated inside the conversation - """ { - OpenAI.conversation { - val question = Question("fake-question") - val questionJsonString = Json.encodeToString(question) - val answer = Answer("fake-answer") - val answerJsonString = Json.encodeToString(answer) - val question2 = "question 2" - - val message = mapOf(questionJsonString to answerJsonString, question2 to answerJsonString) - - val model = - TestFunctionsModel( - modelType = ModelType.GPT_3_5_TURBO_FUNCTIONS, - name = "fake-model", - responses = message - ) - - val response1: Answer = prompt(Prompt { +user(question) }, model) - - val response2: Answer = prompt(Prompt(question2), model) - - val memories = store.memories(conversationId!!, 10000) - - memories.size shouldBe 4 - } - } - }) diff --git a/openai/src/jvmTest/kotlin/openai/data/TestFunctionsModel.kt b/openai/src/jvmTest/kotlin/openai/data/TestFunctionsModel.kt deleted file mode 100644 index 29259168a..000000000 --- a/openai/src/jvmTest/kotlin/openai/data/TestFunctionsModel.kt +++ /dev/null @@ -1,88 +0,0 @@ -package openai.data - -import com.xebia.functional.tokenizer.ModelType -import com.xebia.functional.xef.llm.ChatWithFunctions -import com.xebia.functional.xef.llm.Embeddings -import com.xebia.functional.xef.llm.models.chat.* -import com.xebia.functional.xef.llm.models.embeddings.EmbeddingRequest -import com.xebia.functional.xef.llm.models.embeddings.EmbeddingResult -import com.xebia.functional.xef.llm.models.functions.FunctionCall -import com.xebia.functional.xef.llm.models.usage.Usage -import kotlinx.coroutines.flow.Flow - -class TestFunctionsModel( - override val modelType: ModelType, - override val name: String, - val responses: Map = emptyMap(), -) : ChatWithFunctions, Embeddings, AutoCloseable { - - var requests: MutableList = mutableListOf() - - override suspend fun createChatCompletion( - request: ChatCompletionRequest - ): ChatCompletionResponse { - requests.add(request) - return ChatCompletionResponse( - id = "fake-id", - `object` = "fake-object", - created = 0, - model = "fake-model", - choices = - listOf( - Choice( - message = - Message( - role = Role.USER, - content = responses[request.messages.last().content] ?: "fake-content", - name = Role.USER.name - ), - finishReason = "fake-finish-reason", - index = 0 - ) - ), - usage = Usage.ZERO - ) - } - - override suspend fun createChatCompletions( - request: ChatCompletionRequest - ): Flow { - throw NotImplementedError() - } - - override fun tokensFromMessages(messages: List): Int { - return messages.sumOf { it.content.length } - } - - override suspend fun createEmbeddings(request: EmbeddingRequest): EmbeddingResult { - return EmbeddingResult(data = emptyList(), usage = Usage.ZERO) - } - - override suspend fun createChatCompletionWithFunctions( - request: ChatCompletionRequest - ): ChatCompletionResponseWithFunctions { - requests.add(request) - val response = responses[request.messages.last().content] ?: "fake-content" - return ChatCompletionResponseWithFunctions( - id = "fake-id", - `object` = "fake-object", - created = 0, - model = "fake-model", - choices = - listOf( - ChoiceWithFunctions( - message = - MessageWithFunctionCall( - role = Role.USER.name, - content = response, - functionCall = FunctionCall("fake-function-name", response), - name = Role.USER.name - ), - finishReason = "fake-finish-reason", - index = 0 - ) - ), - usage = Usage.ZERO - ) - } -} diff --git a/openai/src/jvmTest/kotlin/openai/data/TestModel.kt b/openai/src/jvmTest/kotlin/openai/data/TestModel.kt deleted file mode 100644 index bc6ffd2a3..000000000 --- a/openai/src/jvmTest/kotlin/openai/data/TestModel.kt +++ /dev/null @@ -1,59 +0,0 @@ -package openai.data - -import com.xebia.functional.tokenizer.ModelType -import com.xebia.functional.xef.llm.Chat -import com.xebia.functional.xef.llm.Embeddings -import com.xebia.functional.xef.llm.models.chat.* -import com.xebia.functional.xef.llm.models.embeddings.EmbeddingRequest -import com.xebia.functional.xef.llm.models.embeddings.EmbeddingResult -import com.xebia.functional.xef.llm.models.usage.Usage -import kotlinx.coroutines.flow.Flow - -class TestModel( - override val modelType: ModelType, - override val name: String, - val responses: Map = emptyMap(), -) : Chat, Embeddings, AutoCloseable { - - var requests: MutableList = mutableListOf() - - override suspend fun createChatCompletion( - request: ChatCompletionRequest - ): ChatCompletionResponse { - requests.add(request) - return ChatCompletionResponse( - id = "fake-id", - `object` = "fake-object", - created = 0, - model = "fake-model", - choices = - listOf( - Choice( - message = - Message( - role = Role.USER, - content = responses[request.messages.last().content] ?: "fake-content", - name = Role.USER.name - ), - finishReason = "fake-finish-reason", - index = 0 - ) - ), - usage = Usage.ZERO - ) - } - - override suspend fun createChatCompletions( - request: ChatCompletionRequest - ): Flow { - throw NotImplementedError() - } - - override fun tokensFromMessages(messages: List): Int { - return messages.sumOf { it.content.length } - } - - override suspend fun createEmbeddings(request: EmbeddingRequest): EmbeddingResult { - return EmbeddingResult(data = emptyList(), usage = Usage.ZERO) - } -} diff --git a/openai/src/jvmTest/kotlin/openai/data/models.kt b/openai/src/jvmTest/kotlin/openai/data/models.kt deleted file mode 100644 index 188aa3ec1..000000000 --- a/openai/src/jvmTest/kotlin/openai/data/models.kt +++ /dev/null @@ -1,7 +0,0 @@ -package openai.data - -import kotlinx.serialization.Serializable - -@Serializable data class Question(val question: String) - -@Serializable data class Answer(val bar: String)