Add line content field to CodeExample and enhance examples description; implement log summary generation in CLI

This commit is contained in:
gagb 2025-03-19 16:04:57 -07:00
parent 7eb13a28a1
commit a3a2f43234
2 changed files with 24 additions and 1 deletions

View File

@ -21,6 +21,9 @@ class CodeExample(BaseModel):
reason: str = Field(
..., description="A two sentence, human-readable explanation why this example and lines relate to the code."
)
line_content: str = Field(
..., description="The exact content of the line where the error is found. This should be a single line."
)
line: int = Field(..., description="The most important line number where a human would say the error is.")
line_end: int = Field(..., description="Line number where the issue ends.")
@ -28,7 +31,9 @@ class CodeExample(BaseModel):
class Code(BaseModel):
name: str = Field(..., description="Normalized unique name for the code (lowercase, hyphen separated).")
definition: str = Field(..., description="Definition of the code.")
examples: List[CodeExample] = Field(..., description="List of code examples associated with the code.")
examples: List[CodeExample] = Field(
..., description="List of code examples associated with the code. Cannot be empty."
)
severity: int = Field(
..., description="Severity rating of the error identified using the code. Valid values: 0, 1, 2."
)

View File

@ -1,6 +1,7 @@
import os
import argparse
from typing import List, Sequence, Optional
from openai import OpenAI
from ._base import Document, CodedDocument
from .coders.oai_coder import OAIQualitativeCoder
@ -56,11 +57,28 @@ def print_coded_results(input_path: str, coded_doc: CodedDocument) -> None:
print("\n")
def get_log_summary(input_path: str) -> str:
"""
Generate a single sentence of summary for the given log file.
"""
client = OpenAI()
text = load_log_file(input_path, prepend_numbers=False).text
response = client.responses.create(
model="gpt-4o",
input=f"Summarize the following log file in one sentence.\n{text}",
)
return response.output_text
def code_command(input_path: str) -> None:
"""
Process the given input path by coding log files.
"""
if os.path.isfile(input_path):
print(f"Processing file: {input_path}")
print(get_log_summary(input_path))
coded_doc = code_log(input_path)
if coded_doc is None:
raise ValueError("Failed to code the document.")