Skip to content

Commit bfd5e48

Browse files
committed
Allow specifying the role used for "system" messages
1 parent 2c89b1c commit bfd5e48

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/instructor.ex

+5-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ defmodule Instructor do
3434
* `: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.
3535
* `:max_retries` - The maximum number of times to retry the LLM call if it fails, or does not pass validations.
3636
(defaults to `0`)
37+
* `:instructor_role` - The role to use in system messages. Defaults to `"system"`.
38+
Some models, such as OpenAI's o1 series, require the role to be `"developer"`.
3739
3840
## Examples
3941
@@ -126,6 +128,7 @@ defmodule Instructor do
126128
params
127129
|> Keyword.put_new(:max_retries, 0)
128130
|> Keyword.put_new(:mode, :tools)
131+
|> Keyword.put_new(:instructor_role, "system")
129132

130133
is_stream = Keyword.get(params, :stream, false)
131134
response_model = Keyword.fetch!(params, :response_model)
@@ -453,7 +456,7 @@ defmodule Instructor do
453456
reask_messages(raw_response, params, config) ++
454457
[
455458
%{
456-
role: "system",
459+
role: Keyword.get(params, :instructor_role, "system"),
457460
content: """
458461
The response did not pass validation. Please try again and fix the following validation errors:\n
459462
@@ -513,7 +516,7 @@ defmodule Instructor do
513516
end
514517

515518
sys_message = %{
516-
role: "system",
519+
role: Keyword.get(params, :instructor_role, "system"),
517520
content: """
518521
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
519522
#{json_schema}

lib/instructor/validator.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ defmodule Instructor.Validator do
104104
response_model: Validation,
105105
messages: [
106106
%{
107-
role: "system",
107+
role: Keyword.get(opts, :instructor_role, "system"),
108108
content: """
109109
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.
110110
"""

0 commit comments

Comments
 (0)