Skip to content

Commit

Permalink
Package, type and module clean up. (#335)
Browse files Browse the repository at this point in the history
* rename package `auto` to `conversation`

* Remove unused `Program`

* Rename package `vectorstores` to `store`

* Remove unused AI error types

* Change scala `auto` package to `conversation`, remove unused types and modules

* Remove cats module until we have a solution based on the methods exported as CompletableFuture
  • Loading branch information
raulraja authored Aug 18, 2023
1 parent bbc52eb commit 2829f57
Show file tree
Hide file tree
Showing 252 changed files with 473 additions and 1,134 deletions.
19 changes: 0 additions & 19 deletions core/src/commonMain/kotlin/com/xebia/functional/xef/AIError.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
package com.xebia.functional.xef

import arrow.core.NonEmptyList
import com.xebia.functional.xef.llm.models.chat.Message
import kotlin.jvm.JvmOverloads

sealed class AIError @JvmOverloads constructor(message: String, cause: Throwable? = null) :
RuntimeException(message, cause) {

class NoResponse : AIError("No response from the AI")

data class MessagesExceedMaxTokenLength(
val messages: List<Message>,
val promptTokens: Int,
val maxTokens: Int
) :
AIError(
"Prompt exceeds max token length: $promptTokens + $maxTokens = ${promptTokens + maxTokens}"
)

data class PromptExceedsMaxTokenLength(
val prompt: String,
val promptTokens: Int,
val maxTokens: Int
) :
AIError(
"Prompt exceeds max token length: $promptTokens + $maxTokens = ${promptTokens + maxTokens}"
)

data class PromptExceedsMaxRemainingTokenLength(val promptTokens: Int, val maxTokens: Int) :
AIError(
"Prompt exceeds max remaining token length: $promptTokens + $maxTokens = ${promptTokens + maxTokens}"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.xebia.functional.xef.conversation

@DslMarker annotation class AiDsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import arrow.atomic.Atomic
import arrow.atomic.update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.AIError
import com.xebia.functional.xef.llm.Chat
Expand All @@ -7,8 +7,8 @@ import com.xebia.functional.xef.llm.Images
import com.xebia.functional.xef.llm.models.functions.CFunction
import com.xebia.functional.xef.llm.models.images.ImagesGenerationResponse
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.VectorStore
import kotlin.jvm.JvmSynthetic
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.KSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.VectorStore

expect abstract class PlatformConversation(
store: VectorStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.xebia.functional.xef.llm

import com.xebia.functional.tokenizer.ModelType
import com.xebia.functional.xef.AIError
import com.xebia.functional.xef.auto.AiDsl
import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.AiDsl
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.models.chat.*
import com.xebia.functional.xef.prompt.Prompt
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.xebia.functional.xef.llm
import arrow.core.nonFatalOrThrow
import arrow.core.raise.catch
import com.xebia.functional.xef.AIError
import com.xebia.functional.xef.auto.AiDsl
import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.AiDsl
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.models.chat.ChatCompletionRequestWithFunctions
import com.xebia.functional.xef.llm.models.chat.ChatCompletionResponseWithFunctions
import com.xebia.functional.xef.llm.models.functions.CFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.xebia.functional.xef.llm
import com.xebia.functional.xef.llm.models.images.ImagesGenerationRequest
import com.xebia.functional.xef.llm.models.images.ImagesGenerationResponse
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.VectorStore

interface Images : LLM {
suspend fun createImages(request: ImagesGenerationRequest): ImagesGenerationResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.xebia.functional.xef.llm

import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.models.chat.*
import com.xebia.functional.xef.vectorstores.Memory
import com.xebia.functional.xef.store.Memory
import io.ktor.util.date.*

internal object MemoryManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.xebia.functional.xef.llm

import com.xebia.functional.tokenizer.truncateText
import com.xebia.functional.xef.AIError
import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.models.chat.Message
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.prompt.templates.assistant
import com.xebia.functional.xef.vectorstores.Memory
import com.xebia.functional.xef.store.Memory

internal object PromptCalculator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ which states the following:
// TODO: We should consider a fork and maintain it ourselves.
*/
import com.xebia.functional.xef.auto.Description
import com.xebia.functional.xef.conversation.Description
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlinx.serialization.ExperimentalSerializationApi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.prompt.configuration

import com.xebia.functional.xef.auto.MessagePolicy
import com.xebia.functional.xef.conversation.MessagePolicy
import com.xebia.functional.xef.llm.models.chat.Role
import kotlin.jvm.JvmField
import kotlin.jvm.JvmOverloads
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.prompt.evaluator

import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.Chat
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.prompt.templates.system
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.prompt.expressions

import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.ChatWithFunctions
import com.xebia.functional.xef.llm.models.chat.Message
import com.xebia.functional.xef.prompt.Prompt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.prompt.expressions

import com.xebia.functional.xef.auto.Description
import com.xebia.functional.xef.conversation.Description
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.prompt.expressions

import com.xebia.functional.xef.auto.Description
import com.xebia.functional.xef.conversation.Description
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.prompt.lang

import com.xebia.functional.xef.auto.Conversation
import com.xebia.functional.xef.conversation.Conversation
import com.xebia.functional.xef.llm.ChatWithFunctions
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.prompt.templates.system
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import com.xebia.functional.xef.embeddings.Embedding

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

data class ConversationId(val value: String)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import arrow.atomic.Atomic
import arrow.atomic.getAndUpdate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import com.xebia.functional.xef.llm.models.chat.Message

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

fun List<Memory>.reduceByLimitToken(limitTokens: Int): List<Memory> =
fold(Pair(0, emptyList<Memory>())) { (accTokens, list), memory ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import com.xebia.functional.xef.embeddings.Embedding
import kotlin.jvm.JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.tokenizer.ModelType
import com.xebia.functional.xef.data.TestEmbeddings
import com.xebia.functional.xef.data.TestModel
import com.xebia.functional.xef.llm.models.chat.Message
import com.xebia.functional.xef.llm.models.chat.Role
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.LocalVectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.LocalVectorStore
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.ints.shouldBeLessThan
import io.kotest.matchers.shouldBe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

val lorem =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import com.xebia.functional.xef.data.TestEmbeddings
import io.kotest.core.spec.style.StringSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import com.xebia.functional.xef.data.TestEmbeddings
import io.kotest.core.spec.style.StringSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.vectorstores
package com.xebia.functional.xef.store

import com.xebia.functional.xef.llm.models.chat.Message
import com.xebia.functional.xef.llm.models.chat.Role
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import kotlinx.serialization.SerialInfo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.VectorStore

class JSConversation(
override val store: VectorStore,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.VectorStore

actual abstract class PlatformConversation
actual constructor(store: VectorStore, conversationId: ConversationId?) : Conversation, AutoClose {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto.jvm;
package com.xebia.functional.xef.conversation.jvm;

import java.lang.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.auto.jvm.Description
import com.xebia.functional.xef.conversation.jvm.Description

/**
* Description of a property to enhance the LLM prompt chances to get the data in the right format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

fun interface FromJson<A> {
fun fromJson(a: String): A
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.VectorStore
import java.io.Closeable

open class JVMConversation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.xebia.functional.xef.auto
package com.xebia.functional.xef.conversation

import com.xebia.functional.xef.auto.serialization.JacksonSerialization
import com.xebia.functional.xef.conversation.serialization.JacksonSerialization
import com.xebia.functional.xef.llm.Chat
import com.xebia.functional.xef.llm.ChatWithFunctions
import com.xebia.functional.xef.llm.Images
import com.xebia.functional.xef.llm.models.functions.CFunction
import com.xebia.functional.xef.llm.models.images.ImagesGenerationResponse
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.vectorstores.ConversationId
import com.xebia.functional.xef.vectorstores.VectorStore
import com.xebia.functional.xef.store.ConversationId
import com.xebia.functional.xef.store.VectorStore
import java.util.concurrent.CompletableFuture
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xebia.functional.xef.auto.futures
package com.xebia.functional.xef.conversation.futures

import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.xebia.functional.xef.auto.serialization
package com.xebia.functional.xef.conversation.serialization

import com.github.victools.jsonschema.generator.MemberScope
import com.github.victools.jsonschema.generator.Module
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder
import com.github.victools.jsonschema.generator.TypeScope
import com.xebia.functional.xef.auto.Description
import com.xebia.functional.xef.conversation.Description

internal class DescriptionModule : Module {
override fun applyToConfigBuilder(builder: SchemaGeneratorConfigBuilder) {
Expand Down
Loading

0 comments on commit 2829f57

Please sign in to comment.