API Usage

Basic API Usage

You can use the Dynamic Ledger programmatically via the LanguageModel class.

Dynamic Ledger

from dynamic_cheatsheet.language_model import LanguageModel

model = LanguageModel(model_name="openai/gpt-4o")

with open("prompts/generator_prompt_dynamic_ledger.txt") as f:
    generator_prompt = f.read()
with open("prompts/curator_prompt_dynamic_ledger.txt") as f:
    curator_prompt = f.read()

results = model.advanced_generate(
    approach_name="DynamicCheatsheet_DynamicLedger",
    input_txt="<your question>",
    cheatsheet="(empty)",
    generator_template=generator_prompt,
    cheatsheet_template=curator_prompt,
    retrieve_top_k=3,
)

print(results["final_answer"])     # extracted answer
print(results["final_cheatsheet"]) # updated ledger (JSON)

Return Values

The advanced_generate method returns a dictionary with:

KeyDescription
final_answerThe model's extracted answer
final_outputThe full model output text
final_cheatsheetThe updated memory store (JSON for Dynamic Ledger)
stepsList of step details including operations applied
memory_store_sizeNumber of entries in the store (Dynamic Ledger only)
memory_store_textHuman-readable summary of strategies (Dynamic Ledger only)

Iterating Over Problems

To accumulate strategies across a sequence of problems, pass the returned final_cheatsheet back as the cheatsheet argument for the next call:

cheatsheet = "(empty)"

for question in questions:
    results = model.advanced_generate(
        approach_name="DynamicCheatsheet_DynamicLedger",
        input_txt=question,
        cheatsheet=cheatsheet,
        generator_template=generator_prompt,
        cheatsheet_template=curator_prompt,
        retrieve_top_k=3,
    )
    cheatsheet = results["final_cheatsheet"]
    print(results["final_answer"])