From 2c569635eb5558a02f0652f68aae875857b0ee4c Mon Sep 17 00:00:00 2001 From: Savitha Raghunathan Date: Wed, 18 Oct 2023 16:51:04 -0400 Subject: [PATCH 1/3] adding sample prompt --- examples/eap_to_quarkus/sampleprompt.py | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 examples/eap_to_quarkus/sampleprompt.py diff --git a/examples/eap_to_quarkus/sampleprompt.py b/examples/eap_to_quarkus/sampleprompt.py new file mode 100644 index 0000000..09c559e --- /dev/null +++ b/examples/eap_to_quarkus/sampleprompt.py @@ -0,0 +1,78 @@ +import os +import openai + +api_key = os.environ.get('OPENAI_API_KEY') + +if api_key is None: + raise ValueError("API key not found. Set the OPENAI_API_KEY environment variable.") + +openai.api_key = api_key + +def get_completion(prompt, model="gpt-3.5-turbo"): + messages = [{"role": "user", "content": prompt}] + response = openai.ChatCompletion.create( + model=model, + messages=messages, + temperature=0, + ) + return response.choices[0].message["content"] + +text = """You are an expert in Java EAP and Quarkus technologies. You are going to assist with modernizing EAP applications to +Quarkus 3.4.1, Jakarta EE 9, and Java 11. There are some sample scenarios provided below, + +Example 1: +Incident metdata: Stateless scoped bean + +Issue details: + +@Stateless +public class OrderService { + // ... +} + +Resolution: + +@ApplicationScoped +public class OrderService { + // ... +} + +Example 2: +Incident metdata: Stateless scoped bean + +Issue details: + +@Stateless +public class CatalogService { + // ... +} + +Resolution: + +@ApplicationScoped +public class CatalogService { + // ... +} +""" + +# Example code snippet to modernize +java_code_snippet = """ +Incident metadata: Stateless scoped bean + +Issue details: +``` +@Stateless +public class MemberRegistration { + '....' + '....' +} +``` +""" + +prompt =f""" +You have been provided with prior solved examples in #{text}. It is time to resolve a similar incident. Find a solution for the issue in #{java_code_snippet}. +Make sure it is compatible with Quarkus 3.4.1 as well as Jakarta EE 9 and Java 11. + +""" +response = get_completion(prompt) +print(response) \ No newline at end of file From d28b1f080c8a2b11742bd4c7f18e461a7d770c9c Mon Sep 17 00:00:00 2001 From: Savitha Raghunathan Date: Thu, 19 Oct 2023 14:55:59 -0400 Subject: [PATCH 2/3] incorporate langchain --- examples/eap_to_quarkus/sampleprompt.py | 41 ++++++++++++------------- requirements.txt | 3 ++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/examples/eap_to_quarkus/sampleprompt.py b/examples/eap_to_quarkus/sampleprompt.py index 09c559e..c44ff3f 100644 --- a/examples/eap_to_quarkus/sampleprompt.py +++ b/examples/eap_to_quarkus/sampleprompt.py @@ -1,23 +1,23 @@ import os +from dotenv import find_dotenv, load_dotenv +from langchain.chat_models import ChatOpenAI +from langchain.prompts import ChatPromptTemplate import openai -api_key = os.environ.get('OPENAI_API_KEY') +_ = load_dotenv(find_dotenv()) +openai.api_key = os.environ['OPENAI_API_KEY'] +chat = ChatOpenAI(temperature=0.0, model="gpt-3.5-turbo") -if api_key is None: - raise ValueError("API key not found. Set the OPENAI_API_KEY environment variable.") +temp =""" +You have been provided with prior solved examples in {text}. It is time to resolve a similar incident. Find a solution for the issue in {java_code_snippet}. +Make sure it is compatible with Quarkus 3.4.1 as well as Jakarta EE 9 and Java 11. -openai.api_key = api_key +""" -def get_completion(prompt, model="gpt-3.5-turbo"): - messages = [{"role": "user", "content": prompt}] - response = openai.ChatCompletion.create( - model=model, - messages=messages, - temperature=0, - ) - return response.choices[0].message["content"] +prompt_template = ChatPromptTemplate.from_template(temp) -text = """You are an expert in Java EAP and Quarkus technologies. You are going to assist with modernizing EAP applications to +modernize_text = """ +You are an expert in Java EAP and Quarkus technologies. You are going to assist with modernizing EAP applications to Quarkus 3.4.1, Jakarta EE 9, and Java 11. There are some sample scenarios provided below, Example 1: @@ -55,8 +55,7 @@ def get_completion(prompt, model="gpt-3.5-turbo"): } """ -# Example code snippet to modernize -java_code_snippet = """ +modernize_question=""" Incident metadata: Stateless scoped bean Issue details: @@ -69,10 +68,10 @@ def get_completion(prompt, model="gpt-3.5-turbo"): ``` """ -prompt =f""" -You have been provided with prior solved examples in #{text}. It is time to resolve a similar incident. Find a solution for the issue in #{java_code_snippet}. -Make sure it is compatible with Quarkus 3.4.1 as well as Jakarta EE 9 and Java 11. +modernize_messages = prompt_template.format_messages( + text=modernize_text, + java_code_snippet=modernize_question) -""" -response = get_completion(prompt) -print(response) \ No newline at end of file +modernize_response = chat(modernize_messages) + +print(modernize_response.content) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2ff9331..ca18a66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -76,6 +76,9 @@ nvidia-nccl-cu11==2.14.3 nvidia-nvtx-cu11==11.7.91 openai==0.27.8 openapi-schema-pydantic==1.2.4 +openapi-core==0.18.1 +openapi-schema-validator==0.6.2 +openapi-spec-validator==0.6.0 openllm==0.1.16 openlm==0.0.5 opentelemetry-api==1.17.0 From 9643d72e49afbaadd6589066616cac4d651792cc Mon Sep 17 00:00:00 2001 From: Savitha Raghunathan Date: Thu, 19 Oct 2023 17:21:37 -0400 Subject: [PATCH 3/3] adding o/p formatting --- examples/eap_to_quarkus/sampleprompt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/eap_to_quarkus/sampleprompt.py b/examples/eap_to_quarkus/sampleprompt.py index c44ff3f..dc1d252 100644 --- a/examples/eap_to_quarkus/sampleprompt.py +++ b/examples/eap_to_quarkus/sampleprompt.py @@ -12,6 +12,7 @@ You have been provided with prior solved examples in {text}. It is time to resolve a similar incident. Find a solution for the issue in {java_code_snippet}. Make sure it is compatible with Quarkus 3.4.1 as well as Jakarta EE 9 and Java 11. +Make sure the output is displayed in the diff format like github """ prompt_template = ChatPromptTemplate.from_template(temp)