Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/instructor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ defmodule Instructor do
* `:mode` - The mode to use when parsing the response, :tools, :json, :md_json (defaults to `:tools`), generally speaking you don't need to change this unless you are not using OpenAI.
* `:max_retries` - The maximum number of times to retry the LLM call if it fails, or does not pass validations.
(defaults to `0`)
* `:instructor_role` - The role to use in system messages. Defaults to `"system"`.
Some models, such as OpenAI's o1 series, require the role to be `"developer"`.

## Examples

Expand Down Expand Up @@ -126,6 +128,7 @@ defmodule Instructor do
params
|> Keyword.put_new(:max_retries, 0)
|> Keyword.put_new(:mode, :tools)
|> Keyword.put_new(:instructor_role, "system")

is_stream = Keyword.get(params, :stream, false)
response_model = Keyword.fetch!(params, :response_model)
Expand Down Expand Up @@ -453,7 +456,7 @@ defmodule Instructor do
reask_messages(raw_response, params, config) ++
[
%{
role: "system",
role: Keyword.get(params, :instructor_role, "system"),
content: """
The response did not pass validation. Please try again and fix the following validation errors:\n

Expand Down Expand Up @@ -513,7 +516,7 @@ defmodule Instructor do
end

sys_message = %{
role: "system",
role: Keyword.get(params, :instructor_role, "system"),
content: """
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
#{json_schema}
Expand Down
1 change: 1 addition & 0 deletions lib/instructor/adapters/anthropic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ defmodule Instructor.Adapters.Anthropic do
{_, params} = Keyword.pop(params, :response_model)
{_, params} = Keyword.pop(params, :validation_context)
{_, params} = Keyword.pop(params, :max_retries)
{_, params} = Keyword.pop(params, :instructor_role)
{mode, params} = Keyword.pop(params, :mode)
stream = Keyword.get(params, :stream, false)
params = Enum.into(params, %{})
Expand Down
1 change: 1 addition & 0 deletions lib/instructor/adapters/gemini.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ defmodule Instructor.Adapters.Gemini do
{_, params} = Keyword.pop(params, :response_model)
{_, params} = Keyword.pop(params, :validation_context)
{_, params} = Keyword.pop(params, :max_retries)
{_, params} = Keyword.pop(params, :instructor_role)
{mode, params} = Keyword.pop(params, :mode)
stream = Keyword.get(params, :stream, false)
params = Enum.into(params, %{})
Expand Down
1 change: 1 addition & 0 deletions lib/instructor/adapters/openai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Instructor.Adapters.OpenAI do
{_, params} = Keyword.pop(params, :response_model)
{_, params} = Keyword.pop(params, :validation_context)
{_, params} = Keyword.pop(params, :max_retries)
{_, params} = Keyword.pop(params, :instructor_role)
{mode, params} = Keyword.pop(params, :mode)
stream = Keyword.get(params, :stream, false)
params = Enum.into(params, %{})
Expand Down
2 changes: 1 addition & 1 deletion lib/instructor/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defmodule Instructor.Validator do
response_model: Validation,
messages: [
%{
role: "system",
role: Keyword.get(opts, :instructor_role, "system"),
content: """
You are a world class validation model. Capable to determine if the following value is valid for the statement, if it is not, explain why.
"""
Expand Down