Skip to content

Commit

Permalink
adding test notebook
Browse files Browse the repository at this point in the history
Co-authored-by: JonahSussman <sussmanjonah@gmail.com>
Co-authored-by: Jason Montleon <jmontleo@redhat.com>
Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us>
Signed-off-by: Savitha Raghunathan <saveetha13@gmail.com>
  • Loading branch information
savitharaghunathan committed Feb 14, 2024
1 parent 68765e6 commit 8e7290e
Show file tree
Hide file tree
Showing 2 changed files with 553 additions and 7 deletions.
176 changes: 169 additions & 7 deletions kai/ai-test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,182 @@
"outputs": [],
"source": [
"from langchain import PromptTemplate\n",
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.chains import LLMChain\n",
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.callbacks import FileCallbackHandler\n",
"\n",
"import os\n",
"\n",
"prompt = \"\"\"\n",
"say this is a test\n",
"template = \"\"\"\n",
"You are an excellent enterprise architect who has an extensive\n",
"background in helping companies rewrite their legacy Java EE applications to Quarkus.\n",
"\n",
"You will read a user's problem along with examples of how they have solved a problem in the past.\n",
"The past examples will be presented in format of a summary of the issue along with source code of \n",
"that point in time along with the updated source code when the problem is fixed\n",
"\n",
"You will then write Quarkus code to solve their current problem.\n",
"You will output the results in the form a diff which can be applied via 'git apply'.\n",
"\n",
"Your job is to look at the 'Current Issue' and the 'Current Issue Original Source Code' \n",
"and rewrite the 'Current Issue Original Source Code' so the 'Current Issue' is solved \n",
"in a manner similar to how 'Example #1 Original Source Code' was rewritten to \n",
"'Example #1 Solved Source Code' \n",
"\n",
"Think through the changes you will make and explain each step of the process.\n",
"If you are unsure of what changes is needed please state you are unsure and ask \n",
"for clarification to help you.\n",
"\n",
"When you are done explaining the reasoning for each change, write the updated \n",
"Quarkus source code in the form of a diff which can be applied via 'git apply' \n",
"in Markdown format, e.g.:\n",
"\n",
"```diff\n",
"....\n",
"```\n",
"\n",
"### Input:\n",
"\n",
"Example #1 Issue: {example1_issue}\n",
"\n",
"Example #1 Original Source Code:\n",
"```java\n",
"{example1_original_code}\n",
"```\n",
"\n",
"Example #1 Solved Source Code:\n",
"```java\n",
"{example1_solved_code}\n",
"```\n",
"\n",
"Current Issue: \n",
"{current_issue}\n",
"\n",
"Current Issue Original Source Code: \n",
"```java\n",
"{current_issue_original_code}\n",
"```\n",
"\"\"\"\n",
"\n",
" streaming=True)\n",
"example1_original_code = \"\"\"import java.util.HashMap;\n",
"import java.util.Map;\n",
"\n",
"public class OldStyleRouter {\n",
" interface RequestHandler {\n",
" void handle(String requestData);\n",
" }\n",
"\n",
" private Map<String, RequestHandler> routes;\n",
"\n",
" public OldStyleRouter() {\n",
" routes = new HashMap<>();\n",
" }\n",
"\n",
" public void addRoute(String path, RequestHandler handler) {\n",
" routes.put(path, handler);\n",
" }\n",
"\n",
" public void handleRequest(String path, String requestData) {\n",
" if (routes.containsKey(path)) {\n",
" routes.get(path).handle(requestData);\n",
" } else {\n",
" System.out.println(\"No handler for path: \" + path);\n",
" }\n",
" }\n",
"\n",
" public static void main(String[] args) {\n",
" OldStyleRouter router = new OldStyleRouter();\n",
"\n",
" // Adding routes using anonymous classes\n",
" router.addRoute(\"/home\", new RequestHandler() {\n",
" @Override\n",
" public void handle(String data) {\n",
" System.out.println(\"Home Page Requested: \" + data);\n",
" }\n",
" });\n",
" router.addRoute(\"/about\", new RequestHandler() {\n",
" @Override\n",
" public void handle(String data) {\n",
" System.out.println(\"About Page Requested: \" + data);\n",
" }\n",
" });\n",
"\n",
" // Handling requests\n",
" router.handleRequest(\"/home\", \"User data for home\");\n",
" router.handleRequest(\"/about\", \"User data for about\");\n",
" }\n",
"}\n",
"\"\"\"\n",
"\n",
"example1_solved_code = \"\"\"import java.util.HashMap;\n",
"import java.util.Map;\n",
"import java.util.function.Consumer;\n",
"\n",
"public class ModernRouter {\n",
" private Map<String, Consumer<String>> routes;\n",
"\n",
" public ModernRouter() {\n",
" routes = new HashMap<>();\n",
" }\n",
"\n",
" public void addRoute(String path, Consumer<String> handler) {\n",
" routes.put(path, handler);\n",
" }\n",
"\n",
" public void handleRequest(String path, String requestData) {\n",
" if (routes.containsKey(path)) {\n",
" routes.get(path).accept(requestData);\n",
" } else {\n",
" System.out.println(\"No handler for path: \" + path);\n",
" }\n",
" }\n",
"\n",
" public static void main(String[] args) {\n",
" ModernRouter router = new ModernRouter();\n",
"\n",
" // Adding routes with lambda expressions\n",
" router.addRoute(\"/home\", data -> System.out.println(\"Home Page Requested: \" + data));\n",
" router.addRoute(\"/about\", data -> System.out.println(\"About Page Requested: \" + data));\n",
"\n",
" // Handling requests\n",
" router.handleRequest(\"/home\", \"User data for home\");\n",
" router.handleRequest(\"/about\", \"User data for about\");\n",
" }\n",
"}\n",
"\"\"\"\n",
"\n",
"current_issue_original_code = \"\"\"import java.util.Comparator;\n",
"\n",
"public class OldStyleJavaExample {\n",
" public static void main(String[] args) {\n",
" // Using an anonymous class to implement a comparator\n",
" Comparator<Integer> compareIntegers = new Comparator<Integer>() {\n",
" @Override\n",
" public int compare(Integer x, Integer y) {\n",
" return x.compareTo(y);\n",
" }\n",
" };\n",
"\n",
" // Using the comparator\n",
" int comparisonResult = compareIntegers.compare(5, 10);\n",
" System.out.println(\"Result using anonymous class: \" + comparisonResult);\n",
" }\n",
"}\n",
"\"\"\"\n",
"\n",
"template_args = {\n",
" \"example1_issue\": \"The usage of anonymous classes for routes is against our coding conventions. Please use modern Java functional syntax instead\",\n",
" \"example1_original_code\": example1_original_code,\n",
" \"example1_solved_code\": example1_solved_code,\n",
" \"current_issue\": \"The usage of anonymous classes for routes is against our coding conventions. Please use modern Java functional syntax instead\",\n",
" \"current_issue_original_code\": current_issue_original_code,\n",
"}\n",
"\n",
"formatted_prompt = template.format(**template_args)\n",
"\n",
"llm = ChatOpenAI(streaming=True)\n",
"\n",
"for chunk in llm.stream(prompt):\n",
" print(chunk.content, end=\"\", flush=True)\n"
"for chunk in llm.stream(formatted_prompt):\n",
" print(chunk.content, end=\"\", flush=True)"
]
},
{
Expand Down
Loading

0 comments on commit 8e7290e

Please sign in to comment.