{"id":19228125,"url":"https://github.com/unit-mesh/chocolate-factory-examples","last_synced_at":"2025-04-11T00:04:34.632Z","repository":{"id":195709243,"uuid":"693494402","full_name":"unit-mesh/chocolate-factory-examples","owner":"unit-mesh","description":"the Spring examples for Chocolate Factory","archived":false,"fork":false,"pushed_at":"2023-10-29T03:54:31.000Z","size":403,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T00:04:27.794Z","etag":null,"topics":["agent","genai","genai-poc"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unit-mesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-19T06:26:06.000Z","updated_at":"2025-01-08T05:36:00.000Z","dependencies_parsed_at":"2024-11-09T15:28:24.744Z","dependency_job_id":"40ba966d-2de3-4214-9c58-dde657483b7c","html_url":"https://github.com/unit-mesh/chocolate-factory-examples","commit_stats":null,"previous_names":["unit-mesh/chocolate-factory-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unit-mesh%2Fchocolate-factory-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unit-mesh%2Fchocolate-factory-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unit-mesh%2Fchocolate-factory-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unit-mesh%2Fchocolate-factory-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unit-mesh","download_url":"https://codeload.github.com/unit-mesh/chocolate-factory-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317705,"owners_count":21083528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","genai","genai-poc"],"created_at":"2024-11-09T15:26:49.445Z","updated_at":"2025-04-11T00:04:34.607Z","avatar_url":"https://github.com/unit-mesh.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chocolate Factory Example\n\n处理流程：\n\n![Query \u0026\u0026 Indexing](docs/query-indexing.png)\n\n需要了解的基本知识：\n\n- 基本的 Kotlin 语法\n- 如何写好 Prompt \n- 检索增强（Retrieval Augmented Generation）相关的概念，可参考：RAG: [https://framework.unitmesh.cc/docs/rag](https://framework.unitmesh.cc/docs/rag)\n\n本项目相关的 Chocolate Factory 文档:\n\n- RAG: [https://framework.unitmesh.cc/docs/rag](https://framework.unitmesh.cc/docs/rag)\n- 代码拆分：https://framework.unitmesh.cc/docs/code-splitter\n\n## 相关论文\n\n- [Query2doc: Query Expansion with Large Language Models](https://arxiv.org/abs/2303.07678)\n- [Precise Zero-Shot Dense Retrieval without Relevance Labels](https://arxiv.org/abs/2212.10496)\n- [Lost in the Middle: How Language Models Use Long Contexts](https://arxiv.org/abs/2307.03172)\n\n## 查询过程\n\n用户的查询条件：Semantic Workflow 是如何实现的？\n\n生成的中间 DSL：\n\n- question: Semantic Workflow 是如何实现的？\n- englishQuery: How is Semantic Workflow implemented?\n- originLanguageQuery: Semantic Workflow 是如何实现的？\n- hypotheticalCode:\n```kotlin\npublic class SemanticWorkflow {\n   private WorkflowEngine engine;\n   \n   public SemanticWorkflow() {\n      engine = new WorkflowEngine();\n   }\n   \n   public void executeWorkflow(Workflow workflow) {\n      // Perform semantic analysis on the workflow\n      SemanticAnalyzer analyzer = new SemanticAnalyzer();\n      Workflow analyzedWorkflow = analyzer.analyze(workflow);\n      \n      // Execute the analyzed workflow using the workflow engine\n      engine.execute(analyzedWorkflow);\n   }\n}\n```\n\n相关代码片段：\n\n```bash\n0.7847863 // canonicalName: cc.unitmesh.cf.domains.semantic.CodeSemanticWorkflowTest\n0.76635444 // canonicalName: cc.unitmesh.cf.domains.semantic.CodeSemanticDecl\n0.74648994 // canonicalName: cc.unitmesh.cf.core.flow.ProblemAnalyzer\n0.7410852 // canonicalName: cc.unitmesh.cf.domains.spec.SpecDomainDecl\n0.72767156 // canonicalName: cc.unitmesh.cf.core.flow.DomainDeclaration\n0.73245597 // canonicalName: cc.unitmesh.cf.core.flow.model.WorkflowResult\n0.7434818 // canonicalName: cc.unitmesh.cf.domains.interpreter.CodeInterpreterWorkflow.execute\n0.757218 // canonicalName: cc.unitmesh.cf.core.flow.Workflow\n0.7722022 // canonicalName: cc.unitmesh.cf.domains.semantic.flow.SemanticProblemAnalyzer\n0.807935 // canonicalName: cc.unitmesh.cf.domains.semantic.CodeSemanticWorkflow.execute\n```\n\n## 最后输出\n\n根据提供的代码，我们可以看到 CodeSemanticWorkflow 是一个继承自 Workflow 的类，它实现了 execute 方法来执行语义化的代码搜索。\n\n在 execute 方法中，它首先创建了一个 ElasticsearchStore 对象，并获取了用户最后一条消息的内容作为问题。然后，它使用 SemanticProblemAnalyzer\n对象来分析问题，该对象使用 llmProvider 来完成问题的解析。接下来，它使用 SemanticSolutionExecutor 对象来执行语义化的代码搜索，并将结果转换为\nFlowable\u003cAnswer\u003e。最后，它调用 toFlowableResult 方法将结果转换为 Flowable\u003cWorkflowResult\u003e 并返回。\n\n下面是一个使用 PlantUML 绘制的流程图，展示了 CodeSemanticWorkflow 的执行过程：\n\n```plantuml\n@startuml\nstart\n:创建 ElasticsearchStore 对象;\n:获取用户最后一条消息的内容;\n:使用 SemanticProblemAnalyzer 对象分析问题;\n:使用 SemanticSolutionExecutor 对象执行语义化的代码搜索;\n:将结果转换为 Flowable\u003cAnswer\u003e;\n:将结果转换为 Flowable\u003cWorkflowResult\u003e;\nstop\n@enduml\n```\n\n希望以上信息能够回答您的问题。\n\n## 文档\n\n环境准备：\n\n1. Install [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html)\n2. Start project: `./gradlew bootRun`\n\n### 创建索引\n\n1. 下载 [ArchGuard Scanner CLI](https://github.com/archguard/archguard/releases) （搜索  scanner_cli-2.0.7-all.jar）\n2. 运行索引\n\n```\njava -jar scanner_cli-2.0.6-all.jar --language=Kotlin --output=http --server-url=http://localhost:18080 --\npath=/Volumes/source/ai/chocolate-factory --with-function-code\n```\n\n## 调试示例\n\n执行：[API-Request.http](./API-Request.http)\n\n结果示例：\n\n\n```debug\n查询条件：\n\nquestion: Kotlin 代码是如何分析和处理的？\nenglishQuery: analyze and process Kotlin code\noriginLanguageQuery: // Kotlin 代码分析和处理的方法\nhypotheticalCode:\nval code = \"\"\"\n    fun calculateSum(a: Int, b: Int): Int {\n        return a + b\n    }\n\"\"\"\n\nval tree = KotlinParser().parse(code)\nval analyzer = KotlinAnalyzer()\nval result = analyzer.analyze(tree)\nval processedCode = KotlinProcessor().process(result)\n\n代码片段：\n\n0.788222 // canonicalName: cc.unitmesh.code.interpreter.KotlinInterpreterTest\n0.77546304 // canonicalName: org.archguard.scanner.analyser.count.LanguageWorkerTest.bomSkip.bomSkip2.checkComplexity.checkComplexity2.processByFileFromResource.processKotlinDemo.languageServiceFile\n0.76314676 // canonicalName: org.archguard.scanner.analyser.ScalaAnalyser\n0.75397754 // canonicalName: com.thoughtworks.archguard.insights.application.IssueInsightFilterTest\n0.74462515 // canonicalName: org.archguard.scanner.analyser.SimpleEstimateContext\n0.74160945 // canonicalName: com.thoughtworks.archguard.scanner2.domain.model.MethodMetric\n0.74107826 // canonicalName: com.thoughtworks.archguard.code.module.domain.AbstractAnalysisServiceTest.setUp.should_calculate_package_abstract_ratio\n0.74130785 // canonicalName: org.archguard.scanner.analyser.diffchanges.GitDiffer.countBetween.calculateChange\n0.741813 // canonicalName: org.archguard.doc.generator.KotlinAnalysisTest\n0.7492634 // canonicalName: org.archguard.scanner.analyser.JavaAnalyser.analyse.analysisBasicInfoByFile\n0.7600594 // canonicalName: cc.unitmesh.code.interpreter.KotlinInterpreter.eval\n0.7631941 // canonicalName: org.archguard.aaac.repl.ArchdocInterpreter\n0.77764046 // canonicalName: org.archguard.scanner.analyser.KotlinAnalyser\n\n```\n根据提供的代码，可以看出Kotlin代码的分析和处理是通过使用不同的类和方法来完成的。以下是关键的类和方法：\n\n1. `KotlinAnalyser`类：这个类是用来分析Kotlin代码的。它实现了`LanguageSourceCodeAnalyser`接口，并且有一个`analyse()`方法来执行代码分析。在`analyse()`方法中，它使用`getFilesByPath()`方法获取指定路径下的所有Kotlin文件，并对每个文件调用`analysisByFile()`方法进行分析。最后，它将分析结果保存到`client`中。\n\n2. `analysisByFile()`方法：这个方法用于分析单个Kotlin文件。它首先读取文件内容，然后使用`kotlinast.KotlinAnalyser`类的`analysis()`方法对代码进行分析。分析结果包括数据结构和函数列表。最后，它将分析结果返回。\n\n3. `KotlinReplWrapper`类：这个类是用来执行Kotlin代码的。它有一个`eval()`方法，可以执行传入的Kotlin代码，并返回执行结果。\n\n综上所述，Kotlin代码的分析和处理是通过使用`KotlinAnalyser`类和`KotlinReplWrapper`类来完成的。`KotlinAnalyser`类用于分析代码并保存分析结果，而`KotlinReplWrapper`类用于执行代码并返回执行结果。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funit-mesh%2Fchocolate-factory-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funit-mesh%2Fchocolate-factory-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funit-mesh%2Fchocolate-factory-examples/lists"}