add docstring comment

This commit is contained in:
David Westgate 2024-05-09 13:57:17 -07:00
parent 6d0373c92b
commit f87ee5cc15

View File

@ -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