This Eval checks the correctness and readability of the code from a code generation process. The template variables are:
query: The query is the coding question being asked
code: The code is the code that was returned.
Code Generation Eval Template
You are a stern but practical senior software engineer who cares a lot about simplicity and
readability of code. Can you review the following code that was written by another engineer?
Focus on readability of the code. Respond with "readable" if you think the code is readable,
or "unreadable" if the code is unreadable or needlessly complex for what it's trying
to accomplish.
ONLY respond with "readable" or "unreadable"
Task Assignment:
```
{query}
```
Implementation to Evaluate:
```
{code}
```
We are continually iterating our templates, view the most up-to-date template on GitHub. Last updated on 10/12/2023
Benchmark Results
GPT-4 Results
GPT-3.5 Results
GPT-4 Turbo
How To Run the Eval
from phoenix.evals import ( CODE_READABILITY_PROMPT_RAILS_MAP, CODE_READABILITY_PROMPT_TEMPLATE, OpenAIModel, download_benchmark_dataset, llm_classify,)model =OpenAIModel( model_name="gpt-4", temperature=0.0,)#The rails is used to hold the output to specific values based on the template#It will remove text such as ",,," or "..."#Will ensure the binary value expected from the template is returned rails =list(CODE_READABILITY_PROMPT_RAILS_MAP.values())readability_classifications =llm_classify( dataframe=df, template=CODE_READABILITY_PROMPT_TEMPLATE, model=model, rails=rails, provide_explanation=True, #optional to generate explanations for the value produced by the eval LLM)
The above shows how to use the code readability template.