المسؤول - تخصيص - النص يتصرف بشكل سيء

أواجه مشكلات مماثلة عند محاولة التصفية على مطالبات روبوت الدردشة الخاصة بي.

الجزء الغريب حقًا هو أن السلوك يمكن أن يكون جيدًا في تثبيت واحد ولكنه ليس في تثبيت آخر.

خذ عامل التصفية البسيط جدًا chatbot.prompt في المسؤول → تخصيص → نص:

التثبيت العامل:

التثبيت الفاشل:

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'

ملف اللغة المعني هو هذا:

هل أفعل شيئًا غير قانوني؟

3 إعجابات

حسناً
يبدو أن الدالة المعنية تتوقع نصًا:

ولكنها تتلقى بطريقة ما 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

مما يتسبب في تعطلها … سأواصل التحقيق

يتم استدعاؤها من هنا، أعتقد:

يمكنني تكرار المشكلة باستخدام:

I18nInterpolationKeysFinder.find(I18n.overrides_disabled { I18n.t("chatbot.prompt.system.", locale: :en) })
من وحدة تحكم rails.

أعتقد أن هذا السطر من المفترض أن يمنع الدالة من تلقي Hash، ولكنه لا يعمل، لماذا؟:

إعجاب واحد (1)

نقل هذا إلى #bug، لأنني أعتقد أن هذا السلوك غير صحيح وغير موثوق لسبب ما.

وفقًا للكود، إذا كانت القيمة Hash، فلا ينبغي إرسالها إلى طريقة record_for (حيث ستتسبب في استثناء لأنها تتوقع نصًا)، ولكن في بعض الحالات، يتم ذلك.

يسعدني أن يتم تصحيحي.

إعجاب واحد (1)

يحدث هذا عندما يكون هناك تجاوز للترجمة لمفتاح كان في السابق سلسلة قابلة للترجمة، ولكن تم تحويله إلى Hash لاحقًا. هذا بالضبط ما حدث مع chatbot.prompt.system.

يبدو هذا تراجعًا. أنا متأكد من أن هذا كان يعمل في الماضي.

يمكنني بسهولة تكرار هذا باستخدام ملف لغة مثل هذا:

en:
  foo: "this is foo"

انتقل إلى تخصيص – > النص وتجاوز “foo” بقيمة مختلفة.

ثم، قم بتغيير ملف اللغة ليبدو كالتالي:

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

قم بزيارة تخصيص – > النص مرة أخرى وابحث عن “foo”. سيسجل Discourse الخطأ التالي.

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 تحميل تجاوزات الترجمة إذا لم يكن هناك سلسلة إنجليزية مقابلة.

4 إعجابات

شكرا @gerhard

هذا بالضبط ما حدث: لقد أضفت مفتاحًا نهائيًا آخر في نفس الدلو.

… وهذا لا يؤثر على عمليات التثبيت الجديدة.

هل هناك أي نوع من الحلول البديلة لوحدة تحكم rails؟

إعجاب واحد (1)
TranslationOverride.where(translation_key: "chatbot.prompt.system").delete_all
TranslationOverride.send(:reload_locale!)
5 إعجابات

ممتاز. نعم كنت سأجرب ذلك ولكن ليس على :laptop:

هل يمكنني إضافة ذلك إلى ترحيل؟!

إعجابَين (2)

أعتقد أن هذه المشكلة قد تم حلها أيضًا مع هذه المشكلة: :tada:

إعجابَين (2)