From ed2a70254a71f67785828a8bb057acb5d73d01ba Mon Sep 17 00:00:00 2001 From: Tim Asp <707699+timothyasp@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:07:24 -0800 Subject: [PATCH] fix: dedent json system prompt (#465) --- instructor/patch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instructor/patch.py b/instructor/patch.py index 63e85dfb5..5ce705063 100644 --- a/instructor/patch.py +++ b/instructor/patch.py @@ -1,6 +1,7 @@ import inspect import json import logging +from textwrap import dedent from collections.abc import Iterable from functools import wraps from tenacity import Retrying, AsyncRetrying, stop_after_attempt, RetryError @@ -133,11 +134,11 @@ def handle_response_model( elif mode in {Mode.JSON, Mode.MD_JSON, Mode.JSON_SCHEMA}: # If its a JSON Mode we need to massage the prompt a bit # in order to get the response we want in a json format - message = f""" + message = dedent(f""" As a genius expert, your task is to understand the content and provide the parsed objects in json that match the following json_schema:\n {response_model.model_json_schema()['properties']} - """ + """) # Check for nested models if "$defs" in response_model.model_json_schema(): message += f"\nHere are some more definitions to adhere too:\n{response_model.model_json_schema()['$defs']}"