Skip to content

Commit 31d6327

Browse files
committed
refactor: update for new flow
1 parent 6755dfe commit 31d6327

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

rag-script/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
temp
22
dependencies/
3-
0_codes.json
3+
0_codes.json
4+
.env

rag-script/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ dependencies {
2424
implementation(libs.huggingface.tokenizers)
2525
implementation(libs.dataframe)
2626

27+
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
28+
2729
implementation("io.ktor:ktor-client-logging:2.3.4")
2830
implementation("io.ktor:ktor-client-core:2.3.4")
2931
implementation("io.ktor:ktor-client-cio:2.3.4")

rag-script/src/main/kotlin/cc/unitmesh/apply/Connection.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class Connection(val connectionType: ConnectionType, val apiKey: String, val api
3737
return completion(function())
3838
}
3939

40-
fun streamCompletion(msg: String): Flowable<String> {
41-
return provider.streamCompletion(listOf(LlmMsg.ChatMessage(LlmMsg.ChatRole.User, msg)))
40+
fun streamCompletion(function: () -> String): Flowable<String> {
41+
return provider.streamCompletion(listOf(LlmMsg.ChatMessage(LlmMsg.ChatRole.User, function())))
4242
}
4343
}
4444

rag-script/src/main/kotlin/cc/unitmesh/apply/Workflow.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ import cc.unitmesh.nlp.embedding.EmbeddingProvider
66
import cc.unitmesh.rag.document.Document
77
import cc.unitmesh.rag.store.EmbeddingMatch
88
import cc.unitmesh.store.ElasticsearchStore
9+
import io.github.cdimascio.dotenv.Dotenv
10+
11+
12+
913

1014
/**
1115
* Apply is a DSL for invoking a function in a template.
1216
*/
1317
@ApplyDsl
1418
class Workflow(val name: String) {
19+
var env = try {
20+
Dotenv.load()
21+
} catch (e: Exception) {
22+
null
23+
}
24+
1525
var connection: Connection = Connection(ConnectionType.OpenAI, "", "")
1626
var vectorStore: VectorStore = VectorStore(StoreType.Elasticsearch)
1727
var embedding: EmbeddingEngine = EmbeddingEngine(EngineType.SentenceTransformers)
@@ -117,3 +127,8 @@ fun scripting(name: String, init: Workflow.() -> Unit): Workflow {
117127
workflow.init()
118128
return workflow
119129
}
130+
fun scripting(init: Workflow.() -> Unit): Workflow {
131+
val workflow = Workflow("scripting")
132+
workflow.init()
133+
return workflow
134+
}

rag-script/src/test/kotlin/cc/unitmesh/apply/WorkflowTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ class WorkflowTest {
1313
@Test
1414
@Ignore
1515
fun index_and_query() {
16-
scripting("code") {
17-
connection = Connection(ConnectionType.OpenAI)
16+
scripting {
17+
val apiKey = env?.get("OPENAI_API_KEY") ?: ""
18+
val apiHost = env?.get("OPENAI_API_HOST") ?: ""
19+
20+
connection = Connection(ConnectionType.OpenAI, apiKey, apiHost)
1821
embedding = EmbeddingEngine(EngineType.SentenceTransformers)
1922
vectorStore = VectorStore(StoreType.Elasticsearch)
2023

0 commit comments

Comments
 (0)