Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in java.data by
recategorized ago by

Trying to run make-chat-model

(ns problem.problem
  (:require [clojure.java.data.builder :as builder])
  (:import (dev.langchain4j.model.openai OpenAiChatModel)
           (dev.langchain4j.model.openai OpenAiChatModel$OpenAiChatModelBuilder)))

(defn make-chat-model []
  (builder/to-java
    OpenAiChatModel 
    OpenAiChatModel$OpenAiChatModelBuilder
    (OpenAiChatModel/builder)
    {:baseUrl  "localhost"
     :apiKey (System/getenv "OPENAI_API_KEY")} {}))

fails with the following error

:#error {}
 :cause Duplicate setter found for :modelName in dev.langchain4j.model.openai.OpenAiChatModel$OpenAiChatModelBuilder class
 :via
 [{:type java.lang.IllegalArgumentException
   :message Duplicate setter found for :modelName in dev.langchain4j.model.openai.OpenAiChatModel$OpenAiChatModelBuilder class
   :at [clojure.java.data.builder$find_setters$fn__9041 invoke builder.clj 66]}]

The code is in the following repo: https://github.com/gavlooth/problem

2 Answers

+2 votes
ago by

Since modelName is not supplied as a property, in this case it could just ignore that setter altogether -- so I consider that one bug (java.data will fail if there are overloaded setters that you don't care about).

In the case where you are trying to build with a property that is overloaded, java.data would have to perform some sort of overload resolution to try to pick a "best match" which would be fairly complex.

What it could do is pick one setter for which instance? is true of the parameter type and the property value -- and complain if more than one setter satisfies that. That would still be somewhat overprescriptive but it would be less restrictive than the status quo.

See https://clojure.atlassian.net/issues/JDATA-24 and https://clojure.atlassian.net/issues/JDATA-25

ago by
OK, a fix for these two issue has been released in org.clojure/java.data {:mvn/version "1.3.113"}
0 votes
ago by

That setter is overloaded - what should it do? Just call it reflectively?

Why not just call this directly with interop?

...