Commit Graph

731 Commits

Author SHA1 Message Date
Sam fb81307c59
FEATURE: web browsing tool (#548)
This pull request makes several improvements and additions to the GitHub-related tools and personas in the `discourse-ai` repository:

1. It adds the `WebBrowser` tool to the  `Researcher` persona, allowing the AI to visit web pages, retrieve HTML content, extract the main content, and convert it to plain text.

2. It updates the `GithubFileContent`, `GithubPullRequestDiff`, and `GithubSearchCode` tools to handle HTTP responses more robustly (introducing size limits). 

3. It refactors the `send_http_request` method in the `Tool` class to follow redirects when specified, and to read the response body in chunks to avoid memory issues with large responses. (only for WebBrowser)

4. It updates the system prompt for the `Researcher` persona to provide more detailed guidance on when to use Google search vs web browsing, and how to optimize tool usage and reduce redundant requests.

5. It adds a new `web_browser_spec.rb` file with tests for the `WebBrowser` tool, covering various scenarios like handling different HTML structures and following redirects.
2024-03-28 16:01:58 +11:00
Sam 74c6725c75
FIX: avoid error when attempting to show ai helper to anon (#549)
Also adds an extra guard around ai helper context positioning.
2024-03-28 12:24:00 +11:00
Sam 61e4c56e1a
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.

For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.

The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.

This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.

Other integrations will need to be updated to support images.

Several specs were added to test the new functionality at the persona, prompt building and API layers.

 - Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.

 - Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity


---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-27 14:30:11 +11:00
Discourse Translator Bot 82387cc51d
Update translations (#547) 2024-03-26 10:21:23 -03:00
Martin Brennan c3b26ccb10
DEV: Move admin routes + templates to admin/assets/javascripts/ path (#545)
This ensures these routes and templates are not loaded if the user isn't
admin. Only affects Persona routes at this point in time.
2024-03-25 09:58:53 +10:00
Natalie Tay f3b3312ce0
FIX: Avoid replying to the reply user for llm_triage automation (#544)
Avoid replying to the reply user. This causes an infinite conversation from the reply_user to the reply_user
2024-03-22 12:34:18 +08:00
Jarek Radosz 1d476e3b68
DEV: Remove an unused template (#541) 2024-03-21 15:24:29 +01:00
Martin Brennan fb0d56324f
FEATURE: Improve admin plugin UI and use new plugins show route (#512)
This commit changes Discourse AI's admin plugin page to use the new plugin
show route. The UI for persona editing has also been improved for consistency,
and other plugin UIs will follow suit:

Settings for the plugin are now listed in the plugin UI and can be changed
from there directly after core PR discourse/discourse#26154 is merged.

See also:

* https://github.com/discourse/discourse/pull/26024
* https://github.com/discourse/discourse/pull/26154
* https://github.com/discourse/discourse/pull/26254
2024-03-21 14:29:56 +10:00
Sam 5cac47a30a
FIX: unify automation model translation (#540)
report runner and llm triage used different paths to figure out
underlying model name, unify so we use the same path.

fixes claude 3 based models on llm triage
2024-03-21 11:32:35 +11:00
Sam e8b2a200c1
FIX: prompt engineering for summary prompt (#539)
Prompt was steering incorrectly into the wrong language.

New prompt attempts to be more concise and clear and provides
better guidance about size of summary and how to format it.
2024-03-20 16:33:05 +11:00
Sam 41f1530078
FIX: mention suppression was not working right (#538)
We were only suppressing non mentions, ones that become spans.

@sam in the test was not resolving to a mention cause the user
did not exist.

depends on: https://github.com/discourse/discourse/pull/26253 for tests to pass.
2024-03-20 13:00:39 +11:00
Discourse Translator Bot 1a55d7f6e7
Update translations (#536) 2024-03-19 16:00:17 +01:00
Sam cc0369dd39
FEATURE: friendlier reply behavior in bot PMs (#535)
- Stop replying as bot, when human replies to another human
- Reply as correct persona when replying directly to a persona
- Fix paper cut where suppressing notifications was not doing so
2024-03-19 20:15:12 +11:00
Sam f62703760f
FEATURE: add Claude 3 sonnet/haiku support for Amazon Bedrock (#534)
This PR consolidates the  implements new Anthropic Messages interface for Bedrock Claude endpoints and adds support for the new Claude 3 models (haiku, opus, sonnet).

Key changes:
- Renamed `AnthropicMessages` and `Anthropic` endpoint classes into a single `Anthropic` class (ditto for ClaudeMessages -> Claude)
- Updated `AwsBedrock` endpoints to use the new `/messages` API format for all Claude models
- Added `claude-3-haiku`, `claude-3-opus` and `claude-3-sonnet` model support in both Anthropic and AWS Bedrock endpoints
- Updated specs for the new consolidated endpoints and Claude 3 model support

This refactor removes support for old non messages API which has been deprecated by anthropic
2024-03-19 06:48:46 +11:00
Sam d7ed8180af
FEATURE: allow suppression of notifications from report generation (#533)
* FEATURE: allow suppression of notifications from report generation

Previously we needed to do this by hand, unfortunately this uses up
too many tokens and is very hard to discover.

New option means that we can trivially disable notifications without
needing any prompt engineering.

* URI.parse is safer, use it
2024-03-16 08:05:03 +11:00
David Taylor dfc13fc631
UX: Add title suffix to shared AI pages (#531) 2024-03-15 10:31:58 +00:00
David Taylor 8b0e9984cf
FIX: Syntax highlighting for shared-ai conversions with CSP enabled (#532)
- Adds a nonce to both script tags
- Removes the `onload=` inline script, and moves the tags to the end of the `<body>` instead. This provides the same UX (page will load and render, then hljs will be applied when ready)
2024-03-15 13:48:24 +11:00
Rafael dos Santos Silva 3b8f900486
FIX: Handle unicode on tokenizer (#515)
* FIX: Handle unicode on tokenizer

Our fast track code broke when strings had characters who are longer in tokens than
in UTF-8.

Admins can set `DISCOURSE_AI_STRICT_TOKEN_COUNTING: true` in app.yml to ensure token counting is strict, even if slower.


Co-authored-by: wozulong <sidle.pax_0e@icloud.com>
2024-03-14 17:33:30 -03:00
Rafael dos Santos Silva b327313115
DEV: Fix module namespace breaking reloads (#530) 2024-03-14 15:19:28 -03:00
Kris fc6c3c81e7
UX: add support for dark mode (#529) 2024-03-13 13:16:07 -04:00
Sam ea5c38686e
FIX: expire assets when CSS changes FIX: missing translation on share page (#528)
* FIX: expire assets when CSS changes
FIX: missing translation on share page

Also add trivial image styling

* oops not needed
2024-03-13 20:52:33 +11:00
Sam 9d92dd76fb
FIX: don't show share conversation incorrectly (#526)
* FIX: don't show share conversation incorrectly

- ai_persona_name can be null vs undefined leading to button showing up where it should not
- do not allow sharing of conversations where user is sending PMs to self

* remove erroneous code

* avoid query
2024-03-13 11:24:22 +11:00
Roman Rizzi c4ead89c6b
FIX: Filter soft-deleted topics when backfilling sentiment (#527) 2024-03-12 21:01:24 -03:00
Kris 1c90ad81c2
UX: update styles and markup for share feature (#525) 2024-03-12 18:25:33 -04:00
Discourse Translator Bot 25d283b527
Update translations (#524) 2024-03-12 15:40:21 +01:00
Kelv d57212475c
FIX: ai-image-caption should not crash on checking currentUser can_use_assistant (#523) 2024-03-12 16:40:30 +08:00
Sam a03bc6ddec
FEATURE: Share conversations with AI via a URL (#521)
This allows users to share a static page of an AI conversation with
the rest of the world.

By default this feature is disabled, it is enabled by turning on
ai_bot_allow_public_sharing via site settings

Precautions are taken when sharing

1. We make a carbonite copy
2. We minimize work generating page
3. We limit to 100 interactions
4. Many security checks - including disallowing if there is a mix
of users in the PM.

* Bonus commit, large PRs like this PR did not work with github tool
large objects would destroy context


Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-12 16:51:41 +11:00
Keegan George 740731ab53
FIX: Image caption feature should respect composer AI helper groups (#522) 2024-03-11 15:35:20 -07:00
Sam 79638c2f50
FIX: Tune function calling (#519)
Adds support for "name" on functions which can be used for tool calls

For function calls we need to keep track of id/name and previously
we only supported either

Also attempts to improve sql helper
2024-03-09 08:46:40 +11:00
Keegan George b515b4f66d
FEATURE: AI Quick Semantic Search (#501)
This PR adds AI semantic search to the search pop available on every page.

It depends on several new and optional settings, like per post embeddings and a reranker model, so this is an experimental endeavour.


---------

Co-authored-by: Rafael Silva <xfalcox@gmail.com>
2024-03-08 13:02:50 -03:00
David Taylor 114b96f2b4
DEV: Update to new header API and FloatKit (#516) 2024-03-08 10:07:48 +00:00
Sam 936d246b7d
FIX: Improve AI persona editor inputs and optional GitHub auth (#518)
1. Fix input fields in AI persona editor and make GitHub tool authentication optional

2. AI persona editor improvements and tool GitHub access token check

This pull request makes a few improvements:

- Adds `lang="en"` to number input fields in the AI persona editor to prevent localization issues 
- Adds `step="any"` to allow fractional values for temperature and top_p settings
- Makes GitHub tool authentication contingent on `ai_bot_github_access_token` site setting being present

see: https://meta.discourse.org/t/ai-bot-personas-don-t-accept-decimals-for-temperature-top-p/298243/7
2024-03-08 09:54:05 +11:00
Sam 2ad743d246
FEATURE: Add GitHub Helper AI Bot persona and tools (#513)
Introduces a new AI Bot persona called 'GitHub Helper' which is specialized in assisting with GitHub-related tasks and questions. It includes the following key changes:

- Implements the GitHub Helper persona class with its system prompt and available tools
   
- Adds three new AI Bot tools for GitHub interactions:
  - github_file_content: Retrieves content of files from a GitHub repository
  - github_pull_request_diff: Retrieves the diff for a GitHub pull request
  - github_search_code: Searches for code in a GitHub repository
    
- Updates the AI Bot dialects to support the new GitHub tools

- Implements multiple function calls for standard tool dialect
2024-03-08 06:37:23 +11:00
Rafael dos Santos Silva 176a4458f2
FIX: Prevent AI chat thread titles from being created before replies are posted (#517)
Chat thread replies draft trigger the thread_created event, which we relied on
to trigger the AI generated title. Because of that we now will use the noisier
chat_message_created event, and manually check for thread and replies existence.

See https://github.com/discourse/discourse/pull/26033
2024-03-07 16:14:17 -03:00
Selase Krakani 820e6d63ff
DEV: Lower pinned version to fix unsupported API error on stable (#514)
Previous pinned version included references to new plugin API not
available on stable.

This new pinned version also contains 'backported' SSRF protection
security fix.
2024-03-07 14:30:05 +00:00
Loïc Guitaut 6ae4218a96 DEV: Fix new Rubocop offenses 2024-03-06 15:23:29 +01:00
Sam 8b382d6098
FEATURE: support for claude opus and sonnet (#508)
This provides new support for messages API from Claude.

It is required for latest model access.

Also corrects implementation of function calls.

* Fix message interleving

* fix broken spec

* add new models to automation
2024-03-06 06:04:37 +11:00
Discourse Translator Bot d7aeb1c731
Update translations (#510) 2024-03-05 12:02:46 -03:00
Sam b7a96e3bcb
FIX: avoid all bot feedback loops (#507)
We need to ensure that under no circumstances feedback loops between
bots will emerge cause this can eat up a lot of tokens
2024-03-05 10:02:49 +11:00
Keegan George 9485f3110a
UX: AI Helper positioning (#506) 2024-03-05 08:58:00 +11:00
Keegan George cee1b3d275
FIX: Backspace in composer custom prompt closes menu (#505) 2024-03-04 13:33:31 -08:00
Sam 77cf9e2cff
FIX: system persona non English save, missing bot pms
- FIX: only update system attributes when updating system persona
- FIX: update participant count by hand so bot messages show in inbox
 

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2024-03-04 09:56:59 +11:00
Sam c02794cf2e
FIX: support multiple tool calls (#502)
* FIX: support multiple tool calls

Prior to this change we had a hard limit of 1 tool call per llm
round trip. This meant you could not google multiple things at
once or perform searches across two tools.

Also:

- Hint when Google stops working
- Log topic_id / post_id when performing completions

* Also track id for title
2024-03-02 07:53:21 +11:00
Kris b72ee805b6
DEV: update caption test for core interaction change (#503) 2024-03-01 14:58:33 -05:00
Sam 59bab2bba3
FIX: stream messages when directly PMing a persona (#500)
previous to this fix we did not consider personas a bot in the
front end
2024-03-01 07:53:42 +11:00
Sam 9fb1430e40
FIX: support spaces within arguments for Open AI (#499)
Previous to this fix if a tool call ever streamed a SPACE alone,
we would eat it and ignore it, breaking params

Also fixes some tests to ensure they are actually called :)
2024-02-29 12:47:34 +11:00
Rafael dos Santos Silva 1b72a00d2c
FEATURE: Option for AI triage to send a post to the review queue (#498)
Option for AI triage to send a post to the review queue
2024-02-29 12:33:28 +11:00
Keegan George 6a30b06a55
DEV: Cancel popup should abort request (#497) 2024-02-28 13:32:45 -08:00
Sam 484fd1435b
DEV: improve internal design of ai persona and bug fix (#495)
* DEV: improve internal design of ai persona and bug fix

- Fixes bug where OpenAI could not describe images
- Fixes bug where mentionable personas could not be mentioned unless overarching bot was enabled
- Improves internal design of playground and bot to allow better for non "bot" users
- Allow PMs directly to persona users (previously bot user would also have to be in PM)
- Simplify internal code


Co-authored-by: Martin Brennan <martin@discourse.org>
2024-02-28 16:46:32 +11:00
Keegan George a1b607db80
FIX: Composer service call breaking shared edits (#494) 2024-02-28 10:13:46 +11:00