Use structured outputs with Pydantic models instead of text parsing
This commit is contained in:
38
main.py
38
main.py
@@ -1,16 +1,21 @@
|
||||
from claude_dspy import ClaudeCode, ClaudeCodeConfig
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from modaic import AutoProgram
|
||||
import dspy
|
||||
|
||||
|
||||
class Output(BaseModel):
|
||||
files: list[str]
|
||||
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):
|
||||
message: str = dspy.InputField(desc="Request to process")
|
||||
output: Output = dspy.OutputField(desc="List of files modified or created")
|
||||
log_file: str = dspy.InputField(desc="Log file to process")
|
||||
output: list[ErrorReport] = dspy.OutputField(desc="list of error reports created")
|
||||
|
||||
|
||||
def main():
|
||||
@@ -23,25 +28,32 @@ def main():
|
||||
signature=ClaudeCodeSignature,
|
||||
working_directory=".",
|
||||
permission_mode="acceptEdits",
|
||||
allowed_tools=["Read", "Bash", "Write"],
|
||||
allowed_tools=["Read", "Write", "Bash"],
|
||||
)
|
||||
|
||||
cc.push_to_hub(
|
||||
"farouk1/claude-code",
|
||||
with_code=True,
|
||||
commit_message="Add more functionality to signature description parsing",
|
||||
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"])
|
||||
|
||||
# Test the agent
|
||||
result = cc(message="create a python program that prints 'Hello, World!' and save it to a file in this directory")
|
||||
print(result.output.files)
|
||||
print(result.output)
|
||||
print(result.usage)
|
||||
"""
|
||||
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__":
|
||||
|
||||
Reference in New Issue
Block a user