Administrador -> Personalizar -> Texto comportándose mal

Estoy encontrando muchos problemas similares a este al intentar filtrar en los prompts de mi chatbot.

La parte realmente extraña es que el comportamiento puede ser bueno en una instalación pero no en otra.

Tome el filtro muy simple de chatbot.prompt en Administración → Personalizar → Texto:

Instalación que funciona:

Instalación fallida:

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/middleware/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'

El archivo de localización en cuestión es este:

¿Estoy haciendo algo ilegal?

3 Me gusta

ok

parece que o método em questão está esperando texto:

mas de alguma forma está recebendo um 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

Fazendo com que ele caia… Continuarei a investigação

Está sendo chamado daqui, acredito:

Posso reproduzir o problema com:

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

do console do rails.

Acho que esta linha deveria impedir que o método recebesse um Hash, mas não está funcionando, por quê?:

1 me gusta

Moviendo esto a Bug, porque creo que este comportamiento es incorrecto y por alguna razón poco fiable.

Según el código, si el valor es un Hash, no debería enviarse al método record_for (donde causaría una excepción ya que espera texto), pero en algunos casos, sí lo hace.

Estaré encantado de ser corregido.

1 me gusta

Esto ocurre cuando hay una anulación de traducción para una clave que anteriormente era una cadena traducible, pero que se convirtió en un Hash más tarde. Eso es exactamente lo que sucedió con chatbot.prompt.system.

Esto parece una regresión. Estoy bastante seguro de que esto solía funcionar en el pasado.

Puedo reproducir esto fácilmente con un archivo de localización como este:

en:
  foo: "this is foo"

Ve a Customize –> Text y anula “foo” con un valor diferente.

Luego, cambia el archivo de localización para que se vea así:

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

Visita Customize –> Text de nuevo y busca “foo”. Discourse registrará el siguiente error.

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 no debería cargar anulaciones de traducción si no hay una cadena en inglés correspondiente.

4 Me gusta

Gracias @gerhard

Eso es exactamente lo que sucedió: agregué otra clave final en el mismo bucket.

… Y no afecta las nuevas instalaciones.

¿Existe algún tipo de solución alternativa con la consola de Rails?

1 me gusta
TranslationOverride.where(translation_key: "chatbot.prompt.system").delete_all
TranslationOverride.send(:reload_locale!)
5 Me gusta

Perfecto. Sí, iba a intentar eso pero no en :laptop:

¿Supongo que podría añadir eso a una migración?!

2 Me gusta

Creo que este error también se ha resuelto junto con este: :tada:

2 Me gusta