-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[AI-3] Store the model catalogue and capability verdicts #24882
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
Open
tangopium
wants to merge
1
commit into
feature/66020-pr03-disconnect-and-key-removal
from
feature/66020-pr04-model-records-sync-capabilities
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| # What we know about one capability of one model on one server. | ||
| # | ||
| # Three states rather than a boolean, because the honest answer is very often | ||
| # "we cannot tell": the OpenAI model list carries no capability information at | ||
| # all, and only some servers offer a non-standard endpoint that does. | ||
| # | ||
| # The rule the rest of the system depends on: only :unsupported blocks. An | ||
| # :unknown verdict warns and lets the administrator proceed, because refusing | ||
| # on "we could not tell" would make most self-hosted servers unusable. | ||
| class LlmCapabilityVerdict < ApplicationRecord | ||
| belongs_to :llm_connection | ||
|
|
||
| enum :state, { supported: "supported", unsupported: "unsupported", unknown: "unknown" }, validate: true | ||
|
|
||
| # Where the verdict came from. Orthogonal to the state, so that an | ||
| # administrator's assertion can be shown as such without adding a fourth state | ||
| # that every caller would have to handle. | ||
| enum :source, | ||
| { metadata: "metadata", probe: "probe", admin: "admin", observed: "observed" }, | ||
| prefix: true, | ||
| validate: true | ||
|
|
||
| validates :model_id, presence: true | ||
| validates :capability, presence: true, uniqueness: { scope: %i[llm_connection_id model_id] } | ||
|
|
||
| scope :for_model, ->(model_id) { where(model_id:) } | ||
| scope :for_capability, ->(capability) { where(capability: capability.to_s) } | ||
|
|
||
| # An administrator's assertion survives re-detection: they know something about | ||
| # their deployment that we could not determine. | ||
| scope :sticky, -> { where(source: "admin") } | ||
|
|
||
| def blocking? | ||
| unsupported? | ||
| end | ||
|
|
||
| def dimensions | ||
| detail["dimensions"] | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| # A model this connection can address. | ||
| # | ||
| # Rows come from two places: discovered from the server's model list, or entered | ||
| # by an administrator. Both are addressed by +external_id+, which is whatever the | ||
| # deployment calls the model -- provider-specific and not comparable across | ||
| # vendors, which is why it is never used as a lookup key into a public catalogue. | ||
| class LlmModel < ApplicationRecord | ||
| belongs_to :llm_connection | ||
|
|
||
| validates :external_id, presence: true, uniqueness: { scope: :llm_connection_id } | ||
|
|
||
| scope :active, -> { where(active: true) } | ||
| scope :discovered, -> { where(manual: false) } | ||
| scope :manual, -> { where(manual: true) } | ||
| scope :by_identifier, -> { order(:external_id) } | ||
|
|
||
| def name = display_name.presence || external_id | ||
|
|
||
| # Precedence: what an administrator set, then what the server reported (vLLM | ||
| # and SGLang publish the operator's actual --max-model-len), then what a | ||
| # registry believes about the model in general. | ||
| def context_window | ||
| raw_metadata["admin_context_window"] || | ||
| raw_metadata["max_model_len"] || | ||
| raw_metadata["context_window"] | ||
| end | ||
|
|
||
| def context_window_source | ||
| return :admin if raw_metadata["admin_context_window"].present? | ||
| return :server if raw_metadata["max_model_len"].present? | ||
| return :registry if raw_metadata["context_window"].present? | ||
|
|
||
| nil | ||
| end | ||
|
|
||
| def verdict_for(capability) | ||
| llm_connection.capability_verdicts | ||
| .for_model(external_id) | ||
| .for_capability(capability) | ||
| .first | ||
| end | ||
|
|
||
| # Discovered models that the server stopped offering are deactivated rather | ||
| # than deleted, so a binding or verdict pointing at one still has something to | ||
| # name. Manual entries are never deactivated by a refresh: nothing confirms | ||
| # them, so nothing can un-confirm them either. | ||
| def withdrawn? = !active? && !manual? | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| module Llm | ||
| # The capabilities a model may have, and how to read the published ones. | ||
| module Capabilities | ||
| ALL = %i[embeddings function_calling structured_output vision reasoning].freeze | ||
|
|
||
| # Capabilities a chat model can be asked about. +embeddings+ is deliberately | ||
| # absent: it is a different kind of model, not a feature of a chat one. | ||
| CHAT = (ALL - %i[embeddings]).freeze | ||
| EMBEDDING = %i[embeddings].freeze | ||
|
|
||
| module_function | ||
|
|
||
| # What a public registry says about this model id. | ||
| # | ||
| # Advisory only. The registry describes a model as some vendor deploys it, | ||
| # which is not the same as this deployment: the same weights are catalogued | ||
| # with contradictory capability flags and context windows an order of | ||
| # magnitude apart across providers. Verdicts derived from it are therefore | ||
| # recorded with source "metadata", and an administrator can overrule them. | ||
| # | ||
| # @return [Hash{Symbol => Symbol}, nil] capability => :supported / :unsupported, | ||
| # or nil when the registry does not know the model -- the normal case for a | ||
| # self-hosted server. | ||
| def published_for(model_id) | ||
| info = RubyLLM.models.find(model_id) | ||
|
|
||
| { states: states_from(info), context_window: info.context_window, display_name: info.name } | ||
| rescue RubyLLM::ModelNotFoundError | ||
| nil | ||
| rescue StandardError => e | ||
| # Registry lookup is an enrichment; it must never break a model sync. | ||
| Rails.logger.info { "LLM capability lookup for #{model_id} failed: #{e.class} #{e.message}" } | ||
| nil | ||
| end | ||
|
|
||
| def states_from(info) | ||
| embedding = info.type.to_s == "embedding" | ||
| published = Array(info.capabilities).map(&:to_sym) | ||
| relevant = embedding ? EMBEDDING : CHAT | ||
|
|
||
| states = relevant.index_with { |capability| published.include?(capability) ? :supported : :unsupported } | ||
| states.merge(embeddings: embedding ? :supported : :unsupported) | ||
|
Comment on lines
+71
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we missing the edge case of |
||
| end | ||
|
|
||
| def label(capability) | ||
| I18n.t("llm.capabilities.#{capability}.label") | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.