.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_claude/claude_01_judge_session.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_07_claude_claude_01_judge_session.py: Claude as the evaluator of a session ==================================== The examples of the previous sections used the offline mock judge. This one calls Claude through the Anthropic Messages API (an API key is needed, so the gallery shows the code without running it). Set the key once: * locally: ``export ANTHROPIC_API_KEY=...`` in the shell; * in Google Colab: add a secret named ``ANTHROPIC_API_KEY`` (key icon on the left) and allow the notebook to read it; :func:`easyiec.evaluators.llm.clients.get_api_key` finds it. Never paste a key into a notebook cell or a file that others may see. .. GENERATED FROM PYTHON SOURCE LINES 18-22 A cached client and a debiased judge ------------------------------------ :class:`~easyiec.evaluators.CachedClient` stores every answer on disk, so a rerun of the notebook costs nothing and gives the same results. .. GENERATED FROM PYTHON SOURCE LINES 22-36 .. code-block:: Python import easyiec as ei from easyiec.evaluators import AnthropicClient, CachedClient, LLMJudge from easyiec.problems import ImageSegmentation from easyiec.strategies import InteractiveGA problem = ImageSegmentation() client = CachedClient(AnthropicClient("claude-sonnet-5-5", effort="low"), ".easyiec_cache") judge = LLMJudge(client, problem, debias="reverse", n_views=2, image_size=224) user = ei.SimulatedUser(problem, target=None) # only as the oracle: Dice-based ground truth res = ei.run(problem, InteractiveGA(pop_size=9), judge, generations=8, seed=1, oracle=user.true_utility) print(res.summary()) # queries, items, usd, best true utility print(res.log.records[-1].feedback.rationale) # Claude's reason for its last choice .. GENERATED FROM PYTHON SOURCE LINES 37-39 Report and cost --------------- .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python ei.viz.session_report(res, "claude_segmentation.html", evaluator=judge, title="Segmentation tuned by Claude") print(client.inner.usage) # calls, tokens and estimated USD of new (uncached) calls .. _sphx_glr_download_auto_examples_07_claude_claude_01_judge_session.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/easyiec/main?urlpath=lab/tree/notebooks/auto_examples/07_claude/claude_01_judge_session.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: claude_01_judge_session.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: claude_01_judge_session.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: claude_01_judge_session.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_