diff --git a/lib/instructor.ex b/lib/instructor.ex index 70178e9..e216327 100644 --- a/lib/instructor.ex +++ b/lib/instructor.ex @@ -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 @@ -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) @@ -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 @@ -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} diff --git a/lib/instructor/adapters/anthropic.ex b/lib/instructor/adapters/anthropic.ex index 74191e9..115a82c 100644 --- a/lib/instructor/adapters/anthropic.ex +++ b/lib/instructor/adapters/anthropic.ex @@ -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, %{}) diff --git a/lib/instructor/adapters/gemini.ex b/lib/instructor/adapters/gemini.ex index 66dc933..9c6ed66 100644 --- a/lib/instructor/adapters/gemini.ex +++ b/lib/instructor/adapters/gemini.ex @@ -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, %{}) diff --git a/lib/instructor/adapters/openai.ex b/lib/instructor/adapters/openai.ex index c4db50c..f0e4c44 100644 --- a/lib/instructor/adapters/openai.ex +++ b/lib/instructor/adapters/openai.ex @@ -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, %{}) diff --git a/lib/instructor/validator.ex b/lib/instructor/validator.ex index c81b96b..8cade6a 100644 --- a/lib/instructor/validator.ex +++ b/lib/instructor/validator.ex @@ -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. """