mirror of
https://github.com/kennethreitz/instructor.git
synced 2026-06-05 22:50:18 +00:00
feat: anthropic system prompt clean up (#523)
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
This commit is contained in:
@@ -162,6 +162,8 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
.idea/
|
||||
|
||||
.vscode/
|
||||
|
||||
examples/citation_with_extraction/fly.toml
|
||||
my_cache_directory/
|
||||
tutorials/wandb/*
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import Any, Dict, Optional, Type, TypeVar
|
||||
from xml.dom.minidom import parseString
|
||||
from docstring_parser import parse
|
||||
from functools import wraps
|
||||
from pydantic import BaseModel, create_model
|
||||
@@ -61,8 +62,9 @@ class OpenAISchema(BaseModel): # type: ignore[misc]
|
||||
@classmethod
|
||||
@property
|
||||
def anthropic_schema(cls) -> str:
|
||||
from instructor.anthropic_utils import json_to_xml, extract_xml, xml_to_model
|
||||
return json_to_xml(cls)
|
||||
from instructor.anthropic_utils import json_to_xml
|
||||
return "\n".join(line.lstrip() for line in parseString(json_to_xml(cls)).toprettyxml().splitlines()[1:])
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_response(
|
||||
|
||||
@@ -29,7 +29,6 @@ from typing import (
|
||||
|
||||
from instructor.mode import Mode
|
||||
|
||||
|
||||
logger = logging.getLogger("instructor")
|
||||
|
||||
T_Model = TypeVar("T_Model", bound=BaseModel)
|
||||
@@ -284,8 +283,7 @@ def handle_response_model(
|
||||
elif mode == Mode.ANTHROPIC_TOOLS:
|
||||
tool_descriptions = response_model.anthropic_schema
|
||||
system_prompt = dedent(
|
||||
f"""
|
||||
In this environment you have access to a set of tools you can use to answer the user's question.
|
||||
f"""In this environment you have access to a set of tools you can use to answer the user's question.
|
||||
You may call them like this:
|
||||
<function_calls>
|
||||
<invoke>
|
||||
@@ -297,9 +295,8 @@ def handle_response_model(
|
||||
</invoke>
|
||||
</function_calls>
|
||||
|
||||
Here are the tools available:\n{tool_descriptions}
|
||||
"""
|
||||
)
|
||||
Here are the tools available:""") + tool_descriptions
|
||||
|
||||
if "system" in new_kwargs:
|
||||
new_kwargs["system"] = f"{system_prompt}\n{new_kwargs['system']}"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user