|
|
This page contains documentation for the main files used to run MARCO
|
|
|
|
|
|
<details><summary>agent.py</summary>
|
|
|
<p>
|
|
|
This is the main file used to run MARCO. It contains the specifications for MARCO’s UI, and is also where the functions used to optimize code are called.
|
|
|
|
|
|
Lines 1-5 import the required packages and files. streamlit is the framework used to build MARCO’s frontend. agent_functions contains the functions that concern interacting with the LLM. asyncio is a Python library that allows for concurrent programming, allowing process_optimization() to wait for input from functions in agent_functions. base64 was used for encoding a background image and is no longer used in the file. time is used in the typewriter_effect_code function to simulate dynamic text output.
|
|
|
|
|
|
Lines 8-83 set the formatting for MARCO’s webpage using the markdown() function from streamlit.
|
|
|
|
|
|
Lines 85-92 define create_error_message(), which creates error messages as needed.
|
|
|
|
|
|
Lines 95-102 define typewriter_effect_code(), which allows the text to output as if it is being typed one letter at a time, instead of all at once.
|
|
|
|
|
|
Lines 105-106 initialize the session.
|
|
|
|
|
|
Lines 109-114 control the layout of the main content area (i.e., the title, the textbox for the code, and the controls for selecting the LLM and number of techniques used)
|
|
|
|
|
|
Lines 116-144 define the process_optimization(), which gets the optimization techniques/optimized code using functions in agent_functions.py and outputs them (along with the unoptimized code imputed by the user, for comparison purposes.
|
|
|
|
|
|
Lines 146-150 govern what happens when the user presses the “Improve Code” button. If there is code in the textbox, process_optimization() is called to start the optimization process. Otherwise, a warning message is outputted asking the user to input code.
|
|
|
</p>
|
|
|
</details>
|
|
|
|
|
|
<details><summary>agent_functions.py</summary>
|
|
|
<p>
|
|
|
This file contains the functions that require direct interaction with the LLM. These functions are called within process_optimization() in agent.py.
|
|
|
|
|
|
Lines 1-7 import the required packages. The primary framework used is LangChain, allowing us to power MARCO with models developed by OpenAI. Most of the other imports deal with file access.
|
|
|
|
|
|
Line 9 gets necessary variables from the .env environment file, such as the API keys used for accessing the model.
|
|
|
|
|
|
Line 10 initializes llm, the variable that will be used the LLM.
|
|
|
|
|
|
Lines 13-20 define the select_model() function, which takes the model selected by the user and uses it to set llm. This function also sets llm as a global variable.
|
|
|
|
|
|
Lines 22-45 define the get_optimization_techniques() function. This function asks the model for a list of optimization techniques (with the exact number of techniques set by the user), and does some formatting before returning the list of techniques.
|
|
|
|
|
|
Lines 47-58 define the get_subsets() function. This was previously used in formatting the list of optimization techniques, but is now unused.
|
|
|
|
|
|
Lines 60-77 define the improve_code() function. This function asks the model to optimize the code using the previously generated optimization techniques, and returns the user’s imputed code optimized using each technique.
|
|
|
</p>
|
|
|
</details> |
|
|
\ No newline at end of file |