BoxcarsAI / boxcars

Building applications with composability using Boxcars with LLM's. Inspired by LangChain.
MIT License
430 stars 39 forks source link

Language of output is fixed to English #52

Closed kawakamimoeki closed 9 months ago

kawakamimoeki commented 1 year ago

Since Conversation is written in English, the output is fixed in English.

https://github.com/BoxcarsAI/boxcars/blob/9787f5f7d5f175f0b57a2547ed153be9564390f0/lib/boxcars/boxcar/active_record.rb#L242-L264

I wanted to communicate in Japanese, so I defined conversation in Japanese and replaced default. Is this a good method?

CTEMPLATE = [
  Boxcars::Boxcar.syst("あなたはRuby on Rails Active Recordのコードジェネレーターです"),
  Boxcars::Boxcar.syst("入力された質問に対して、構文的に正しいRails Active Recordコードを作成して実行し、その結果を返します。",
       "ユーザーが特定の例数を指定しない限り、最大で%<top_k>sの結果に限定してください。\n",
       "ユーザーの指定に関係なく、特定のモデルからすべてのカラムをクエリしないでください。",
       "質問に応じて、関連する属性のみを要求してください。\n",
       "また、属性がどのモデルに属しているかに注意してください。\n\n",
       "以下の書式を使用してください:\n",
       "質問: ${{ここに質問を入力}}\n",
       "ARChanges: ${{レコードの数の変更を計算するActive Recordコード}} - ",
       "このARCodeがデータ変更を行う場合のみ、この行を追加してください。\n",
       "ARCode: ${{実行するActive Recordコード}} - 有効なコードを使用してください\n",
       "回答: ${{ここに最終的な回答を入力}}\n\n",
       "以下のActive Recordモデルのみを使用してください: %<model_info>s\n",
       "モデルの説明に表示される属性名のみを使用してください。\n",
       "変数や属性名を創作せず、ARChangesとARCodeのコードで変数を共有しないように注意してください。\n",
       "存在しない属性をクエリしないように注意し、上記の書式を使用してください。\n",
       "最後に、コードでprintやputsを使用しないようにしてください"
      ),
  Boxcars::Boxcar.user("質問: %<question>s")
].freeze

conversation ||= Boxcars::Conversation.new(lines: CTEMPLATE)
my_prompt ||= Boxcars::ConversationPrompt.new(
  conversation: conversation,
  input_variables: [:question],
  other_inputs: [:top_k],
  output_variables: [:answer])
helpdesk = Boxcars::ActiveRecord.new(name: 'helpdesk', models: [User, Blog], prompt: my_prompt)

I would like to support either of the following.

  1. More replaceable design of conversation or
  2. Conversation locale (if replacement is not recommended)
francis commented 1 year ago

This is a good idea. Would moving the prompts to something like the i18n methods of rails let us pull this off?

Another idea is to use chat gpt to help us translate, but I don't know how to verify.

Maybe a prompt store with translations would be the most straightforward.

francis commented 9 months ago

I am willing to accept PRs that handle the above, but it is currently too heavy of a lift for me to get accomplished.