Amministratore -> Personalizza -> Testo che si comporta male

Sto riscontrando problemi simili quando tento di filtrare i prompt del mio chatbot.

La parte davvero strana è che il comportamento può essere corretto su un’installazione ma non su un’altra.

Prendi il filtro molto semplice di chatbot.prompt su Admin → Personalizza → Testo:

Installazione funzionante:

Installazione non funzionante:

NoMethodError (undefined method `scan' for {:basic=>"You are a helpful assistant.", :agent=>"You are a helpful assistant. You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with. The current date and time is %{current_date_time}. Only respond to the last question, using the prior information as context, if appropriate."}:Hash)
lib/i18n/i18n_interpolation_keys_finder.rb:6:in `find'
app/controllers/admin/site_texts_controller.rb:183:in `record_for'
app/controllers/admin/site_texts_controller.rb:249:in `block in find_translations'
app/controllers/admin/site_texts_controller.rb:234:in `each'
app/controllers/admin/site_texts_controller.rb:234:in `find_translations'
app/controllers/admin/site_texts_controller.rb:34:in `index'
app/controllers/application_controller.rb:422:in `block in with_resolved_locale'
app/controllers/application_controller.rb:422:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:64:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:389:in `call'
lib/middleware/gtm_script_nonce_injector.rb:10:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:233:in `call'

Il file locale in questione è questo:

Sto facendo qualcosa di illegale?

3 Mi Piace

ok

sembra che il metodo in questione si aspetti del testo:

ma in qualche modo riceve un Hash:

irb(main):001:0> item = {:basic=>"You are a helpful assistant.", :agent=>"You are a helpful assistant.  You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with.  The current date and time is %{current_date_time}.  Only respond to the last question, using the prior information as context, if appropriate."}
=>
{:basic=>"You are a helpful assistant.", :agent=>
  "You are a helpful assistant.  You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with.  The current date and time is %{current_date_time}.  Only respond to the last question, using the prior information as context, if appropriate."}
irb(main):002:0> item
=>
{:basic=>"You are a helpful assistant.",
 :agent=>
  "You are a helpful assistant.  You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with.  The current date and time is %{current_date_time}.  Only respond to the last question, using the prior information as context, if appropriate."}
irb(main):003:0> item.scan
(irb):3:in `<main>': undefined method `scan' for {:basic=>"You are a helpful assistant.", :agent=>"You are a helpful assistant.  You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with.  The current date and time is %{current_date_time}.  Only respond to the last question, using the prior information as context, if appropriate."}:Hash (NoMethodError)
        from /home/robert/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /home/robert/.rbenv/versions/3.2.1/bin/irb:25:in `load'
        from /home/robert/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'
irb(main):004:0

Causando il suo blocco… Continuerò l’indagine

Viene chiamato da qui, credo:

Posso riprodurre il problema con:

I18nInterpolationKeysFinder.find(I18n.overrides_disabled { I18n.t("chatbot.prompt.system.", locale: :en) })
dalla console rails.

Penso che questa riga dovrebbe impedire al metodo di ricevere un Hash, ma non funziona, perché?:

1 Mi Piace

Spostando questo in Bug, perché penso che questo comportamento sia errato e per qualche motivo inaffidabile.

Secondo il codice, se il valore è un Hash, non dovrebbe essere inviato al metodo record_for (dove causerebbe un’eccezione poiché si aspetta del testo), ma in alcuni casi lo è.

Sono felice di essere corretto.

1 Mi Piace

Questo si verifica quando esiste una sovrascrittura di traduzione per una chiave che in precedenza era una stringa traducibile, ma che è stata successivamente convertita in un Hash. Questo è esattamente ciò che è accaduto con chatbot.prompt.system.

Questo sembra una regressione. Sono abbastanza sicuro che in passato funzionasse.

Posso riprodurre facilmente questo problema con un file di localizzazione come questo:

en:
  foo: "this is foo"

Vai su Personalizza → Testo e sovrascrivi “foo” con un valore diverso.

Quindi, modifica il file di localizzazione in modo che sia simile a questo:

en:
  foo:
    basic: "Basic Foo"
    advanced: "Advanced Foo"

Visita di nuovo Personalizza → Testo e cerca “foo”. Discourse registrerà il seguente errore.

NoMethodError (undefined method `scan' for {:basic=>"Basic Foo", :advanced=>"Advanced Foo"}:Hash)
lib/i18n/i18n_interpolation_keys_finder.rb:6:in `find'
app/controllers/admin/site_texts_controller.rb:183:in `record_for'
app/controllers/admin/site_texts_controller.rb:249:in `block in find_translations'
app/controllers/admin/site_texts_controller.rb:234:in `each'
app/controllers/admin/site_texts_controller.rb:234:in `find_translations'
app/controllers/admin/site_texts_controller.rb:34:in `index'

Discourse non dovrebbe caricare le sovrascritture di traduzione se non esiste una stringa inglese corrispondente.

4 Mi Piace

Grazie @gerhard

È esattamente quello che è successo: ho aggiunto un’altra chiave finale nello stesso bucket.

… E non influisce sulle nuove installazioni.

Esiste una sorta di soluzione alternativa tramite la console Rails?

1 Mi Piace
TranslationOverride.where(translation_key: "chatbot.prompt.system").delete_all
TranslationOverride.send(:reload_locale!)
5 Mi Piace

Perfetto. Sì, stavo per provare quello ma non al :laptop:

Immagino di poter aggiungere quello a una migrazione?!

2 Mi Piace

Credo che questo bug sia stato risolto insieme a questo: :tada:

2 Mi Piace