Skip to content

Commit

Permalink
revert line-length for now
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomlam committed Apr 19, 2024
1 parent 12a2311 commit 0e930d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion 02-household-queries/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class CaptureLlmPromptHandler(BaseCallbackHandler):
def __init__(self, printToStdOut=True):
self.toStdout = printToStdOut

async def on_llm_start(self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) -> Any:
async def on_llm_start(
self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
) -> Any:
formatted_prompts = "\n".join(prompts).replace("```", "``")
if self.toStdout:
print(f"\nPROMPT:\n{formatted_prompts}")
Expand Down
24 changes: 18 additions & 6 deletions 02-household-queries/dspy_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class BasicQA(dspy.Signature):
"""Answer questions with short answers."""

question = dspy.InputField()
answer = dspy.OutputField(desc="Respond with only one of these words: Yes, No, Maybe")
answer = dspy.OutputField(
desc="Respond with only one of these words: Yes, No, Maybe"
)


def run_basic_predictor(query):
Expand Down Expand Up @@ -69,7 +71,9 @@ class GenerateAnswer(dspy.Signature):
Focus on clarity and decisiveness, being concise in conveying your evaluation while catering to the specifics of the question.
"""

context = dspy.InputField(desc="may contain relevant facts used to answer the question")
context = dspy.InputField(
desc="may contain relevant facts used to answer the question"
)
question = dspy.InputField()
answer = dspy.OutputField(
desc="Start with one of these words: Yes, No, Maybe",
Expand Down Expand Up @@ -206,7 +210,9 @@ def main_train(qa_pairs):
print("Using retrieve_k =", retrieve_k)
module: dspy.Module = RAG(retrieve_k)

filename = input("Specify compiled_module file to load optimized module or press Enter to start from scratch: ")
filename = input(
"Specify compiled_module file to load optimized module or press Enter to start from scratch: "
)
if filename:
module.load(filename)
compiled_module = module
Expand Down Expand Up @@ -237,11 +243,15 @@ def main_train(qa_pairs):
""")
if not llm_choice:
llm_choice = "openhermes"
dspy.settings.configure(lm=create_llm_model(llm_choice), rm=create_retriever_model())
dspy.settings.configure(
lm=create_llm_model(llm_choice), rm=create_retriever_model()
)

if not filename:
file_suffix = f"optimizer{optimizer_choice}_{retrieve_k}_{llm_choice}_{time.strftime('%Y-%m-%d-%H%M%S')}"
compiled_module = optimize_module(optimizer, module, training, eval_kwargs, file_suffix)
compiled_module = optimize_module(
optimizer, module, training, eval_kwargs, file_suffix
)
print_optimization(compiled_module)

evaluate_module(compiled_module, eval_metric, training)
Expand Down Expand Up @@ -335,7 +345,9 @@ def optimize_module(optimizer, module, training, eval_kwargs, file_suffix):
print("----- optimizing ------------------")
if eval_kwargs:
# COPRO requires eval_kwargs whereas other optimizers don't
compiled_module = optimizer.compile(module, trainset=training, eval_kwargs=eval_kwargs)
compiled_module = optimizer.compile(
module, trainset=training, eval_kwargs=eval_kwargs
)
else:
compiled_module = optimizer.compile(module, trainset=training)
compiled_module.save(f"compiled_module-{file_suffix}.json")
Expand Down
3 changes: 1 addition & 2 deletions 02-household-queries/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[tool.ruff]
# Allow lines to be as long as 120.
line-length = 120
# line-length = 120

0 comments on commit 0e930d7

Please sign in to comment.