Skip to content

Commit

Permalink
fix: fix relevant code issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 16, 2023
1 parent 94d1f33 commit 103272b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CodeSemanticWorkflow : Workflow() {
| - Keep number of quoted lines of code to a minimum when possible
| - Basic markdown is allowed
| - If you have enough information, try your best to answer more details.
| - You muse use PlantUML to provide key process of your thinking,
| - You MUST provide key process of your thinking,
|
|相关的代码:
|${'$'}{relevantCode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import cc.unitmesh.cf.core.flow.SolutionExecutor
import cc.unitmesh.cf.core.flow.model.Answer
import cc.unitmesh.cf.core.llms.LlmMsg
import cc.unitmesh.cf.core.llms.LlmProvider
import cc.unitmesh.cf.core.parser.MarkdownCode
import cc.unitmesh.cf.domains.interpreter.flow.CodeInput
import cc.unitmesh.cf.domains.interpreter.flow.CodeSolutionExecutor
import cc.unitmesh.cf.domains.semantic.CodeSemanticWorkflow
import cc.unitmesh.cf.domains.semantic.context.SemanticVariableResolver
import cc.unitmesh.cf.domains.semantic.model.ExplainQuery
Expand All @@ -14,7 +17,10 @@ import cc.unitmesh.nlp.embedding.OpenAiEncoding
import cc.unitmesh.rag.document.Document
import cc.unitmesh.rag.document.DocumentOrder
import cc.unitmesh.rag.store.EmbeddingStore
import io.reactivex.rxjava3.core.BackpressureStrategy
import io.reactivex.rxjava3.core.Flowable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

class SemanticSolutionExecutor(
val completion: LlmProvider,
Expand Down Expand Up @@ -52,14 +58,13 @@ class SemanticSolutionExecutor(
codes.add(it.score to it.embedded.text)
variables.putCode("", codes.map { it.second })
val testPrompt = variables.compile(basePrompt)
// todo: make 3072 configurable
// todo: make 2048 configurable
if (encodingTokenizer.encode(testPrompt).size >= 2048) {
codes.removeAt(codes.size - 1)
return@forEach
}
}


val reorderCodes = DocumentOrder.lostInMiddleReorder(codes)
variables.putCode("", reorderCodes.map { it.second })
val finalPrompt = variables.compile(basePrompt)
Expand Down Expand Up @@ -89,7 +94,20 @@ class SemanticSolutionExecutor(
|```
|""".trimMargin()

return Flowable.just(Answer(this.javaClass.name, debugInfo))
.concatWith(completion.map { Answer(this.javaClass.name, it) })
return Flowable.create({ emitter ->
emitter.onNext(Answer(this.javaClass.name, debugInfo))
completion
.subscribe(
{ result ->
val answer = Answer(this.javaClass.name, result)
emitter.onNext(answer)
},
{ throwable: Throwable ->
emitter.tryOnError(throwable)
})
{
emitter.onComplete()
}
}, BackpressureStrategy.BUFFER)
}
}

0 comments on commit 103272b

Please sign in to comment.