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

Error: 1st argument is not an atom #89

Closed
camfeghali opened this issue Dec 18, 2024 · 6 comments
Closed

Error: 1st argument is not an atom #89

camfeghali opened this issue Dec 18, 2024 · 6 comments

Comments

@camfeghali
Copy link

I'm running into this error still unfortunately:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an atom

    :erlang.function_exported({:parameterized, {Ecto.Embedded, %Ecto.Embedded{cardinality: :many, field: :ingredients, owner: Wfdex.Recipes.GeneratedRecipe, related: Wfdex.Recipes.GeneratedRecipe.Ingredient, on_cast: nil, on_replace: :raise, unique: true, ordered: true}}}, :to_json_schema, 0)

My dependency versions are:

      {:phoenix_ecto, "~> 4.5"},
      {:ecto_sql, "~> 3.12"},
      {:postgrex, ">= 0.0.0"}
      {:instructor, "~> 0.0.5"},

Any help would be much appreciated!

@Ivor
Copy link

Ivor commented Dec 19, 2024

I am not familiar with the response for ecto_schema.__schema__(:embeds) but looking at the code it seems the expected value is

{:parameterized, Ecto.Embedded, %Ecto.Embedded{related: related}}

but as can be seen in the error message above, what we're getting is

{:parameterized, {Ecto.Embedded, %Ecto.Embedded{related: related}}}

I am not in a position to verify this now but I suspect that there may have been a change in what Ecto returns?

@dankentfield
Copy link

dankentfield commented Dec 20, 2024

I am getting the same, I managed to create a workaround using normal schemas

defmodule App.OpenAI.Instructors.TestCase do
  use Ecto.Schema

  schema "test_case" do
    field :input, :string
    field :expected_output, :string
  end
end

defmodule App.OpenAI.Instructors.TestCases do
  use Ecto.Schema
  
  schema "response" do
    has_many :test_cases, App.OpenAI.Instructors.TestCase
  end
end

@admiralakber
Copy link

Hi there,

First and foremost, I am new to Elixir so please excuse any stupidity. I am also getting this error when running the Politician example.

I tried changing to a "normal" schema:

defmodule Politician do
  use Ecto.Schema
  use Instructor.Validator
  
  schema "politician" do
    field :first_name, :string
    field :last_name, :string
    has_many :offices_held, Politician.Office
    end
end

defmodule Politician.Office do
  use Ecto.Schema
  use Instructor.Validator
  schema "office" do
    field :office, Ecto.Enum, values: [:president, :vice_president, :governor, :consgress, :senate]
    field :from_date, :date
    field :to_date, :date
  end
end

Then running:

Instructor.chat_completion(
  model: "gpt-3.5-turbo",
  response_model: Politician,
  messages: [
    %{
      role: "user",
      content:
        "Who won the American 2020 election and what offices have they held over their career?"
    }
  ]
)

Returns:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an atom

    (erts 13.2.2.11) :erlang.function_exported({:parameterized, {Ecto.Enum, %{embed_as: :self, mappings: [president: "president", vice_president: "vice_president", governor: "governor", consgress: "consgress", senate: "senate"], on_cast: %{"consgress" => :consgress, "governor" => :governor, "president" => :president, "senate" => :senate, "vice_president" => :vice_president}, on_dump: %{consgress: "consgress", governor: "governor", president: "president", senate: "senate", vice_president: "vice_president"}, on_load: %{"consgress" => :consgress, "governor" => :governor, "president" => :president, "senate" => :senate, "vice_president" => :vice_president}, type: :string}}}, :to_json_schema, 0)
    (instructor 0.0.5) lib/instructor/json_schema.ex:292: Instructor.JSONSchema.for_type/1
    (instructor 0.0.5) lib/instructor/json_schema.ex:79: anonymous fn/2 in Instructor.JSONSchema.bfs_from_ecto_schema/2
    (elixir 1.17.3) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.17.3) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (instructor 0.0.5) lib/instructor/json_schema.ex:77: Instructor.JSONSchema.bfs_from_ecto_schema/2
    (instructor 0.0.5) lib/instructor/json_schema.ex:138: Instructor.JSONSchema.bfs_from_ecto_schema/2
    #cell:ftaif47ga2kfoxit:1: (file)

@admiralakber
Copy link

I can confirm this is fixed on the main branch:

{:instructor, git: "https://github.com/thmsmlr/instructor_ex.git", branch: "main"}

I suppose this is linked to Issues #25 - however, this fix does bring up issue #88

Hi there,

First and foremost, I am new to Elixir so please excuse any stupidity. I am also getting this error when running the Politician example.

I tried changing to a "normal" schema:

defmodule Politician do
use Ecto.Schema
use Instructor.Validator

schema "politician" do
field :first_name, :string
field :last_name, :string
has_many :offices_held, Politician.Office
end
end

defmodule Politician.Office do
use Ecto.Schema
use Instructor.Validator
schema "office" do
field :office, Ecto.Enum, values: [:president, :vice_president, :governor, :consgress, :senate]
field :from_date, :date
field :to_date, :date
end
end
Then running:

Instructor.chat_completion(
model: "gpt-3.5-turbo",
response_model: Politician,
messages: [
%{
role: "user",
content:
"Who won the American 2020 election and what offices have they held over their career?"
}
]
)
Returns:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an atom

    (erts 13.2.2.11) :erlang.function_exported({:parameterized, {Ecto.Enum, %{embed_as: :self, mappings: [president: "president", vice_president: "vice_president", governor: "governor", consgress: "consgress", senate: "senate"], on_cast: %{"consgress" => :consgress, "governor" => :governor, "president" => :president, "senate" => :senate, "vice_president" => :vice_president}, on_dump: %{consgress: "consgress", governor: "governor", president: "president", senate: "senate", vice_president: "vice_president"}, on_load: %{"consgress" => :consgress, "governor" => :governor, "president" => :president, "senate" => :senate, "vice_president" => :vice_president}, type: :string}}}, :to_json_schema, 0)
    (instructor 0.0.5) lib/instructor/json_schema.ex:292: Instructor.JSONSchema.for_type/1
    (instructor 0.0.5) lib/instructor/json_schema.ex:79: anonymous fn/2 in Instructor.JSONSchema.bfs_from_ecto_schema/2
    (elixir 1.17.3) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.17.3) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (instructor 0.0.5) lib/instructor/json_schema.ex:77: Instructor.JSONSchema.bfs_from_ecto_schema/2
    (instructor 0.0.5) lib/instructor/json_schema.ex:138: Instructor.JSONSchema.bfs_from_ecto_schema/2
    #cell:ftaif47ga2kfoxit:1: (file)

@dankentfield
Copy link

Can confirm this has been fixed on main for me 👍🏻

@thmsmlr
Copy link
Owner

thmsmlr commented Feb 9, 2025

Solved in the latest release, {:instructor, "~> 0.1.0"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants