Skip to content

Commit

Permalink
Remove hardcoded references to sources and targets in the prompts (#536)
Browse files Browse the repository at this point in the history
* Remove hardcoded references to sources and targets in the prompts

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Fix mypy + test errors

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Regenerate cache

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Update test config file

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>

* regenerate cache

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Regenerate cache

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Setting rulesets to be a particular to release to prevent cache misses

Signed-off-by: Shawn Hurley <shawn@hurley.page>

* Regen rebased cache

Signed-off-by: Shawn Hurley <shawn@hurley.page>

* setting sort on source and targets, regen cache

Signed-off-by: Shawn Hurley <shawn@hurley.page>

* fix for setting seed tasks correctly

Signed-off-by: Shawn Hurley <shawn@hurley.page>

---------

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>
Signed-off-by: Shawn Hurley <shawn@hurley.page>
Co-authored-by: Shawn Hurley <shawn@hurley.page>
  • Loading branch information
fabianvf and shawn-hurley authored Jan 23, 2025
1 parent e831798 commit 170114a
Show file tree
Hide file tree
Showing 113 changed files with 3,060 additions and 2,472 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: kai-rpc-server.${{ env.OS }}-${{ env.OS_ARCH }}.zip
path: kai-rpc-server.${{ env.OS }}-${{ env.OS_ARCH }}.zip
path: kai-rpc-server.${{ env.OS }}-${{ env.OS_ARCH }}.zip
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ get-analyzer-deps:

# This will get the rulesets and set them to be used by run_demo.py
get-rulesets:
(cd example/analysis && rm -rf rulesets && git clone https://github.com/konveyor/rulesets); rm -rf example/analysis/rulesets/preview
(cd example/analysis && rm -rf rulesets && git clone --depth 1 --branch v0.6.0 https://github.com/konveyor/rulesets); rm -rf example/analysis/rulesets/preview

run-demo:
cd example && python run_demo.py
Expand Down
1 change: 1 addition & 0 deletions kai/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def get_impacted_files(self) -> dict[pathlib.Path, list[ExtendedIncident]]:
"violation_name": violation_name,
"ruleset_description": ruleset.description,
"violation_description": violation.description,
"violation_labels": violation.labels,
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"input": [
{
"lc": 1,
"type": "constructor",
"id": [
"langchain",
"schema",
"messages",
"SystemMessage"
],
"kwargs": {
"content": "\n You are an experienced java developer, who specializes in migrating code from java-ee to quarkus\n ",
"type": "system"
}
},
{
"lc": 1,
"type": "constructor",
"id": [
"langchain",
"schema",
"messages",
"HumanMessage"
],
"kwargs": {
"content": "\n I will give you a java-ee file for which I want to take one step towards migrating to quarkus.\n\nI will provide you with static source code analysis information highlighting an issue which needs to be addressed.\n\nFix only the problem described. Other problems will be solved in subsequent steps so it is unnecessary to handle them now.\n\nBefore attempting to migrate the code to quarkus reason through what changes are required and why.\n\nPay attention to changes you make and impacts to external dependencies in the pom.xml as well as changes to imports we need to consider.\n\nRemember when updating or adding annotations that the class must be imported.\n\nAs you make changes that impact the pom.xml or imports, be sure you explain what needs to be updated.\n\nAfter you have shared your step by step thinking, provide a full output of the updated file.\n\n# Input information\n\n## Input File\n\nFile name: \"Producers.java\"\nSource file contents:\n```java\npackage com.redhat.coolstore.utils;\n\nimport jakarta.enterprise.inject.Produces;\nimport jakarta.enterprise.inject.spi.InjectionPoint;\nimport java.util.logging.Logger;\n\n/**\n * A class that uses CDI to alias Java EE resources, such as the @Resource annotation\n * \n */\npublic class Producers {\n\n Logger log = Logger.getLogger(Producers.class.getName());\n\n @Produces\n public Logger produceLog(InjectionPoint injectionPoint) {\n return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());\n }\n\n}\n```\n\n## Issues\n\n\n### incident 0\nincident to fix: \"In Quarkus, you can skip the @Produces annotation completely if the producer method is annotated with a scope annotation, a stereotype or a qualifier..\n This field could be accessed using a `@Named` getter method instead.\"\nLine number: 12\n\n\n\n# Output Instructions\nStructure your output in Markdown format such as:\n\n## Reasoning\nWrite the step by step reasoning in this markdown section. If you are unsure of a step or reasoning, clearly state you are unsure and why.\n\n## Updated java File\n```java\n// Write the updated file in this section. If the file should be removed, make the content of the updated file a comment explaining it should be removed.\n```\n\n## Additional Information (optional)\n\nIf you have any additional details or steps that need to be performed, put it here.\n\n ",
"type": "human"
}
}
],
"output": {
"lc": 1,
"type": "constructor",
"id": [
"langchain",
"schema",
"messages",
"AIMessage"
],
"kwargs": {
"content": "## Reasoning\nTo address the issue described, we need to consider the differences in how Quarkus handles CDI (Context and Dependency Injection) compared to Java EE. \n\nIn Java EE, the `@Produces` annotation is used to enable the creation of beans that can be injected into other components. However, Quarkus simplifies this process by allowing the use of scope annotations, stereotypes, or qualifiers to define the scope of a bean.\n\nIn this case, we have a `Logger` being produced by the `produceLog` method. Since we're not explicitly defining a scope for this bean, we can use the `@Named` annotation to make it a named bean, which can then be injected into other components.\n\nHowever, the issue also suggests using a getter method instead of a field. This is because Quarkus uses a more traditional JavaBean approach for named beans, where a getter method is used to access the bean.\n\nSo, we will replace the `produceLog` method with a getter method annotated with `@Named` and `@ApplicationScoped` (since we're not specifying a scope, we'll use the application scope by default).\n\n## Updated java File\n```java\npackage com.redhat.coolstore.utils;\n\nimport jakarta.enterprise.context.ApplicationScoped;\nimport jakarta.inject.Named;\n\nimport java.util.logging.Logger;\n\n/**\n * A class that uses CDI to alias Java EE resources, such as the @Resource annotation\n * \n */\npublic class Producers {\n\n @Named\n @ApplicationScoped\n public Logger getLogger() {\n return Logger.getLogger(Producers.class.getName());\n }\n\n}\n```\n\n## Additional Information (optional)\nNote that we've also removed the `injectionPoint` parameter, as it's not necessary with the new approach. Additionally, we've changed the logger name to use the `Producers` class name, since we're not using the `injectionPoint` to get the member's declaring class name.\n\nNo changes are required in the `pom.xml` file for this specific update, as we're only changing the annotations and method signature. However, if you're planning to use Quarkus, you'll need to add the Quarkus CDI extension to your `pom.xml` file:\n```xml\n<dependency>\n <groupId>io.quarkus</groupId>\n <artifactId>quarkus-arc</artifactId>\n</dependency>\n```",
"response_metadata": {
"finish_reason": "stop",
"model_name": "kai-test-generation"
},
"type": "ai",
"id": "run-1710698d-63b3-401d-8cdd-92be5d174686-0",
"tool_calls": [],
"invalid_tool_calls": []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"input": [
{
"lc": 1,
"type": "constructor",
"id": [
"langchain",
"schema",
"messages",
"SystemMessage"
],
"kwargs": {
"content": "\n You are an experienced java developer, who specializes in migrating code from java-ee to quarkus\n ",
"type": "system"
}
},
{
"lc": 1,
"type": "constructor",
"id": [
"langchain",
"schema",
"messages",
"HumanMessage"
],
"kwargs": {
"content": "\n I will give you a java-ee file for which I want to take one step towards migrating to quarkus.\n\nI will provide you with static source code analysis information highlighting an issue which needs to be addressed.\n\nFix only the problem described. Other problems will be solved in subsequent steps so it is unnecessary to handle them now.\n\nBefore attempting to migrate the code to quarkus reason through what changes are required and why.\n\nPay attention to changes you make and impacts to external dependencies in the pom.xml as well as changes to imports we need to consider.\n\nRemember when updating or adding annotations that the class must be imported.\n\nAs you make changes that impact the pom.xml or imports, be sure you explain what needs to be updated.\n\nAfter you have shared your step by step thinking, provide a full output of the updated file.\n\n# Input information\n\n## Input File\n\nFile name: \"ShoppingCartOrderProcessor.java\"\nSource file contents:\n```java\npackage com.redhat.coolstore.service;\n\nimport java.util.logging.Logger;\nimport jakarta.annotation.Resource;\nimport jakarta.inject.Inject;\nimport javax.jms.JMSContext;\nimport javax.jms.Topic;\n\nimport com.redhat.coolstore.model.ShoppingCart;\nimport com.redhat.coolstore.utils.Transformers;\nimport io.quarkus.jms.JMSTopic;\n\n@jakarta.ejb.Stateless\npublic class ShoppingCartOrderProcessor {\n\n @Inject\n Logger log;\n\n @Inject\n JMSContext context;\n\n @Inject\n @JMSTopic(\"orders\")\n Topic ordersTopic;\n\n \n \n public void process(ShoppingCart cart) {\n log.info(\"Sending order from processor: \");\n context.createProducer().send(ordersTopic, Transformers.shoppingCartToJson(cart));\n }\n\n\n\n}\n```\n\n## Issues\n\n\n### incident 0\nincident to fix: \"References to JavaEE/JakartaEE JMS elements should be removed and replaced with their Quarkus SmallRye/Microprofile equivalents.\"\nLine number: 7\n\n\n\n# Output Instructions\nStructure your output in Markdown format such as:\n\n## Reasoning\nWrite the step by step reasoning in this markdown section. If you are unsure of a step or reasoning, clearly state you are unsure and why.\n\n## Updated java File\n```java\n// Write the updated file in this section. If the file should be removed, make the content of the updated file a comment explaining it should be removed.\n```\n\n## Additional Information (optional)\n\nIf you have any additional details or steps that need to be performed, put it here.\n\n ",
"type": "human"
}
}
],
"output": {
"lc": 1,
"type": "constructor",
"id": [
"langchain",
"schema",
"messages",
"AIMessage"
],
"kwargs": {
"content": "## Reasoning\nTo address the issue described in incident 0, we need to replace the JavaEE/JakartaEE JMS elements with their Quarkus SmallRye/Microprofile equivalents.\n\n1. The `@jakarta.ejb.Stateless` annotation is a JavaEE annotation and should be removed as Quarkus does not support EJBs. Instead, Quarkus uses CDI (Context and Dependency Injection) for bean management.\n\n2. The `JMSContext` and `Topic` classes are part of the JavaEE JMS API. In Quarkus, we should use the `@Inject` annotation with the `JMSContext` type from the `io.quarkus.jms.runtime` package, but we need to use the `@Channel` annotation from the `io.quarkus.smallrye.jms` package to inject the topic.\n\nHowever, the `@Channel` annotation is used to inject a JMS channel, not a topic. For topics, we should use the `@Inject` annotation with the `JMSContext` type and then use the `context.createProducer().send(\"orders\", message)` method to send a message to the topic.\n\n3. The `@JMSTopic` annotation is not a standard JavaEE annotation, it's a Quarkus annotation, so we don't need to replace it.\n\n## Updated java File\n```java\npackage com.redhat.coolstore.service;\n\nimport java.util.logging.Logger;\nimport jakarta.inject.Inject;\nimport io.quarkus.jms.runtime.JMSContext;\nimport com.redhat.coolstore.model.ShoppingCart;\nimport com.redhat.coolstore.utils.Transformers;\n\nimport io.quarkus.jms.JMSTopic;\n\npublic class ShoppingCartOrderProcessor {\n\n @Inject\n Logger log;\n\n @Inject\n JMSContext context;\n\n @Inject\n @JMSTopic(\"orders\")\n String ordersTopic;\n\n \n \n public void process(ShoppingCart cart) {\n log.info(\"Sending order from processor: \");\n context.createProducer().send(ordersTopic, Transformers.shoppingCartToJson(cart));\n }\n\n\n\n}\n```\n\n## Additional Information\nIn the `pom.xml` file, we need to make sure that we have the following dependencies:\n\n```xml\n<dependency>\n <groupId>io.quarkus</groupId>\n <artifactId>quarkus-jms</artifactId>\n</dependency>\n<dependency>\n <groupId>io.quarkus</groupId>\n <artifactId>quarkus-artemis-jms</artifactId>\n</dependency>\n```\n\nAlso, we need to configure the JMS connection factory and the topic in the `application.properties` file:\n\n```properties\nquarkus.artemis.url=tcp://localhost:61616\nquarkus.artemis.username=artemis\nquarkus.artemis.password=simply\nquarkus.artemis.jms.topic.orders=orders\n```",
"response_metadata": {
"finish_reason": "stop",
"model_name": "kai-test-generation"
},
"type": "ai",
"id": "run-80e943bf-776e-455e-8737-596a9e5c9361-0",
"tool_calls": [],
"invalid_tool_calls": []
}
}
}
Loading

0 comments on commit 170114a

Please sign in to comment.