61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from claude_dspy import ClaudeCode, ClaudeCodeConfig
|
|
from pydantic import BaseModel, Field
|
|
from modaic import AutoProgram
|
|
import dspy
|
|
|
|
|
|
class ErrorReport(BaseModel):
|
|
error: str = Field(..., description="Error message")
|
|
timestamp: str = Field(..., description="Timestamp of error")
|
|
line_located: int | None = Field(..., description="Line number where error occurred")
|
|
file_located: str | None = Field(..., description="File where error occurred")
|
|
description: str = Field(..., description="Description of errors")
|
|
reccomedated_fixes: list[str] = Field(..., description="List of recommended fixes")
|
|
|
|
|
|
class ClaudeCodeSignature(dspy.Signature):
|
|
log_file: str = dspy.InputField(desc="Log file to process")
|
|
output: list[ErrorReport] = dspy.OutputField(desc="list of error reports created")
|
|
|
|
|
|
def main():
|
|
# create config
|
|
config = ClaudeCodeConfig()
|
|
|
|
# create agent
|
|
cc = ClaudeCode(
|
|
config,
|
|
signature=ClaudeCodeSignature,
|
|
working_directory=".",
|
|
permission_mode="acceptEdits",
|
|
allowed_tools=["Read", "Write", "Bash"],
|
|
)
|
|
|
|
cc.push_to_hub(
|
|
"farouk1/claude-code",
|
|
with_code=True,
|
|
commit_message="Use structured outputs with Pydantic models instead of text parsing",
|
|
)
|
|
|
|
# agent = AutoProgram.from_precompiled("farouk1/claude-code", signature=ClaudeCodeSignature, working_directory=".", permission_mode="acceptEdits", allowed_tools=["Read", "Write", "Bash"])
|
|
"""
|
|
print("Running Claude Code...")
|
|
result = cc(log_file="log.txt")
|
|
print("Claude Code finished running!")
|
|
print("-" * 50)
|
|
print("Output: ", result.output)
|
|
print("Output type: ", type(result.output))
|
|
print("Usage: ", result.usage)
|
|
print("Output type: ", type(result.output))
|
|
print("-" * 50)
|
|
|
|
print()
|
|
print("Trace:")
|
|
for i, item in enumerate(result.trace):
|
|
print(f" {i}: {item}")
|
|
"""
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|