Improve dice rolling for discourse-narrative-bot

Although @discobot has a dice roller, it’s too simple. It’s not yet capable of rolling complex dice and formulas for specific needs. So, I’d like to improve this feature and make it possible to run dice like 1d20+5, 1d20+2 + 2d12-1, 5d10k2 and so on…

I submitted this PR and would very much appreciate reviews and thoughts about it. Thanks! :slight_smile:

https://github.com/discourse/discourse/pull/7381

Hi! To find out what I can do, say @discobot display help.

Shoo! I don’t want to talk to you… ¬¬

Discourse AI에는 꽤 능숙하고 창의적인 주사위 굴리기 기능이 있습니다. 예를 들어 @random_picker_bot 을 사용할 수 있는데요, 저에게 1d20+5를 굴려 주시겠어요?

그리고 혹시 괜찮으시다면 제 고양이에게도 무작위로 이름을 하나 지어 주세요.

Random Picker

Picking from ["1-20"], picked: [5]

Random Picker

Picking from ["Whiskers,Mittens,Socks,Shadow,Simba,Leo,Oliver,Luna,Bella,Max"], picked: ["Shadow"]

For your adventurous roll of 1d20+5, the dice landed on a 5, which adds up to a grand total of 10!

And for your future feline friend, the Random Picker has decreed its name shall be Shadow. Sounds like a kitty destined for stealthy midnight adventures, doesn’t it? :cat_face::sparkles:

여기서 가장 큰 장점은 특수한 구문을 배울 필요가 없다는 점입니다. GPT-4가 알아서 처리해 주거든요. 주사위 굴림을 약간 비싸게 만들 수는 있지만, GPT 3.5도 꽤 그럴듯하게 잘 작동합니다.

이런 시스템이 우리가 기대하는 대로 작동하는지 어떻게 알 수 있을까요? 홀수를 더 선호하거나, 중복을 피하려는 경향이 있거나, 실제로는 무엇이든 가능할 수 있습니다.

https://github.com/discourse/discourse-ai/blob/main/lib/ai_bot/tools/random_picker.rb 에서 난수 생성 코드를 확인할 수 있습니다. 예를 들어, 주사위 던지기는 다음과 같이 결정되는 것으로 보입니다:

아, 정말 감사합니다. 저는 LLM이 그 일을 처리한다고 단순하게 생각했었는데, 절차적 코드에 연결되는 방식은 전혀 다른 이야기이고, 이 경우에는 그것이 정답이군요!

챗봇에서도 비슷한 일이 벌어져요. 수학을 시키면 우연에 맡기지 않고 결정론적인 함수를 호출합니다.