Skip to content

Commit

Permalink
refactor: update for new flow
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 20, 2023
1 parent 6755dfe commit 31d6327
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion rag-script/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
temp
dependencies/
0_codes.json
0_codes.json
.env
2 changes: 2 additions & 0 deletions rag-script/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependencies {
implementation(libs.huggingface.tokenizers)
implementation(libs.dataframe)

implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")

implementation("io.ktor:ktor-client-logging:2.3.4")
implementation("io.ktor:ktor-client-core:2.3.4")
implementation("io.ktor:ktor-client-cio:2.3.4")
Expand Down
4 changes: 2 additions & 2 deletions rag-script/src/main/kotlin/cc/unitmesh/apply/Connection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Connection(val connectionType: ConnectionType, val apiKey: String, val api
return completion(function())
}

fun streamCompletion(msg: String): Flowable<String> {
return provider.streamCompletion(listOf(LlmMsg.ChatMessage(LlmMsg.ChatRole.User, msg)))
fun streamCompletion(function: () -> String): Flowable<String> {
return provider.streamCompletion(listOf(LlmMsg.ChatMessage(LlmMsg.ChatRole.User, function())))
}
}

Expand Down
15 changes: 15 additions & 0 deletions rag-script/src/main/kotlin/cc/unitmesh/apply/Workflow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ import cc.unitmesh.nlp.embedding.EmbeddingProvider
import cc.unitmesh.rag.document.Document
import cc.unitmesh.rag.store.EmbeddingMatch
import cc.unitmesh.store.ElasticsearchStore
import io.github.cdimascio.dotenv.Dotenv




/**
* Apply is a DSL for invoking a function in a template.
*/
@ApplyDsl
class Workflow(val name: String) {
var env = try {
Dotenv.load()
} catch (e: Exception) {
null
}

var connection: Connection = Connection(ConnectionType.OpenAI, "", "")
var vectorStore: VectorStore = VectorStore(StoreType.Elasticsearch)
var embedding: EmbeddingEngine = EmbeddingEngine(EngineType.SentenceTransformers)
Expand Down Expand Up @@ -117,3 +127,8 @@ fun scripting(name: String, init: Workflow.() -> Unit): Workflow {
workflow.init()
return workflow
}
fun scripting(init: Workflow.() -> Unit): Workflow {
val workflow = Workflow("scripting")
workflow.init()
return workflow
}
7 changes: 5 additions & 2 deletions rag-script/src/test/kotlin/cc/unitmesh/apply/WorkflowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class WorkflowTest {
@Test
@Ignore
fun index_and_query() {
scripting("code") {
connection = Connection(ConnectionType.OpenAI)
scripting {
val apiKey = env?.get("OPENAI_API_KEY") ?: ""
val apiHost = env?.get("OPENAI_API_HOST") ?: ""

connection = Connection(ConnectionType.OpenAI, apiKey, apiHost)
embedding = EmbeddingEngine(EngineType.SentenceTransformers)
vectorStore = VectorStore(StoreType.Elasticsearch)

Expand Down

0 comments on commit 31d6327

Please sign in to comment.