Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying the role used for "system" messages #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -32,6 +32,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 @@ -124,6 +126,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 @@ -451,7 +454,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 @@ -511,7 +514,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
2 changes: 1 addition & 1 deletion lib/instructor/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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