Commit Graph

673 Commits

Author SHA1 Message Date
Jarek Radosz a5a39dd2ee
DEV: Clean up after #677 (#694)
Follow up to b863ddc94b

Ruby:
* Validate `summary` (the column is `not null`)
* Fix `name` validation (the column has `max_length` 100)
* Fix table annotations
* Accept missing `parameter` attributes (`required, `enum`, `enum_values`)

JS:
* Use native classes
* Don't use ember's array extensions
* Add explicit service injections
* Correct class names
* Use `||=` operator
* Use `store` service to create records
* Remove unused service injections
* Extract consts
* Group actions together
* Use `async`/`await`
* Use `withEventValue`
* Sort html attributes
* Use DButtons `@label` arg
* Use `input` elements instead of Ember's `Input` component (same w/ textarea)
* Remove `btn-default` class (automatically applied by DButton)
* Don't mix `I18n.t` and `i18n` in the same template
* Don't track props that aren't used in a template
* Correct invalid `target.value` code
* Remove unused/invalid `this.parameter`/`onChange` code
* Whitespace
* Use the new service import `inject as service` -> `service`
* Use `Object.entries()`
* Add missing i18n strings
* Fix an error in `addEnumValue` (calling `pushObject` on `undefined`)
* Use `TrackedArray`/`TrackedObject`
* Transform tool `parameters` keys (`enumValues` -> `enum_values`)
2024-06-28 08:59:51 +10:00
Rafael dos Santos Silva a708d4dfa2
FIX: Use base64 encoded images in AI Image Caption via LLaVa (#693)
* FIX: Use base64 encoded images in AI Image Caption via LLaVa

This fixed a regression introduced in #646 where we started sending
schemaless URLs for our LLaVa service, which doesn't handle it well.

Moving to base64 encoded images solves:

- The service needing to download images
  Now the service running LLaVa doesn't need internet access

- Secure uploads compat
  Every image is treated the same, less branching for secure uploads

- Image Size problems
  Discourse is now responsible for ensure a max size for images

- Troublesome dev env
  Previously to this commit you would need a dev env that was internet
acessible to use llava image captions
2024-06-27 16:24:44 -03:00
Jan Cernik 8e83c091a2
DEV: Use explicit serializers for all models (#691) 2024-06-27 10:43:00 -03:00
Sam b863ddc94b
FEATURE: custom user defined tools (#677)
Introduces custom AI tools functionality. 

1. Why it was added:
   The PR adds the ability to create, manage, and use custom AI tools within the Discourse AI system. This feature allows for more flexibility and extensibility in the AI capabilities of the platform.

2. What it does:
   - Introduces a new `AiTool` model for storing custom AI tools
   - Adds CRUD (Create, Read, Update, Delete) operations for AI tools
   - Implements a tool runner system for executing custom tool scripts
   - Integrates custom tools with existing AI personas
   - Provides a user interface for managing custom tools in the admin panel

3. Possible use cases:
   - Creating custom tools for specific tasks or integrations (stock quotes, currency conversion etc...)
   - Allowing administrators to add new functionalities to AI assistants without modifying core code
   - Implementing domain-specific tools for particular communities or industries

4. Code structure:
   The PR introduces several new files and modifies existing ones:

   a. Models:
      - `app/models/ai_tool.rb`: Defines the AiTool model
      - `app/serializers/ai_custom_tool_serializer.rb`: Serializer for AI tools

   b. Controllers:
      - `app/controllers/discourse_ai/admin/ai_tools_controller.rb`: Handles CRUD operations for AI tools

   c. Views and Components:
      - New Ember.js components for tool management in the admin interface
      - Updates to existing AI persona management components to support custom tools 

   d. Core functionality:
      - `lib/ai_bot/tool_runner.rb`: Implements the custom tool execution system
      - `lib/ai_bot/tools/custom.rb`: Defines the custom tool class

   e. Routes and configurations:
      - Updates to route configurations to include new AI tool management pages

   f. Migrations:
      - `db/migrate/20240618080148_create_ai_tools.rb`: Creates the ai_tools table

   g. Tests:
      - New test files for AI tool functionality and integration

The PR integrates the custom tools system with the existing AI persona framework, allowing personas to use both built-in and custom tools. It also includes safety measures such as timeouts and HTTP request limits to prevent misuse of custom tools.

Overall, this PR significantly enhances the flexibility and extensibility of the Discourse AI system by allowing administrators to create and manage custom AI tools tailored to their specific needs.

Co-authored-by: Martin Brennan <martin@discourse.org>
2024-06-27 17:27:40 +10:00
Sam af4f871096
FIX: never provide tools with invalid UTF-8 strings (#692)
Previous to this change, on truncation we could return invalid
UTF-8 strings to caller

This also allows tools to read up to 30 megs vs the old 4 megs.
2024-06-27 14:06:52 +10:00
Loïc Guitaut e26c5986f2 DEV: Use Rails 7.0 instead of 7.1 in post-migrations 2024-06-26 18:41:38 +02:00
Loïc Guitaut 6f5873b072 DEV: Use Rails 7.0 instead of 7.1 in migrations 2024-06-26 18:32:11 +02:00
Roman Rizzi e39e0bdb4a
FIX: Move the bot user toggling to the controller. (#688)
Having this as a callback prevents deploys of sites with a vLLM SRV configured and pending migrations. Additionally, this fixes a bug where we didn't delete/deactivate the companion user after deleting an LLM.
2024-06-25 12:45:19 -03:00
Discourse Translator Bot b6f0ad157c
Update translations (#687) 2024-06-25 15:40:17 +02:00
Roman Rizzi f622e2644f
FEATURE: Store provider-specific parameters. (#686)
Previously, we stored request parameters like the OpenAI organization and Bedrock's access key and region as site settings. This change stores them in the `llm_models` table instead, letting us drop more settings while also becoming more flexible.
2024-06-25 08:26:30 +10:00
Sam 1d5fa0ce6c
FIX: when creating an llm we were not creating user (#685)
This meant that if you toggle ai user early it surprisingly did
not work.

Also remove safety settings from gemini, it is overly cautious
2024-06-24 09:59:42 +10:00
dependabot[bot] 346dd734d1
Build(deps): Bump braces from 3.0.2 to 3.0.3 (#683)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-22 16:50:25 +02:00
Roman Rizzi 091dc626e8
FIX: Make sure LlmEnumerator always return value hashes using symbols (#684) 2024-06-21 16:35:31 -03:00
Sam 3a2339902e
FEATURE: allow select claude-3-5 for native tools (#682) 2024-06-21 18:17:36 +10:00
Sam e04a7be122
FEATURE: LLM presets for model creation (#681)
* FEATURE: LLM presets for model creation

Previous to this users needed to look up complicated settings
when setting up models.

This introduces and extensible preset system with Google/OpenAI/Anthropic
presets.

This will cover all the most common LLMs, we can always add more as
we go.

Additionally:

- Proper support for Anthropic Claude Sonnet 3.5
- Stop blurring api keys when navigating away - this made it very complex to reuse keys
2024-06-21 17:32:15 +10:00
Roman Rizzi 558574fa87
DEV: Use LlmModels as options in automation rules (#676) 2024-06-21 08:07:17 +10:00
Rafael dos Santos Silva 714caf34fe
FEATURE: Support for Claude 3.5 Sonnet via AWS Bedrock (#680) 2024-06-20 17:51:46 -03:00
Rafael dos Santos Silva b23a3a86a6
FIX: SRV warning should not trigger on brand new LLM (#679) 2024-06-20 15:37:14 -03:00
Kris 1a8532b91b
UX: improve composer suggestion button layout (#678) 2024-06-20 13:32:14 -04:00
Kris 59ed6d7b3e
UX: show image caption button on image hover (#670) 2024-06-20 08:58:19 +10:00
Roman Rizzi 8849caf136
DEV: Transition "Select model" settings to only use LlmModels (#675)
We no longer support the "provider:model" format in the "ai_helper_model" and
"ai_embeddings_semantic_search_hyde_model" settings. We'll migrate existing
values and work with our new data-driven LLM configs from now on.
2024-06-19 18:01:35 -03:00
Roman Rizzi ed3d5521a8
UX: QoL impromevements to the admin LLM models page. (#674)
API Key value is secret by default, and we include a link to the AI bot user.
2024-06-19 11:21:21 -03:00
Roman Rizzi c4d9fab8e7
FIX: typo when excluding personas from enabled bot list (#671) 2024-06-19 10:16:00 -03:00
Sam 0d6d9a6ef5
FEATURE: allow access to private topics if tool permits (#673)
Previously read tool only had access to public topics, this allows
access to all topics user has access to, if admin opts for the option
Also

- Fixes VLLM migration
- Display which llms have bot enabled
2024-06-19 15:49:36 +10:00
Krzysztof Kotlarek 3c45335936
DEV: disable flaky playground_spec (#672) 2024-06-19 10:56:15 +10:00
Roman Rizzi 8d5f901a67
DEV: Rewire AI bot internals to use LlmModel (#638)
* DRAFT: Create AI Bot users dynamically and support custom LlmModels

* Get user associated to llm_model

* Track enabled bots with attribute

* Don't store bot username. Minor touches to migrate default values in settings

* Handle scenario where vLLM uses a SRV record

* Made 3.5-turbo-16k the default version so we can remove hack
2024-06-18 14:32:14 -03:00
Discourse Translator Bot cc0b222faa
Update translations (#669) 2024-06-18 15:39:41 +02:00
Sam 460f5c4553
FIX: display search correctly, bug when stripping XML (#668)
- Display filtered search correctly, so it is not confusing
- When XML stripping, if a chunk was `<` it would crash
- SQL Helper improved to be better aware of Data Explorer
2024-06-14 15:28:40 +10:00
Sam f642a27f11
FIX: Dall E / Artist broken when tool_details is disabled (#667)
We were missing logic to handle custom_html from tools

This also fixes image generation in chat
2024-06-12 17:58:28 +10:00
Kris 8a0c2020f2
UX: improve appearance of attributed quote when sharing (#665) 2024-06-11 12:06:57 -04:00
Discourse Translator Bot effa6cc59f
Update translations (#664) 2024-06-11 17:20:49 +02:00
Sam 5abf80cb4e
FIX: do not mark column read only so certain deployments work (#663)
In some case we may be deploying migrations, seeding and then
running post migrations, we need this to work so we give up
on this small window of protection
2024-06-11 21:32:49 +10:00
Sam 52a7dd2a4b
FEATURE: optional tool detail blocks (#662)
This is a rather huge refactor with 1 new feature (tool details can
be suppressed)

Previously we use the name "Command" to describe "Tools", this unifies
all the internal language and simplifies the code.

We also amended the persona UI to use less DToggles which aligns
with our design guidelines.

Co-authored-by: Martin Brennan <martin@discourse.org>
2024-06-11 18:14:14 +10:00
Sam 875bb04467
FIX: summarize is not working remove for now (#661)
Summarize is not working right, remove it for now.

Also it was specified twice breaking tool calls.
2024-06-08 12:25:30 +10:00
Roman Rizzi 212ee23698
FIX: Use new report color keys defined in discourse/discourse#27240 (#660) 2024-06-07 15:08:06 -03:00
Sam 8b81ff45b8
FIX: switch off native tools on Anthropic Claude Opus (#659)
Native tools do not work well on Opus.

Chain of Thought prompting means it consumes enormous amounts of
tokens and has poor latency.

This commit introduce and XML stripper to remove various chain of
thought XML islands from anthropic prompts when tools are involved.

This mean Opus native tools is now functions (albeit slowly)

From local testing XML just works better now.

Also fixes enum support in Anthropic native tools
2024-06-07 10:52:01 -03:00
Martin Brennan 7a64699314
DEV: Remove breadcrumbs for now (#656)
This core PR will change the component API a bit,
so it's easier to remove these for now and add them
back after:

https://github.com/discourse/discourse/pull/27365
2024-06-07 10:37:53 +10:00
Rafael dos Santos Silva 92108452f2
FIX: AI Bot Shared Conversation didn't respect CDN / Subfolder (#657) 2024-06-06 15:13:51 -03:00
Sam 3993c685e1
FEATURE: anthropic function calling (#654)
Adds support for native tool calling (both streaming and non streaming) for Anthropic.

This improves general tool support on the Anthropic models.
2024-06-06 08:34:23 +10:00
Sam 564d2de534
FEATURE: Add native Cohere tool support (#655)
Add native Cohere tool support

- Introduce CohereTools class for tool translation and result processing
- Update Command dialect to integrate with CohereTools
- Modify Cohere endpoint to support passing tools and processing tool calls
- Add spec for testing tool triggering with Cohere endpoint
2024-06-04 08:59:15 +10:00
Discourse Translator Bot 97afda278b
Update translations (#653) 2024-05-31 12:27:35 +02:00
Keegan George 02a50a29f8
DEV: Conditionally show AI results toggle based on sort order (#652) 2024-05-29 18:18:22 -07:00
Sam 834fea672f
FEATURE: improved tooling (#651)
1. New tool to easily find files (and default branch) in a Github repo
2. Improved read tool with clearer params and larger context

* limit can totally mess up the richness semantic search adds, so include the results unconditionally.
2024-05-30 06:33:50 +10:00
Martin Brennan d812ecf5da
FIX: Remove doubled up breadcrumb in persona UI (#650)
Followup to 06137ac706
2024-05-29 11:37:01 +10:00
Sam 13840f68b3
FEATURE: restrict public sharing on login required sites (#649)
Initial implementation allowed internet wide sharing of
AI conversations, on sites that require login.

This feature can be an anti feature for private sites cause they
can not share conversations internally.

For now we are removing support for public sharing on login required
sites, if the community need the feature we can consider adding a
setting.
2024-05-29 11:04:47 +10:00
Roman Rizzi bd1490a536
FIX: include_usage is not available in the Azure API. (#648)
Follow-up #618
2024-05-28 16:55:43 -03:00
Sam b487de933d
FEATURE: add support for all vision models (#646)
Previoulsy on GPT-4-vision was supported, change introduces support
for Google/Anthropic and new OpenAI models

Additionally this makes vision work properly in dev environments
cause we sent the encoded payload via prompt vs sending urls
2024-05-28 10:31:15 -03:00
Loïc Guitaut dd4e305ff7
DEV: Update rubocop-discourse to version 3.8.0 (#641) 2024-05-28 11:15:42 +02:00
Sam 309280cbb6
FEATURE: add aspect ratio support to DallE 3 (#647)
DallE 3 supports tall/square and wide images.

This adds support to the 3 variants. (wide / tall / square)
2024-05-28 16:21:40 +10:00
Keegan George dae9d6f14e
FIX: Move image caption group check logic to server side (#645)
* FIX: User groups error before initialization
* DEV: Move group check logic to server side
2024-05-28 10:29:11 +10:00