관리자 -> 사용자 지정 -> 텍스트 동작 오류

채팅봇 프롬프트를 필터링하려고 할 때 이 문제와 유사한 오류가 발생하고 있습니다.

정말 이상한 점은 한 설치 환경에서는 정상적으로 동작하지만, 다른 설치 환경에서는 그렇지 않다는 것입니다.

Admin → Customize → Text의 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.",
...
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>

이로 인해 오류가 발생하고 있습니다… 조사를 계속하겠습니다.

아래 위치에서 호출되는 것 같습니다:

rails 콘솔에서 다음 코드로 문제를 재현할 수 있습니다:

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

아래 행은 메서드가 Hash를 받지 못하도록 방지하기 위한 것으로 생각되는데, 왜 작동하지 않는 것일까요?:

1개의 좋아요

이 동작이 올바르지 않고 어떤 이유로든 신뢰할 수 없다고 판단되어 #contribute:bug로 이동합니다.

코드에 따르면 값이 Hash인 경우 record_for 메서드로 전달되면 안 됩니다(해당 메서드는 텍스트를 기대하므로 예외가 발생하기 때문) 하지만, 일부 경우에는 실제로 전달되고 있습니다.

잘못된 부분이 있다면 수정해 주십시오.

1개의 좋아요

이 문제는 이전에 번역 가능한 문자열이었던 키에 번역 오버라이드가 존재하지만, 나중에 Hash로 변환된 경우 발생합니다. chatbot.prompt.system의 경우에도 정확히 이런 일이 발생했습니다.

이것은 회귀(regression)로 보입니다. 과거에는 이 기능이 정상적으로 작동했던 것으로 확신합니다.

다음과 같은 로케일 파일로 이를 쉽게 재현할 수 있습니다:

en:
  foo: "this is foo"

Customize → Text로 이동하여 "foo"를 다른 값으로 오버라이드하세요.

그런 다음 로케일 파일을 다음과 같이 변경하세요:

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

다시 Customize → Text로 이동하여 "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 님, 감사합니다.

정말 말씀하신 대로였습니다: 같은 버킷에 다른 final 키를 추가했더니 문제가 발생했네요.

… 그리고 새 설치에는 영향을 미치지 않습니다.

rails 콘솔로 해결할 수 있는 방법이 있을까요?

1개의 좋아요
TranslationOverride.where(translation_key: "chatbot.prompt.system").delete_all
TranslationOverride.send(:reload_locale!)
5개의 좋아요

완벽하군요. 네, 저도 그 방법을 시도하려 했는데요, :laptop:에서는 할 수 없겠네요.

아마 마이그레이션에 추가할 수 있겠네요?!

2개의 좋아요

이 버그도 함께 해결되었을 것 같습니다: :tada:

2개의 좋아요