Skip to content

AI Language Style Review

The lab: check EN style submenu (src/resultsLanguageStyleReview/) is an experimental feature that runs the English wording of audit findings through an LLM and lets the auditor accept, ignore, or flag each suggestion.

How it works

  1. Review results (reviewLanguageStyle) copies the featured rows of the Results tab into a scratch tab named En Style Review, sends each issue title and details field to the OpenAI Chat Completions API, and writes the AI's rewrite next to the original.
  2. The reviewer picks Apply, Ignore, or Report Problem per suggestion from a dropdown.
  3. Apply changes (applySuggestionsToAuditTab) writes the approved text back into the Results tab and highlights the changed cells. Report Problem rows must include an explanation, or the run is blocked and the offending cells are highlighted.
  4. Every reviewed title decision (with the prompt used and the reviewer's email) is appended to a central logging spreadsheet, which also maintains per-prompt Apply/Ignore/Problem counters so prompt quality can be compared over time.

External API usage

fetchResponseFromRemoteModel calls https://api.openai.com/v1/chat/completions via UrlFetchApp.fetch with model gpt-4. The API key is read from Apps Script Script Properties under aiAPIKey. API errors surface as the literal cell text ERROR: <message>. A debug flag (isDebugStubsReturnedFromRemoteAiModel) short-circuits all calls with canned stubs for offline development.

Each title and each details value is a separate HTTP request, so a large featured set can approach the Apps Script execution-time limit.

Prompts

Prompts are not in code. They live in a catalog spreadsheet (tab PromptStats), looked up by id; the title prompt is id 1. The details prompt is (deprecated) read from a cell on the review tab itself. The placeholder {{subject}} in a prompt template is replaced with the text being reviewed.

Review tab layout

Header row 5, data from row 6. Columns: id, title, aiTitle, titleAction, titleProblem, (spacer), details, aiDetails, detailsAction, detailsProblem. The action columns get an Apply | Ignore | Report Problem dropdown. On the Results tab, ids are read from column B, titles from G, details from H.

aiReview.ts

Function Description Facing
reviewLanguageStyle() Menu action "Review results" (see workflow above). User-facing (menu)
applySuggestionsToAuditTab() Menu action "Apply changes" (see workflow above). Shows a UI error if nothing is marked Apply. User-facing (menu)
writeToAuditTabAndGetIdToRowNumberMap(...) Substitutes the approved values by issue id in one batched write and returns an id-to-row map. Internal
activateModifiedCellsOnAudit(...) Selects the cells that were just overwritten so the change is visible. Internal
getMissingProblemFeedback(entries) Returns the cells where a reviewer chose Report Problem but left the explanation blank. Internal
createReviewTab(sheetId, afterTab) Inserts the En Style Review tab and seeds the deprecated details-prompt cell. Internal
suggest(reviewTab) Loads the prompts, fetches AI rewrites for every row, writes them into the AI columns, and formats the tab. Internal
copyAuditEntriesToReviewTab_({auditTab, reviewTab}) Copies the featured issues (id, title, details) into the review tab and attaches the decision dropdowns. Internal
fetchAiSuggestionsForSubjects(promptTemplate, subjects) Renders the template per subject (replacing {{subject}}) and returns one model response per subject, or stubs in debug mode. Internal
fetchResponseFromRemoteModel(prompt) Performs the OpenAI POST and returns the assistant message text, No response, or ERROR: .... Internal
getAiAPIKey() Reads the aiAPIKey Script Property; logs an error when absent. Internal
logReviewedTitleSuggestion(entries, reviewTab) Builds a log DTO for every row with a title decision and hands them to addToReviewStatsSheet. Internal
formatReviewTab(entries, tab) / formatModelResponse(original) Formatting helpers. Internal

promptListAndStats.ts

Function Description
getPromptById(promptId) Looks up a prompt's text in the PromptStats tab by id; shows a UI error with a link to the catalog and throws when not found.
updatePromptStats(logTab) Recomputes per-prompt Apply/Ignore/Problem counters from the log entries and writes them back onto each prompt row.

logReviewEntry.ts

Function Description
addToReviewStatsSheet(entries) Appends one row per reviewed suggestion to the Logs tab of the shared stats spreadsheet: timestamp (New York time), original text, suggestion, decision, problem description, prompt id and text, reviewer email, a hyperlink back to the source tab, and the issue id. Then reformats the tab and triggers updatePromptStats.

Inactive: v3/OpenAi.js

getWhyItMattersFromOpenAi(issueDetails, successCriteria) is an experimental function that would draft the "Why it matters" narrative for an issue via a forced OpenAI tool call. Its only call site (in the third-party bug report) is commented out and its auth header is empty, so it cannot run as committed.