From f87ee5cc1594648ddf37d720350c6597bb318908 Mon Sep 17 00:00:00 2001 From: David Westgate Date: Thu, 9 May 2024 13:57:17 -0700 Subject: [PATCH] add docstring comment --- hw4/app.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw4/app.py b/hw4/app.py index e391479..7280d4f 100644 --- a/hw4/app.py +++ b/hw4/app.py @@ -1,4 +1,4 @@ -# derived from https://github.com/wu4f/cs410g-src/blob/main/05_CodeSummarize/01_python_parser.py + from langchain_community.document_loaders.generic import GenericLoader from langchain_community.document_loaders.parsers import LanguageParser from langchain_openai import ChatOpenAI @@ -14,6 +14,14 @@ load_dotenv() llm = ChatOpenAI(model_name="gpt-4-turbo", temperature=0) +""" +Per the prompt below, This agent will de-obfuscate javascript source files, from either the web or a local source, and will apply appropriate commenting and formatting. +A summary of actions taken will be provided, or a reason for rejection will be provided. +An elapsed time will also be shown. + +derived from https://github.com/wu4f/cs410g-src/blob/main/05_CodeSummarize/01_python_parser.py +""" + def deobfuscate(path: str): if url(path): @@ -26,7 +34,7 @@ def deobfuscate(path: str): parser=LanguageParser(), ) docs = loader.load() - prompt1 = PromptTemplate.from_template( + prompt = PromptTemplate.from_template( """You are an expert javascript de-obfuscater. Carefully analyze the following code and de-obduscate, by applying proper formatting, commenting, and re-naming as necessary. Along with this response, make a note of the changes made. If the input is anything other than obfuscated javascript, respond with "Invalid Input:" follwed by the reason why. @@ -35,7 +43,7 @@ def deobfuscate(path: str): """ ) - chain = {"text": RunnablePassthrough()} | prompt1 | llm | StrOutputParser() + chain = {"text": RunnablePassthrough()} | prompt | llm | StrOutputParser() output = "\n".join([d.page_content for d in docs]) result = chain.invoke(output) return result @@ -53,7 +61,7 @@ while True: result: str = deobfuscate(line) end_time = time() elapsed_time = round(end_time - start_time, 2) - print("\n",result,"\n\nElapsed time: ", elapsed_time, " seconds") + print("\n", result, "\n\nElapsed time: ", elapsed_time, " seconds") else: break except Exception as e: