From f6eedf3e0b07e929eb8644b2496a67c80ef8eae0 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 4 Mar 2025 12:22:30 +1100 Subject: [PATCH] FEATURE: implement thinking token support (#1155) adds support for "thinking tokens" - a feature that exposes the model's reasoning process before providing the final response. Key improvements include: - Add a new Thinking class to handle thinking content from LLMs - Modify endpoints (Claude, AWS Bedrock) to handle thinking output - Update AI bot to display thinking in collapsible details section - Fix SEARCH/REPLACE blocks to support empty replacement strings and general improvements to artifact editing - Allow configurable temperature in triage and report automations - Various bug fixes and improvements to diff parsing --- .../composer-fields/persona-llm-selector.gjs | 14 +- config/locales/client.en.yml | 9 +- config/locales/server.en.yml | 1 + discourse_automation/llm_report.rb | 21 +- discourse_automation/llm_triage.rb | 8 + lib/ai_bot/artifact_update_strategies/diff.rb | 163 +++++++------ lib/ai_bot/bot.rb | 91 +++++++- lib/ai_bot/playground.rb | 23 +- lib/ai_bot/tools/github_pull_request_diff.rb | 50 +++- lib/automation/llm_triage.rb | 5 +- lib/automation/report_runner.rb | 4 +- .../anthropic_message_processor.rb | 74 +++++- lib/completions/dialects/claude.rb | 25 +- lib/completions/dialects/claude_tools.rb | 36 ++- lib/completions/endpoints/anthropic.rb | 7 +- lib/completions/endpoints/aws_bedrock.rb | 6 +- lib/completions/endpoints/base.rb | 6 +- lib/completions/endpoints/canned_response.rb | 9 +- lib/completions/endpoints/fake.rb | 3 +- lib/completions/endpoints/open_ai.rb | 1 + lib/completions/llm.rb | 28 ++- lib/completions/prompt.rb | 27 ++- lib/completions/prompt_messages_builder.rb | 11 +- lib/completions/thinking.rb | 38 ++++ .../anthropic_message_processor_spec.rb | 73 ++++++ .../completions/endpoints/anthropic_spec.rb | 215 ++++++++++++++++++ .../discourse_automation/llm_triage_spec.rb | 9 +- .../artifact_update_strategies/diff_spec.rb | 28 +++ spec/lib/modules/ai_bot/playground_spec.rb | 55 +++++ .../tools/github_pull_request_diff_spec.rb | 61 ++++- 30 files changed, 957 insertions(+), 144 deletions(-) create mode 100644 lib/completions/thinking.rb create mode 100644 spec/lib/completions/anthropic_message_processor_spec.rb diff --git a/assets/javascripts/discourse/connectors/composer-fields/persona-llm-selector.gjs b/assets/javascripts/discourse/connectors/composer-fields/persona-llm-selector.gjs index 951d754a..e3e82b4d 100644 --- a/assets/javascripts/discourse/connectors/composer-fields/persona-llm-selector.gjs +++ b/assets/javascripts/discourse/connectors/composer-fields/persona-llm-selector.gjs @@ -168,12 +168,14 @@ export default class BotSelector extends Component { .filter((bot) => !bot.is_persona) .filter(Boolean); - return availableBots.map((bot) => { - return { - id: bot.id, - name: bot.display_name, - }; - }); + return availableBots + .map((bot) => { + return { + id: bot.id, + name: bot.display_name, + }; + }) + .sort((a, b) => a.name.localeCompare(b.name)); }