mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-19 21:58:00 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97454c59e9 | ||
|
|
d25a47789e | ||
|
|
820294c14d | ||
|
|
dd40ca3e5b | ||
|
|
c67f17cf41 | ||
|
|
b948909afa | ||
|
|
3e66d543b9 | ||
|
|
1ac125b7f5 | ||
|
|
aa0c2e7870 | ||
|
|
f5a49ff077 | ||
|
|
a5863a176c | ||
|
|
0c81f90b84 | ||
|
|
81417daa78 | ||
|
|
780e45911d | ||
|
|
dad709cccb | ||
|
|
75b3238e56 | ||
|
|
293b0ffdb0 | ||
|
|
08c18cd387 | ||
|
|
3ab8e7324e | ||
|
|
cf97fa888c | ||
|
|
dd23cfa1ff | ||
|
|
d6ead37102 | ||
|
|
686bb2ccb3 | ||
|
|
69d64f8b1f | ||
|
|
c3ab0ebb38 | ||
|
|
6af3cf4213 | ||
|
|
52c8052ce6 | ||
|
|
471536cc8f | ||
|
|
e5ce3263bc | ||
|
|
264b6dd716 | ||
|
|
d8ac2f3d49 | ||
|
|
64a7c9ab53 | ||
|
|
ee61425153 | ||
|
|
ce8d84a12a | ||
|
|
2e8444b5e3 | ||
|
|
5cc6e141c2 | ||
|
|
850d56cfcf | ||
|
|
d399b025a9 | ||
|
|
200964422d | ||
|
|
8a23b54e56 | ||
|
|
eccf65f0a6 | ||
|
|
2429788ccc | ||
|
|
0125f48f61 | ||
|
|
94028b2c06 | ||
|
|
c5acce7278 | ||
|
|
4eb51f947a | ||
|
|
e11211d215 | ||
|
|
032c7ee56e | ||
|
|
030990ee90 | ||
|
|
371731ac13 | ||
|
|
99622cec48 | ||
|
|
6a4a7dc0d6 | ||
|
|
df01ce188e | ||
|
|
3bfca45e11 | ||
|
|
ccaf2e894a | ||
|
|
1d22232005 | ||
|
|
a66d88c989 | ||
|
|
2e84f10a97 | ||
|
|
dbc2b4f6bc | ||
|
|
9d2b63bbaa | ||
|
|
277dc73468 | ||
|
|
ccac2b04ac | ||
|
|
0c4b94c527 | ||
|
|
37a9046be4 | ||
|
|
b984b4432e | ||
|
|
5e3b632eee | ||
|
|
99dac520cb | ||
|
|
e21e30ce8c | ||
|
|
5a077e1bdb | ||
|
|
8dd5b3bab8 | ||
|
|
03431b85b4 | ||
|
|
9699754ec7 | ||
|
|
64656d3605 | ||
|
|
9bd79bd3a0 | ||
|
|
bfc9f2ea1d | ||
|
|
96e6372fcd | ||
|
|
f01cf498e2 | ||
|
|
77d427610b | ||
|
|
7c59aa11fe | ||
|
|
98810ce884 | ||
|
|
657fda4961 | ||
|
|
f4780939fc | ||
|
|
954cf44939 | ||
|
|
e973b51f75 | ||
|
|
c9474c55b7 | ||
|
|
c0b7016c3a | ||
|
|
78315195cb | ||
|
|
6040e88dad | ||
|
|
ad3d8cbb3a | ||
|
|
c836bd7f33 | ||
|
|
9d71978feb | ||
|
|
940459ca46 | ||
|
|
09d67bc1c2 | ||
|
|
1681405fb9 | ||
|
|
be408a6aee | ||
|
|
cf975f2a6c | ||
|
|
1df1d3f328 | ||
|
|
ed14525390 | ||
|
|
14caf550ec | ||
|
|
f50e041640 | ||
|
|
ebe00812e2 | ||
|
|
ae72c50236 | ||
|
|
48874d617a | ||
|
|
63be312bb4 | ||
|
|
06f66fdab2 | ||
|
|
b9a65d9ca0 | ||
|
|
e4b1ea32fb | ||
|
|
e9975a5fbc | ||
|
|
2ef4d9d53f | ||
|
|
33a2728644 | ||
|
|
a54c0bdbbf | ||
|
|
d6521850e9 | ||
|
|
258bc7a338 | ||
|
|
187663bbf2 | ||
|
|
8060fc01dd | ||
|
|
b2ca49ab92 | ||
|
|
5e445f09fa | ||
|
|
6f5aecd92b | ||
|
|
317d3c9eec | ||
|
|
0acb3a20a2 | ||
|
|
3b93841982 | ||
|
|
38a45955fb | ||
|
|
caec3bfd2c | ||
|
|
12b3d6fc3d | ||
|
|
21927754b6 | ||
|
|
2131bf1817 | ||
|
|
8cbef49d89 | ||
|
|
cdf717ad5f | ||
|
|
02b6f526da | ||
|
|
a365539282 | ||
|
|
7250b270f5 | ||
|
|
d437d08640 | ||
|
|
61f7a3dd72 | ||
|
|
55d7895f58 | ||
|
|
e2859b3d76 | ||
|
|
0a951ead3e | ||
|
|
432ae30fdf | ||
|
|
799112eb9d | ||
|
|
f806ee28c5 | ||
|
|
32ff143b21 | ||
|
|
90a1f681c5 | ||
|
|
99fe9f3a4f | ||
|
|
cf8a9800f3 | ||
|
|
f57e971f80 | ||
|
|
0d104f5abc | ||
|
|
ba6b8d2b3c | ||
|
|
1c72c4d6ec | ||
|
|
4ca5aba58f | ||
|
|
c4d2574508 | ||
|
|
ceac9cefe5 | ||
|
|
ebe2ad62c6 | ||
|
|
9c0dea9927 | ||
|
|
d2a2d658e6 | ||
|
|
d82427ba56 | ||
|
|
386121d198 | ||
|
|
f9245d52c2 | ||
|
|
9fa2a1a135 | ||
|
|
69288699b3 | ||
|
|
826d15729b | ||
|
|
2ae40c59a3 | ||
|
|
119100bbce | ||
|
|
f92fab24b3 | ||
|
|
671abf3b07 | ||
|
|
d0a366258a | ||
|
|
58d7478f3a | ||
|
|
e8216b70a5 | ||
|
|
152d5f9b4f | ||
|
|
f1104c5e09 | ||
|
|
3ccb097705 | ||
|
|
b9416e66c3 | ||
|
|
9f576e8572 | ||
|
|
629613f75a | ||
|
|
abbb8c1650 | ||
|
|
d2ac4e26b0 | ||
|
|
bd97c0fb4b | ||
|
|
8bd54e6d61 | ||
|
|
e419c5561b | ||
|
|
24a73e92e1 | ||
|
|
832e054dbf | ||
|
|
4703ab04ab | ||
|
|
c1d5be63cc | ||
|
|
5d3ea3d57a | ||
|
|
217b9c4db3 | ||
|
|
e9c805f0df | ||
|
|
11475ea4af | ||
|
|
46a7e98141 | ||
|
|
0d6ccbd237 | ||
|
|
efb30cad87 | ||
|
|
fe33867cb6 | ||
|
|
1b1989e8eb | ||
|
|
afa5df894e | ||
|
|
c8d67b1e4c | ||
|
|
e717b84fb4 | ||
|
|
2463c85b77 | ||
|
|
cbf34580b3 | ||
|
|
e60f815d77 | ||
|
|
a19a6b2188 | ||
|
|
d2dd90d089 | ||
|
|
37e113af0e | ||
|
|
776fa8ac58 | ||
|
|
8715054dda | ||
|
|
95da4c6410 | ||
|
|
92f5b49543 | ||
|
|
e6be9a593e | ||
|
|
375be805a1 | ||
|
|
b99866b8fe | ||
|
|
e9998348c5 | ||
|
|
0ad7b8d4dd | ||
|
|
4175387a93 | ||
|
|
1cac1a7913 | ||
|
|
5fa2f3c822 | ||
|
|
5608b48a2d | ||
|
|
bf01fbd706 | ||
|
|
4722c1baa1 | ||
|
|
222c1e929f | ||
|
|
2a648105e6 | ||
|
|
09f5b83e66 | ||
|
|
7a5f2d4aec | ||
|
|
0d1164c0eb | ||
|
|
54588fc92d | ||
|
|
a5bdb3267b | ||
|
|
d7c124926b | ||
|
|
00f45f8998 | ||
|
|
d0d9fa3d22 | ||
|
|
b3dd213538 | ||
|
|
9dfabb3c55 | ||
|
|
d0dbbccd56 | ||
|
|
75576129fe | ||
|
|
2efd08dbbc | ||
|
|
4bd22108de | ||
|
|
4ea767cb45 | ||
|
|
11846e279c | ||
|
|
c861d71383 | ||
|
|
6fbf32d8a2 | ||
|
|
4216a29325 | ||
|
|
45770c2cd7 | ||
|
|
57905d5510 | ||
|
|
e999aab7c0 | ||
|
|
c47d3893ff | ||
|
|
09c1b77414 | ||
|
|
ea083fdec2 | ||
|
|
ceabcdb26e | ||
|
|
a25793ff11 | ||
|
|
8d8a47b43b | ||
|
|
2889581702 | ||
|
|
12602ba8dd | ||
|
|
e4b8487945 | ||
|
|
fc64c0b505 | ||
|
|
47f5756e5a | ||
|
|
e4ef4bc06e | ||
|
|
ae17104886 | ||
|
|
2d82fcc5e1 | ||
|
|
69a6fcf094 | ||
|
|
4aaa2fcbea | ||
|
|
d855a33e6f | ||
|
|
ca16a749fd | ||
|
|
bcdbf7dcbd | ||
|
|
537a608e7a | ||
|
|
a6c5b3de23 | ||
|
|
3fd0d4d5c1 | ||
|
|
5efb6b0158 | ||
|
|
1b3fff67ec | ||
|
|
3409872090 | ||
|
|
18718a6c47 | ||
|
|
34884859d7 | ||
|
|
50bf0baff7 | ||
|
|
83fe126c9f | ||
|
|
37b38e6a40 | ||
|
|
1d1af91f3e | ||
|
|
a18cb22263 | ||
|
|
f8e06faea5 | ||
|
|
8aeeda5dca | ||
|
|
909fbe89bb | ||
|
|
ea0ead58f8 | ||
|
|
3e59f23193 | ||
|
|
05a7e44de4 | ||
|
|
77e7e044e3 | ||
|
|
6b7800b615 | ||
|
|
1ec86ec1a6 | ||
|
|
e08687a5ca |
No files matched your search
@@ -11,3 +11,7 @@ media/**/*.pptx filter=lfs diff=lfs merge=lfs -text
|
||||
media/**/*.png filter=lfs diff=lfs merge=lfs -text
|
||||
media/**/*.ico filter=lfs diff=lfs merge=lfs -text
|
||||
media/**/*.icns filter=lfs diff=lfs merge=lfs -text
|
||||
*.woff2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.afpub filter=lfs diff=lfs merge=lfs -text
|
||||
*.afdesign filter=lfs diff=lfs merge=lfs -text
|
||||
*.afphoto filter=lfs diff=lfs merge=lfs -text
|
||||
+5
-5
@@ -2,13 +2,13 @@
|
||||
* @MindWorkAI/maintainer
|
||||
|
||||
# The release team is responsible for anything inside the .github directory, such as workflows, actions, and issue templates:
|
||||
/.github/ @MindWorkAI/release
|
||||
|
||||
# The release team is responsible for the update directory:
|
||||
/.updates/ @MindWorkAI/release
|
||||
/.github/ @MindWorkAI/release @SommerEngineering
|
||||
|
||||
# Our Rust experts are responsible for the Rust codebase:
|
||||
/runtime/ @MindWorkAI/rust-experts
|
||||
|
||||
# Our .NET experts are responsible for the .NET codebase:
|
||||
/app/ @MindWorkAI/net-experts
|
||||
/app/ @MindWorkAI/net-experts
|
||||
|
||||
# The source code rules must be reviewed by the release team:
|
||||
/app/SourceCodeRules/ @MindWorkAI/release @SommerEngineering
|
||||
+1
-2
@@ -1,2 +1 @@
|
||||
github: [MindWorkAI]
|
||||
open_collective: mindwork-ai
|
||||
github: [MindWorkAI]
|
||||
@@ -1,6 +1,8 @@
|
||||
name: Build and Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
@@ -46,6 +48,7 @@ jobs:
|
||||
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Check tag vs. metadata version
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
# Ensure, that the tag matches the version in the metadata file:
|
||||
if [ "${GITHUB_REF}" != "refs/tags/${FORMATTED_VERSION}" ]; then
|
||||
@@ -249,18 +252,6 @@ jobs:
|
||||
cd publish/dotnet
|
||||
mv mindworkAIStudio.exe "../../app/MindWork AI Studio/bin/dist/mindworkAIStudioServer${{ matrix.dotnet_name_postfix }}"
|
||||
|
||||
- name: Create parts for the Rust cache key (Unix)
|
||||
if: matrix.platform != 'windows-latest'
|
||||
run: |
|
||||
cd runtime
|
||||
echo "CARGO_LOCK_HASH=${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Create parts for the Rust cache key (Windows)
|
||||
if: matrix.platform == 'windows-latest'
|
||||
run: |
|
||||
cd runtime
|
||||
echo "CARGO_LOCK_HASH=${{ hashFiles('**/Cargo.lock') }}" >> $env:GITHUB_ENV
|
||||
|
||||
- name: Cache Rust
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -272,17 +263,7 @@ jobs:
|
||||
~/.rustup/toolchains
|
||||
runtime/target
|
||||
|
||||
# When the entire key matches, Rust might just create the bundles using the current .NET build:
|
||||
key: target-${{ matrix.dotnet_runtime }}-rust-${{ env.RUST_VERSION }}-dependencies-${{ env.CARGO_LOCK_HASH }}
|
||||
|
||||
# - 1st key: the Rust runtime dependencies changed. Anyway, we might be able to re-use many previously built packages.
|
||||
#
|
||||
# - No match: alright, a new Rust version was released. Sadly, we cannot re-use anything now. Why?
|
||||
# The updated Rust compiler might mitigate some bugs or vulnerabilities. In order to apply
|
||||
# these changes to our app, we have to re-compile everything. That's the reason why it makes
|
||||
# no sense to use more parts for the cache key, like Tauri or Tauri build versions.
|
||||
restore-keys: |
|
||||
target-${{ matrix.dotnet_runtime }}-rust-${{ env.RUST_VERSION }}-dependencies-
|
||||
key: target-${{ matrix.dotnet_runtime }}-rust-${{ env.RUST_VERSION }}
|
||||
|
||||
- name: Setup Rust (stable)
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
@@ -300,7 +281,7 @@ jobs:
|
||||
if: matrix.platform != 'windows-latest'
|
||||
run: |
|
||||
if ! cargo tauri --version > /dev/null 2>&1; then
|
||||
cargo install tauri-cli
|
||||
cargo install --version 1.6.2 tauri-cli
|
||||
else
|
||||
echo "Tauri is already installed"
|
||||
fi
|
||||
@@ -309,10 +290,39 @@ jobs:
|
||||
if: matrix.platform == 'windows-latest'
|
||||
run: |
|
||||
if (-not (cargo tauri --version 2>$null)) {
|
||||
cargo install tauri-cli
|
||||
cargo install --version 1.6.2 tauri-cli
|
||||
} else {
|
||||
Write-Output "Tauri is already installed"
|
||||
}
|
||||
|
||||
- name: Delete previous artifact, which may exist due to caching (macOS)
|
||||
if: startsWith(matrix.platform, 'macos')
|
||||
run: |
|
||||
rm -f runtime/target/${{ matrix.rust_target }}/release/bundle/dmg/MindWork AI Studio_*.dmg
|
||||
rm -f runtime/target/${{ matrix.rust_target }}/release/bundle/macos/MindWork AI Studio.app.tar.gz*
|
||||
|
||||
- name: Delete previous artifact, which may exist due to caching (Windows - MSI)
|
||||
if: startsWith(matrix.platform, 'windows') && contains(matrix.tauri_bundle, 'msi')
|
||||
run: |
|
||||
rm -Force "runtime/target/${{ matrix.rust_target }}/release/bundle/msi/MindWork AI Studio_*.msi"
|
||||
rm -Force "runtime/target/${{ matrix.rust_target }}/release/bundle/msi/MindWork AI Studio*msi.zip*"
|
||||
|
||||
- name: Delete previous artifact, which may exist due to caching (Windows - NSIS)
|
||||
if: startsWith(matrix.platform, 'windows') && contains(matrix.tauri_bundle, 'nsis')
|
||||
run: |
|
||||
rm -Force "runtime/target/${{ matrix.rust_target }}/release/bundle/nsis/MindWork AI Studio_*.exe"
|
||||
rm -Force "runtime/target/${{ matrix.rust_target }}/release/bundle/nsis/MindWork AI Studio*nsis.zip*"
|
||||
|
||||
- name: Delete previous artifact, which may exist due to caching (Linux - Debian Package)
|
||||
if: startsWith(matrix.platform, 'ubuntu') && contains(matrix.tauri_bundle, 'deb')
|
||||
run: |
|
||||
rm -f runtime/target/${{ matrix.rust_target }}/release/bundle/deb/mind-work-ai-studio_*.deb
|
||||
|
||||
- name: Delete previous artifact, which may exist due to caching (Linux - AppImage)
|
||||
if: startsWith(matrix.platform, 'ubuntu') && contains(matrix.tauri_bundle, 'appimage')
|
||||
run: |
|
||||
rm -f runtime/target/${{ matrix.rust_target }}/release/bundle/appimage/mind-work-ai-studio_*.AppImage
|
||||
rm -f runtime/target/${{ matrix.rust_target }}/release/bundle/appimage/mind-work-ai-studio*AppImage.tar.gz*
|
||||
|
||||
- name: Build Tauri project (Unix)
|
||||
if: matrix.platform != 'windows-latest'
|
||||
@@ -337,7 +347,7 @@ jobs:
|
||||
cargo tauri build --target ${{ matrix.rust_target }} --bundles ${{ matrix.tauri_bundle }}
|
||||
|
||||
- name: Upload artifact (macOS)
|
||||
if: startsWith(matrix.platform, 'macos')
|
||||
if: startsWith(matrix.platform, 'macos') && startsWith(github.ref, 'refs/tags/v')
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MindWork AI Studio (macOS ${{ matrix.dotnet_runtime }})
|
||||
@@ -348,7 +358,7 @@ jobs:
|
||||
retention-days: ${{ env.RETENTION_INTERMEDIATE_ASSETS }}
|
||||
|
||||
- name: Upload artifact (Windows - MSI)
|
||||
if: startsWith(matrix.platform, 'windows') && contains(matrix.tauri_bundle, 'msi')
|
||||
if: startsWith(matrix.platform, 'windows') && contains(matrix.tauri_bundle, 'msi') && startsWith(github.ref, 'refs/tags/v')
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MindWork AI Studio (Windows - MSI ${{ matrix.dotnet_runtime }})
|
||||
@@ -359,7 +369,7 @@ jobs:
|
||||
retention-days: ${{ env.RETENTION_INTERMEDIATE_ASSETS }}
|
||||
|
||||
- name: Upload artifact (Windows - NSIS)
|
||||
if: startsWith(matrix.platform, 'windows') && contains(matrix.tauri_bundle, 'nsis')
|
||||
if: startsWith(matrix.platform, 'windows') && contains(matrix.tauri_bundle, 'nsis') && startsWith(github.ref, 'refs/tags/v')
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MindWork AI Studio (Windows - NSIS ${{ matrix.dotnet_runtime }})
|
||||
@@ -370,7 +380,7 @@ jobs:
|
||||
retention-days: ${{ env.RETENTION_INTERMEDIATE_ASSETS }}
|
||||
|
||||
- name: Upload artifact (Linux - Debian Package)
|
||||
if: startsWith(matrix.platform, 'ubuntu') && contains(matrix.tauri_bundle, 'deb')
|
||||
if: startsWith(matrix.platform, 'ubuntu') && contains(matrix.tauri_bundle, 'deb') && startsWith(github.ref, 'refs/tags/v')
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MindWork AI Studio (Linux - deb ${{ matrix.dotnet_runtime }})
|
||||
@@ -380,7 +390,7 @@ jobs:
|
||||
retention-days: ${{ env.RETENTION_INTERMEDIATE_ASSETS }}
|
||||
|
||||
- name: Upload artifact (Linux - AppImage)
|
||||
if: startsWith(matrix.platform, 'ubuntu') && contains(matrix.tauri_bundle, 'appimage')
|
||||
if: startsWith(matrix.platform, 'ubuntu') && contains(matrix.tauri_bundle, 'appimage') && startsWith(github.ref, 'refs/tags/v')
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MindWork AI Studio (Linux - AppImage ${{ matrix.dotnet_runtime }})
|
||||
@@ -392,7 +402,7 @@ jobs:
|
||||
|
||||
build_linux_arm64:
|
||||
name: Build app (linux-arm64)
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04
|
||||
needs: read_metadata
|
||||
env:
|
||||
SKIP: false # allows disabling this long-running job temporarily
|
||||
@@ -478,30 +488,13 @@ jobs:
|
||||
cd publish/dotnet
|
||||
mv mindworkAIStudio "../../app/MindWork AI Studio/bin/dist/mindworkAIStudioServer-aarch64-unknown-linux-gnu"
|
||||
|
||||
- name: Create parts for the Rust cache key
|
||||
if: ${{ env.SKIP != 'true' }}
|
||||
run: |
|
||||
cd runtime
|
||||
echo "CARGO_LOCK_HASH=${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Cache linux arm64 runner image
|
||||
if: ${{ env.SKIP != 'true' }}
|
||||
uses: actions/cache@v4
|
||||
id: linux_arm_cache
|
||||
with:
|
||||
path: $RUNNER_TEMP/linux_arm_qemu_cache.img
|
||||
|
||||
# When the entire key matches, Rust might just create the bundles using the current .NET build:
|
||||
key: target-linux-arm64-rust-${{ env.RUST_VERSION }}-dependencies-${{ env.CARGO_LOCK_HASH }}
|
||||
|
||||
# - 1st key: the Rust runtime dependencies changed. Anyway, we might be able to re-use many previously built packages.
|
||||
#
|
||||
# - No match: alright, a new Rust version was released. Sadly, we cannot re-use anything now. Why?
|
||||
# The updated Rust compiler might mitigate some bugs or vulnerabilities. In order to apply
|
||||
# these changes to our app, we have to re-compile everything. That's the reason why it makes
|
||||
# no sense to use more parts for the cache key, like Tauri or Tauri build versions.
|
||||
restore-keys: |
|
||||
target-linux-arm64-rust-${{ env.RUST_VERSION }}-dependencies-
|
||||
path: ${{ runner.temp }}/linux_arm_qemu_cache.img
|
||||
key: target-linux-arm64-rust-${{ env.RUST_VERSION }}
|
||||
|
||||
- name: Build linux arm runner image
|
||||
uses: pguyot/arm-runner-action@v2
|
||||
@@ -539,12 +532,20 @@ jobs:
|
||||
apt-get install --yes libwebkit2gtk-4.0-dev build-essential libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
|
||||
|
||||
# Setup Tauri:
|
||||
cargo install tauri-cli
|
||||
cargo install --version 1.6.2 tauri-cli
|
||||
|
||||
- name: Add the built runner image to the cache
|
||||
if: ${{ steps.linux_arm_cache.outputs.cache-hit != 'true' && env.SKIP != 'true' }}
|
||||
run: |
|
||||
mv ${{ steps.build-linux-arm-runner.outputs.image }} $RUNNER_TEMP/linux_arm_qemu_cache.img
|
||||
mv ${{ steps.build-linux-arm-runner.outputs.image }} ${{ runner.temp }}/linux_arm_qemu_cache.img
|
||||
|
||||
#
|
||||
# This step does not work, because we start a VM with qemu to run the build.
|
||||
#
|
||||
#- name: Delete previous artifact, which may exist due to caching (Linux - Debian Package)
|
||||
# if: ${{ env.SKIP != 'true' }}
|
||||
# run: |
|
||||
# rm -f result/target/aarch64-unknown-linux-gnu/release/bundle/deb/mind-work-ai-studio_*.deb
|
||||
|
||||
- name: Build Tauri project
|
||||
if: ${{ env.SKIP != 'true' }}
|
||||
@@ -552,11 +553,12 @@ jobs:
|
||||
id: build-linux-arm
|
||||
|
||||
with:
|
||||
base_image: file://$RUNNER_TEMP/linux_arm_qemu_cache.img
|
||||
base_image: file://${{ runner.temp }}/linux_arm_qemu_cache.img
|
||||
cpu: cortex-a53
|
||||
optimize_image: false
|
||||
copy_artifact_path: runtime
|
||||
copy_artifact_dest: result
|
||||
bind_mount_repository: true
|
||||
|
||||
#
|
||||
# We do not need to set the PRIVATE_PUBLISH_KEY and PRIVATE_PUBLISH_KEY_PASSWORD here,
|
||||
@@ -569,23 +571,24 @@ jobs:
|
||||
|
||||
shell: /bin/bash
|
||||
commands: |
|
||||
# Delete all previous artifacts, which may exist due to caching:
|
||||
rm -f runtime/target/aarch64-unknown-linux-gnu/release/bundle/deb/mind-work-ai-studio_*.deb
|
||||
|
||||
export HOME=/root
|
||||
export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
|
||||
source "$HOME/.cargo/env"
|
||||
cd runtime
|
||||
|
||||
# Try to restore the Rust cache from previous build:
|
||||
mkdir -p /rust-cache/target
|
||||
rm -fr target
|
||||
cp -Rp /rust-cache/target target
|
||||
|
||||
cargo tauri build --target aarch64-unknown-linux-gnu --bundles deb
|
||||
|
||||
- name: Debug
|
||||
if: ${{ env.SKIP != 'true' }}
|
||||
run: |
|
||||
echo "Current directory: $(pwd)"
|
||||
ls -lhat
|
||||
|
||||
echo "Searching for linux_arm_qemu_cache.img"
|
||||
find $RUNNER_TEMP -name 'linux_arm_qemu_cache.img' -print 2>/dev/null
|
||||
|
||||
echo "Searching for mind-work-ai-studio_*.deb"
|
||||
find . -name 'mind-work-ai-studio_*.deb' -print 2>/dev/null
|
||||
|
||||
# Save the built libraries for the next job:
|
||||
rm -fr /rust-cache/target
|
||||
cp -Rp target /rust-cache
|
||||
|
||||
- name: Update the runner image to cache the Rust runtime build
|
||||
if: ${{ env.SKIP != 'true' }}
|
||||
@@ -593,7 +596,7 @@ jobs:
|
||||
mv ${{ steps.build-linux-arm.outputs.image }} $RUNNER_TEMP/linux_arm_qemu_cache.img
|
||||
|
||||
- name: Upload artifact (Linux - Debian Package)
|
||||
if: ${{ env.SKIP != 'true' }}
|
||||
if: ${{ env.SKIP != 'true' && startsWith(github.ref, 'refs/tags/v') }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MindWork AI Studio (Linux - deb linux-arm64)
|
||||
@@ -606,6 +609,7 @@ jobs:
|
||||
name: Prepare & create release
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build_main, read_metadata, build_linux_arm64]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- name: Create artifact directory
|
||||
run: mkdir -p $GITHUB_WORKSPACE/artifacts
|
||||
@@ -729,6 +733,9 @@ jobs:
|
||||
# Replace newlines in changelog with \n
|
||||
changelog=$(echo "$CHANGELOG" | awk '{printf "%s\\n", $0}')
|
||||
|
||||
# Escape double quotes in changelog:
|
||||
changelog=$(echo "$changelog" | sed 's/"/\\"/g')
|
||||
|
||||
# Create the latest.json file:
|
||||
cat <<EOOOF > $GITHUB_WORKSPACE/release/assets/latest.json
|
||||
{
|
||||
@@ -760,6 +767,7 @@ jobs:
|
||||
name: Publish release
|
||||
runs-on: ubuntu-latest
|
||||
needs: [read_metadata, create_release]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
@@ -794,7 +802,11 @@ jobs:
|
||||
|
||||
- name: Append scan results to changelog
|
||||
run: |
|
||||
changelog="${{ env.CHANGELOG }}"
|
||||
changelog=$(cat <<'EOOOOOOOF'
|
||||
${{ env.CHANGELOG }}
|
||||
EOOOOOOOF
|
||||
)
|
||||
|
||||
links="${{ steps.virus_total.outputs.analysis }}"
|
||||
|
||||
# Create a temporary file for the changelog:
|
||||
@@ -838,7 +850,7 @@ jobs:
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
prerelease: false
|
||||
prerelease: true
|
||||
draft: false
|
||||
make_latest: true
|
||||
body: ${{ env.CHANGELOG }}
|
||||
|
||||
@@ -147,3 +147,4 @@ orleans.codegen.cs
|
||||
**/.idea/**/dynamic.xml
|
||||
**/.idea/**/uiDesigner.xml
|
||||
**/.idea/**/dbnavigator.xml
|
||||
**/.vs
|
||||
@@ -0,0 +1,22 @@
|
||||
# This CITATION.cff file was generated with cffinit.
|
||||
# Visit https://bit.ly/cffinit to generate yours today!
|
||||
|
||||
cff-version: 1.2.0
|
||||
title: AI Studio
|
||||
message: >-
|
||||
When you want to cite AI Studio in your scientific work,
|
||||
please use these metadata.
|
||||
type: software
|
||||
authors:
|
||||
- given-names: Thorsten
|
||||
family-names: Sommer
|
||||
email: thorsten.sommer@dlr.de
|
||||
affiliation: Deutsches Zentrum für Luft- und Raumfahrt (DLR)
|
||||
orcid: 'https://orcid.org/0000-0002-3264-9934'
|
||||
- name: Open Source Community
|
||||
repository-code: 'https://github.com/MindWorkAI/AI-Studio'
|
||||
url: 'https://mindworkai.org/'
|
||||
keywords:
|
||||
- LLM
|
||||
- AI
|
||||
- Orchestration
|
||||
+1
-1
@@ -6,7 +6,7 @@ FSL-1.1-MIT
|
||||
|
||||
## Notice
|
||||
|
||||
Copyright 2024 Thorsten Sommer
|
||||
Copyright 2025 Thorsten Sommer
|
||||
|
||||
## Terms and Conditions
|
||||
|
||||
|
||||
@@ -1,14 +1,66 @@
|
||||
# MindWork AI Studio
|
||||

|
||||
Are you new here? [Read here](#what-is-ai-studio) what AI Studio is.
|
||||
|
||||
MindWork AI Studio is a desktop application available for macOS, Windows, and Linux. It provides a unified chat interface for Large Language Models (LLMs). You bring your own API key for the respective LLM provider to use the models. The API keys are securely stored by the operating system.
|
||||
## News
|
||||
Things we are currently working on:
|
||||
|
||||
- Since November 2024: Work on RAG (integration of your data and files) has begun. We will support the integration of local and external data sources. We need to implement the following runtime (Rust) and app (.NET) steps:
|
||||
|
||||
- [x] ~~Runtime: Restructuring the code into meaningful modules (PR [#192](https://github.com/MindWorkAI/AI-Studio/pull/192))~~
|
||||
- [x] ~~Define the [External Retrieval Interface (ERI)](https://github.com/MindWorkAI/ERI) as a contract for integrating arbitrary external data (PR [#1](https://github.com/MindWorkAI/ERI/pull/1))~~
|
||||
- [x] ~~App: Metadata for providers (which provider offers embeddings?) (PR [#205](https://github.com/MindWorkAI/AI-Studio/pull/205))~~
|
||||
- [x] ~~App: Add an option to show preview features (PR [#222](https://github.com/MindWorkAI/AI-Studio/pull/222))~~
|
||||
- [x] ~~App: Configure embedding providers (PR [#224](https://github.com/MindWorkAI/AI-Studio/pull/224))~~
|
||||
- [x] ~~App: Implement an [ERI](https://github.com/MindWorkAI/ERI) server coding assistant (PR [#231](https://github.com/MindWorkAI/AI-Studio/pull/231))~~
|
||||
- [x] ~~App: Management of data sources (local & external data via [ERI](https://github.com/MindWorkAI/ERI)) (PR [#259](https://github.com/MindWorkAI/AI-Studio/pull/259), [#273](https://github.com/MindWorkAI/AI-Studio/pull/273))~~
|
||||
- [ ] Runtime: Extract data from txt / md / pdf / docx / xlsx files
|
||||
- [ ] (*Optional*) Runtime: Implement internal embedding provider through [fastembed-rs](https://github.com/Anush008/fastembed-rs)
|
||||
- [ ] App: Implement external embedding providers
|
||||
- [ ] App: Implement the process to vectorize one local file using embeddings
|
||||
- [ ] Runtime: Integration of the vector database [LanceDB](https://github.com/lancedb/lancedb)
|
||||
- [ ] App: Implement the continuous process of vectorizing data
|
||||
- [x] ~~App: Define a common retrieval context interface for the integration of RAG processes in chats (PR [#281](https://github.com/MindWorkAI/AI-Studio/pull/281), [#284](https://github.com/MindWorkAI/AI-Studio/pull/284), [#286](https://github.com/MindWorkAI/AI-Studio/pull/286), [#287](https://github.com/MindWorkAI/AI-Studio/pull/287))~~
|
||||
- [x] ~~App: Define a common augmentation interface for the integration of RAG processes in chats (PR [#288](https://github.com/MindWorkAI/AI-Studio/pull/288), [#289](https://github.com/MindWorkAI/AI-Studio/pull/289))~~
|
||||
- [x] ~~App: Integrate data sources in chats (PR [#282](https://github.com/MindWorkAI/AI-Studio/pull/282))~~
|
||||
|
||||
|
||||
- Since September 2024: Experiments have been started on how we can work on long texts with AI Studio. Let's say you want to write a fantasy novel or create a complex project proposal and use LLM for support. The initial experiments were promising, but not yet satisfactory. We are testing further approaches until a satisfactory solution is found. The current state of our experiment is available as an experimental preview feature through your app configuration. Related PR: ~~[#167](https://github.com/MindWorkAI/AI-Studio/pull/167), [#226](https://github.com/MindWorkAI/AI-Studio/pull/226)~~.
|
||||
|
||||
|
||||
Other News:
|
||||
|
||||
- October 2024: We've found the first two financial supporters. Huge thanks to `richard-stanton` and `peerschuett` for backing the project. Thanks for having the courage to be the first to support us.
|
||||
|
||||
- October 2024: The [German Aerospace Center (DLR)](https://en.wikipedia.org/wiki/German_Aerospace_Center) ([Website](https://www.dlr.de/en)) will use AI Studio at least within the scope of one project and will also contribute to its further development. This is great news.
|
||||
|
||||
|
||||
Features we have recently released:
|
||||
|
||||
- v0.9.25: Added [xAI](https://x.ai/) as a new provider. xAI provides their Grok models for generating content.
|
||||
- v0.9.23: Added support for OpenAI `o` models (`o1`, `o1-mini`, `o3`, etc.); added also an [ERI](https://github.com/MindWorkAI/ERI) server coding assistant as a preview feature behind the RAG feature flag. Your own ERI server can be used to gain access to, e.g., your enterprise data from within AI Studio.
|
||||
- v0.9.22: Added options for preview features; added embedding provider configuration for RAG (preview) and writer mode (experimental preview).
|
||||
- v0.9.18: Added the new Anthropic Heiku model; added Groq and Google Gemini as provider options.
|
||||
- v0.9.17: Added the new Anthropic model `claude-3-5-sonnet-20241022`.
|
||||
- v0.9.16: Added workspace display options & improved the layout of the app window.
|
||||
- v0.9.15: Added the bias-of-the-day assistant. Tells you about a cognitive bias every day.
|
||||
- v0.9.13: You can use `ollama` providers secured with API keys.
|
||||
|
||||
## What is AI Studio?
|
||||
|
||||

|
||||

|
||||
|
||||
MindWork AI Studio is a free desktop app for macOS, Windows, and Linux. It provides a unified user interface for interaction with Large Language Models (LLM). AI Studio also offers so-called assistants, where prompting is not necessary. You can think of AI Studio like an email program: you bring your own API key for the LLM of your choice and can then use these AI systems with AI Studio. Whether you want to use Google Gemini, OpenAI o1, or even your own local AI models.
|
||||
|
||||
**Ready to get started 🤩?** [Download the appropriate setup for your operating system here](documentation/Setup.md).
|
||||
|
||||
**Key advantages:**
|
||||
- **Free of charge**: The app is free to use, both for personal and commercial purposes.
|
||||
- **Independence**: You are not tied to any single provider. Instead, you can choose the provider that best suits their needs. Right now, we support OpenAI (GPT4o etc.), Mistral, Anthropic (Claude), and self-hosted models using [llama.cpp](https://github.com/ggerganov/llama.cpp), [ollama](https://github.com/ollama/ollama), [LM Studio](https://lmstudio.ai/), or [Fireworks](https://fireworks.ai/). Support for Google Gemini, and [Replicate](https://replicate.com/) is planned.
|
||||
- **Independence**: You are not tied to any single provider. Instead, you can choose the provider that best suits their needs. Right now, we support OpenAI (GPT4o, o1, etc.), Mistral, Anthropic (Claude), Google Gemini, xAI (Grok), DeepSeek, and self-hosted models using [llama.cpp](https://github.com/ggerganov/llama.cpp), [ollama](https://github.com/ollama/ollama), [LM Studio](https://lmstudio.ai/), [Groq](https://groq.com/), or [Fireworks](https://fireworks.ai/). For scientists and employees of research institutions, we also support [Helmholtz](https://helmholtz.cloud/services/?serviceID=d7d5c597-a2f6-4bd1-b71e-4d6499d98570) and [GWDG](https://gwdg.de/services/application-services/ai-services/) AI services. These are available through federated logins like eduGAIN to all 18 Helmholtz Centers, the Max Planck Society, most German, and many international universities.
|
||||
- **Assistants**: You just want to quickly translate a text? AI Studio has so-called assistants for such and other tasks. No prompting is necessary when working with these assistants.
|
||||
- **Unrestricted usage**: Unlike services like ChatGPT, which impose limits after intensive use, MindWork AI Studio offers unlimited usage through the providers API.
|
||||
- **Cost-effective**: You only pay for what you use, which can be cheaper than monthly subscription services like ChatGPT Plus, especially if used infrequently. But beware, here be dragons: For extremely intensive usage, the API costs can be significantly higher. Unfortunately, providers currently do not offer a way to display current costs in the app. Therefore, check your account with the respective provider to see how your costs are developing. When available, use prepaid and set a cost limit.
|
||||
- **Privacy**: The data entered into the app is not used for training by the providers since we are using the provider's API.
|
||||
- **Privacy**: You can control which providers receive your data using the provider confidence settings. For example, you can set different protection levels for writing emails compared to general chats, etc. Additionally, most providers guarantee that they won't use your data to train new AI systems.
|
||||
- **Flexibility**: Choose the provider and model best suited for your current task.
|
||||
- **No bloatware**: The app requires minimal storage for installation and operates with low memory usage. Additionally, it has a minimal impact on system resources, which is beneficial for battery life.
|
||||
|
||||
@@ -24,16 +76,21 @@ We offer various ways you can support the project:
|
||||
- **One-Time Contributions**: Make a one-time donation and have your name or company logo included in the app as a gesture of our gratitude.
|
||||
|
||||
For companies, sponsoring MindWork AI Studio is not only a way to support innovation but also a valuable opportunity for public relations and marketing. Your company's name and logo will be featured prominently, showcasing your commitment to using cutting-edge AI tools and enhancing your reputation as an innovative enterprise.
|
||||
|
||||
|
||||
To view all available tiers, please visit our [GitHub Sponsors page](https://github.com/sponsors/MindWorkAI).
|
||||
Your support, whether big or small, keeps the wheels turning and is deeply appreciated ❤️.
|
||||
|
||||
## Planned Features
|
||||
Here's an exciting look at some of the features we're planning to add to MindWork AI Studio in future releases:
|
||||
- **More providers**: We plan to add support for additional LLM providers, such as Google Gemini, giving you more options to choose from.
|
||||
- **System prompts**: Integration of a system prompt library will allow you to control the behavior of the LLM with predefined prompts, ensuring consistency and efficiency.
|
||||
- **Text replacement for better privacy**: Define keywords that will be replaced in your chats before sending content to the provider, enhancing your privacy.
|
||||
- **Advanced interactions**: We're full of ideas for advanced interactions tailored for specific use cases, whether in a business context or for writers and other professionals.
|
||||
Here's an exciting look at some of the features we're planning to add to AI Studio in future releases:
|
||||
- **Integrating your data**: You'll be able to integrate your data into AI Studio, like your PDF or Office files, or your Markdown notes.
|
||||
- **Integration of enterprise data:** It will soon be possible to integrate data from the corporate network using a specified interface ([External Retrieval Interface](https://github.com/MindWorkAI/ERI), ERI for short). This will likely require development work by the organization in question.
|
||||
- **Useful assistants:** We'll develop more assistants for everyday tasks.
|
||||
- **Writing mode:** We're integrating a writing mode to help you create extensive works, like comprehensive project proposals, tenders, or your next fantasy novel.
|
||||
- **Specific requirements:** Want an assistant that suits your specific needs? We aim to offer a plugin architecture so organizations and enthusiasts can implement such ideas.
|
||||
- **Voice control:** You'll interact with the AI systems using your voice. To achieve this, we want to integrate voice input (speech-to-text) and output (text-to-speech). However, later on, it should also have a natural conversation flow, i.e., seamless conversation.
|
||||
- **Content creation:** There will be an interface for AI Studio to create content in other apps. You could, for example, create blog posts directly on the target platform or add entries to an internal knowledge management tool. This requires development work by the tool developers.
|
||||
- **Email monitoring:** You can connect your email inboxes with AI Studio. The AI will read your emails and notify you of important events. You'll also be able to access knowledge from your emails in your chats.
|
||||
- **Browser usage:** We're working on offering AI Studio features in your browser via a plugin, allowing, e.g., for spell-checking or text rewriting directly in the browser.
|
||||
|
||||
Stay tuned for more updates and enhancements to make MindWork AI Studio even more powerful and versatile 🤩.
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="AI Studio" type="DotNetProject" factoryName=".NET Project">
|
||||
<option name="EXE_PATH" value="$PROJECT_DIR$/MindWork AI Studio/bin/Debug/net8.0/osx-arm64/mindworkAIStudio.dll" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/MindWork AI Studio" />
|
||||
<option name="PASS_PARENT_ENVS" value="1" />
|
||||
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||
<option name="USE_MONO" value="0" />
|
||||
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||
<option name="RUNTIME_TYPE" value="coreclr" />
|
||||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/MindWork AI Studio/MindWork AI Studio.csproj" />
|
||||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
|
||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
|
||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||
<option name="PROJECT_TFM" value="net8.0" />
|
||||
<method v="2">
|
||||
<option name="Build" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,7 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Dev" type="CompoundRunConfigurationType">
|
||||
<toRun name="AI Studio" type="DotNetProject" />
|
||||
<toRun name="Tauri Dev" type="ShConfigurationType" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -2,6 +2,8 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MindWork AI Studio", "MindWork AI Studio\MindWork AI Studio.csproj", "{059FDFCC-7D0B-474E-9F20-B9C437DF1CDD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceCodeRules", "SourceCodeRules\SourceCodeRules\SourceCodeRules.csproj", "{0976C1CB-D499-4C86-8ADA-B7A7A4DE0BF8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -12,5 +14,11 @@ Global
|
||||
{059FDFCC-7D0B-474E-9F20-B9C437DF1CDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{059FDFCC-7D0B-474E-9F20-B9C437DF1CDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{059FDFCC-7D0B-474E-9F20-B9C437DF1CDD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0976C1CB-D499-4C86-8ADA-B7A7A4DE0BF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0976C1CB-D499-4C86-8ADA-B7A7A4DE0BF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0976C1CB-D499-4C86-8ADA-B7A7A4DE0BF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0976C1CB-D499-4C86-8ADA-B7A7A4DE0BF8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,6 +1,16 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AI/@EntryIndexedValue">AI</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EDI/@EntryIndexedValue">EDI</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ERI/@EntryIndexedValue">ERI</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GWDG/@EntryIndexedValue">GWDG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LLM/@EntryIndexedValue">LLM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LM/@EntryIndexedValue">LM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSG/@EntryIndexedValue">MSG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RAG/@EntryIndexedValue">RAG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=agentic/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=groq/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=gwdg/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mwais/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ollama/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=tauri_0027s/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
@@ -1 +0,0 @@
|
||||
*.woff2 filter=lfs diff=lfs merge=lfs -text
|
||||
@@ -1,20 +1,37 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
public abstract class AgentBase(SettingsManager settingsManager, IJSRuntime jsRuntime, ThreadSafeRandom rng) : IAgent
|
||||
public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager settingsManager, DataSourceService dataSourceService, ThreadSafeRandom rng) : IAgent
|
||||
{
|
||||
protected static readonly ContentBlock EMPTY_BLOCK = new()
|
||||
{
|
||||
Content = null,
|
||||
ContentType = ContentType.NONE,
|
||||
Role = ChatRole.AGENT,
|
||||
Time = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
protected static readonly JsonSerializerOptions JSON_SERIALIZER_OPTIONS = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||
};
|
||||
|
||||
protected DataSourceService DataSourceService { get; init; } = dataSourceService;
|
||||
|
||||
protected SettingsManager SettingsManager { get; init; } = settingsManager;
|
||||
|
||||
protected IJSRuntime JsRuntime { get; init; } = jsRuntime;
|
||||
|
||||
protected ThreadSafeRandom RNG { get; init; } = rng;
|
||||
|
||||
|
||||
protected ILogger<AgentBase> Logger { get; init; } = logger;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the type or category of this agent.
|
||||
/// </summary>
|
||||
@@ -61,24 +78,30 @@ public abstract class AgentBase(SettingsManager settingsManager, IJSRuntime jsRu
|
||||
Blocks = [],
|
||||
};
|
||||
|
||||
protected DateTimeOffset AddUserRequest(ChatThread thread, string request)
|
||||
protected UserRequest AddUserRequest(ChatThread thread, string request)
|
||||
{
|
||||
var time = DateTimeOffset.Now;
|
||||
var lastUserPrompt = new ContentText
|
||||
{
|
||||
Text = request,
|
||||
};
|
||||
|
||||
thread.Blocks.Add(new ContentBlock
|
||||
{
|
||||
Time = time,
|
||||
ContentType = ContentType.TEXT,
|
||||
Role = ChatRole.USER,
|
||||
Content = new ContentText
|
||||
{
|
||||
Text = request,
|
||||
},
|
||||
Content = lastUserPrompt,
|
||||
});
|
||||
|
||||
return time;
|
||||
|
||||
return new()
|
||||
{
|
||||
Time = time,
|
||||
UserPrompt = lastUserPrompt,
|
||||
};
|
||||
}
|
||||
|
||||
protected async Task AddAIResponseAsync(ChatThread thread, DateTimeOffset time)
|
||||
protected async Task AddAIResponseAsync(ChatThread thread, IContent lastUserPrompt, DateTimeOffset time)
|
||||
{
|
||||
if(this.ProviderSettings is null)
|
||||
return;
|
||||
@@ -104,6 +127,6 @@ public abstract class AgentBase(SettingsManager settingsManager, IJSRuntime jsRu
|
||||
// Use the selected provider to get the AI response.
|
||||
// By awaiting this line, we wait for the entire
|
||||
// content to be streamed.
|
||||
await aiText.CreateFromProviderAsync(providerSettings.CreateProvider(), this.JsRuntime, this.SettingsManager, providerSettings.Model, thread);
|
||||
await aiText.CreateFromProviderAsync(providerSettings.CreateProvider(this.Logger), providerSettings.Model, lastUserPrompt, thread);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.ERIClient;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection> logger, ILogger<AgentBase> baseLogger, SettingsManager settingsManager, DataSourceService dataSourceService, ThreadSafeRandom rng) : AgentBase(baseLogger, settingsManager, dataSourceService, rng)
|
||||
{
|
||||
private readonly List<ContentBlock> answers = new();
|
||||
|
||||
#region Overrides of AgentBase
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Type Type => Type.SYSTEM;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Id => "Data Source Selection";
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string JobDescription =>
|
||||
"""
|
||||
You receive a system and a user prompt, as well as a list of possible data sources as input.
|
||||
Your task is to select the appropriate data sources for the given task. You may choose none,
|
||||
one, or multiple sources, depending on what best fits the system and user prompt. You need
|
||||
to estimate and assess which source, based on its description, might be helpful in
|
||||
processing the prompts.
|
||||
|
||||
Your response is a JSON list in the following format:
|
||||
|
||||
```
|
||||
[
|
||||
{"id": "The data source ID", "reason": "Why did you choose this source?", "confidence": 0.87},
|
||||
{"id": "The data source ID", "reason": "Why did you choose this source?", "confidence": 0.54}
|
||||
]
|
||||
```
|
||||
|
||||
You express your confidence as a floating-point number between 0.0 (maximum uncertainty) and
|
||||
1.0 (you are absolutely certain that this source is needed).
|
||||
|
||||
The JSON schema is:
|
||||
|
||||
```
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"reason": {
|
||||
"type": "string"
|
||||
},
|
||||
"confidence": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"reason",
|
||||
"confidence"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
When no data source is needed, you return an empty JSON list `[]`. You do not ask any
|
||||
follow-up questions. You do not address the user. Your response consists solely of
|
||||
the JSON list.
|
||||
""";
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string SystemPrompt(string availableDataSources) => $"""
|
||||
{this.JobDescription}
|
||||
|
||||
{availableDataSources}
|
||||
""";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Settings.Provider? ProviderSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data source selection agent does not work with context. Use
|
||||
/// the process input method instead.
|
||||
/// </summary>
|
||||
/// <returns>The chat thread without any changes.</returns>
|
||||
public override Task<ChatThread> ProcessContext(ChatThread chatThread, IDictionary<string, string> additionalData) => Task.FromResult(chatThread);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ContentBlock> ProcessInput(ContentBlock input, IDictionary<string, string> additionalData)
|
||||
{
|
||||
if (input.Content is not ContentText text)
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
if(text.InitialRemoteWait || text.IsStreaming)
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
if(string.IsNullOrWhiteSpace(text.Text))
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
if(!additionalData.TryGetValue("availableDataSources", out var availableDataSources) || string.IsNullOrWhiteSpace(availableDataSources))
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
var thread = this.CreateChatThread(this.SystemPrompt(availableDataSources));
|
||||
var userRequest = this.AddUserRequest(thread, text.Text);
|
||||
await this.AddAIResponseAsync(thread, userRequest.UserPrompt, userRequest.Time);
|
||||
|
||||
var answer = thread.Blocks[^1];
|
||||
|
||||
this.answers.Add(answer);
|
||||
return answer;
|
||||
}
|
||||
|
||||
// <inheritdoc />
|
||||
public override Task<bool> MadeDecision(ContentBlock input) => Task.FromResult(true);
|
||||
|
||||
// <inheritdoc />
|
||||
public override IReadOnlyCollection<ContentBlock> GetContext() => [];
|
||||
|
||||
// <inheritdoc />
|
||||
public override IReadOnlyCollection<ContentBlock> GetAnswers() => this.answers;
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<List<SelectedDataSource>> PerformSelectionAsync(IProvider provider, IContent lastPrompt, ChatThread chatThread, AllowedSelectedDataSources dataSources, CancellationToken token = default)
|
||||
{
|
||||
logger.LogInformation("The AI should select the appropriate data sources.");
|
||||
|
||||
//
|
||||
// 1. Which LLM provider should the agent use?
|
||||
//
|
||||
|
||||
// We start with the provider currently selected by the user:
|
||||
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_DATA_SOURCE_SELECTION, provider.Id, true);
|
||||
|
||||
// Assign the provider settings to the agent:
|
||||
logger.LogInformation($"The agent for the data source selection uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");
|
||||
this.ProviderSettings = agentProvider;
|
||||
|
||||
//
|
||||
// 2. Prepare the current system and user prompts as input for the agent:
|
||||
//
|
||||
var lastPromptContent = lastPrompt switch
|
||||
{
|
||||
ContentText text => text.Text,
|
||||
|
||||
// Image prompts may be empty, e.g., when the image is too large:
|
||||
ContentImage image => await image.AsBase64(token),
|
||||
|
||||
// Other content types are not supported yet:
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lastPromptContent))
|
||||
{
|
||||
logger.LogWarning("The last prompt is empty. The AI cannot select data sources.");
|
||||
return [];
|
||||
}
|
||||
|
||||
//
|
||||
// 3. Prepare the allowed data sources as input for the agent:
|
||||
//
|
||||
var additionalData = new Dictionary<string, string>();
|
||||
logger.LogInformation("Preparing the list of allowed data sources for the agent to choose from.");
|
||||
|
||||
// Notice: We do not dispose the Rust service here. The Rust service is a singleton
|
||||
// and will be disposed when the application shuts down:
|
||||
var rustService = Program.SERVICE_PROVIDER.GetService<RustService>()!;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("The following data sources are available for selection:");
|
||||
foreach (var ds in dataSources.AllowedDataSources)
|
||||
{
|
||||
switch (ds)
|
||||
{
|
||||
case DataSourceLocalDirectory localDirectory:
|
||||
sb.AppendLine($"- Id={ds.Id}, name='{localDirectory.Name}', type=local directory, path='{localDirectory.Path}'");
|
||||
break;
|
||||
|
||||
case DataSourceLocalFile localFile:
|
||||
sb.AppendLine($"- Id={ds.Id}, name='{localFile.Name}', type=local file, path='{localFile.FilePath}'");
|
||||
break;
|
||||
|
||||
case IERIDataSource eriDataSource:
|
||||
var eriServerDescription = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
//
|
||||
// Call the ERI server to get the server description:
|
||||
//
|
||||
using var eriClient = ERIClientFactory.Get(eriDataSource.Version, eriDataSource)!;
|
||||
var authResponse = await eriClient.AuthenticateAsync(rustService, cancellationToken: token);
|
||||
if (authResponse.Successful)
|
||||
{
|
||||
var serverDescriptionResponse = await eriClient.GetDataSourceInfoAsync(token);
|
||||
if (serverDescriptionResponse.Successful)
|
||||
{
|
||||
eriServerDescription = serverDescriptionResponse.Data.Description;
|
||||
|
||||
// Remove all line breaks from the description:
|
||||
eriServerDescription = eriServerDescription.Replace("\n", " ").Replace("\r", " ");
|
||||
}
|
||||
else
|
||||
logger.LogWarning($"Was not able to retrieve the server description from the ERI data source '{eriDataSource.Name}'. Message: {serverDescriptionResponse.Message}");
|
||||
}
|
||||
else
|
||||
logger.LogWarning($"Was not able to authenticate with the ERI data source '{eriDataSource.Name}'. Message: {authResponse.Message}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning($"The ERI data source '{eriDataSource.Name}' is not available. Thus, we cannot retrieve the server description. Error: {e.Message}");
|
||||
}
|
||||
|
||||
//
|
||||
// Append the ERI data source to the list. Use the server description if available:
|
||||
//
|
||||
if (string.IsNullOrWhiteSpace(eriServerDescription))
|
||||
sb.AppendLine($"- Id={ds.Id}, name='{eriDataSource.Name}', type=external data source");
|
||||
else
|
||||
sb.AppendLine($"- Id={ds.Id}, name='{eriDataSource.Name}', type=external data source, description='{eriServerDescription}'");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogInformation("Prepared the list of allowed data sources for the agent.");
|
||||
additionalData.Add("availableDataSources", sb.ToString());
|
||||
|
||||
//
|
||||
// 4. Let the agent select the data sources:
|
||||
//
|
||||
var prompt = $"""
|
||||
The system prompt is:
|
||||
|
||||
```
|
||||
{chatThread.SystemPrompt}
|
||||
```
|
||||
|
||||
The user prompt is:
|
||||
|
||||
```
|
||||
{lastPromptContent}
|
||||
```
|
||||
""";
|
||||
|
||||
// Call the agent:
|
||||
var aiResponse = await this.ProcessInput(new ContentBlock
|
||||
{
|
||||
Time = DateTimeOffset.UtcNow,
|
||||
ContentType = ContentType.TEXT,
|
||||
Role = ChatRole.USER,
|
||||
Content = new ContentText
|
||||
{
|
||||
Text = prompt,
|
||||
},
|
||||
}, additionalData);
|
||||
|
||||
if(aiResponse.Content is null)
|
||||
{
|
||||
logger.LogWarning("The agent did not return a response.");
|
||||
return [];
|
||||
}
|
||||
|
||||
switch (aiResponse)
|
||||
{
|
||||
|
||||
//
|
||||
// 5. Parse the agent response:
|
||||
//
|
||||
case { ContentType: ContentType.TEXT, Content: ContentText textContent }:
|
||||
{
|
||||
//
|
||||
// What we expect is a JSON list of SelectedDataSource objects:
|
||||
//
|
||||
var selectedDataSourcesJson = textContent.Text;
|
||||
|
||||
//
|
||||
// We know how bad LLM may be in generating JSON without surrounding text.
|
||||
// Thus, we expect the worst and try to extract the JSON list from the text:
|
||||
//
|
||||
var json = ExtractJson(selectedDataSourcesJson);
|
||||
|
||||
try
|
||||
{
|
||||
var aiSelectedDataSources = JsonSerializer.Deserialize<List<SelectedDataSource>>(json, JSON_SERIALIZER_OPTIONS);
|
||||
return aiSelectedDataSources ?? [];
|
||||
}
|
||||
catch
|
||||
{
|
||||
logger.LogWarning("The agent answered with an invalid or unexpected JSON format.");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
case { ContentType: ContentType.TEXT }:
|
||||
logger.LogWarning("The agent answered with an unexpected inner content type.");
|
||||
return [];
|
||||
|
||||
case { ContentType: ContentType.NONE }:
|
||||
logger.LogWarning("The agent did not return a response.");
|
||||
return [];
|
||||
|
||||
default:
|
||||
logger.LogWarning($"The agent answered with an unexpected content type '{aiResponse.ContentType}'.");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the JSON list from the given text. The text may contain additional
|
||||
/// information around the JSON list. The method tries to extract the JSON list
|
||||
/// from the text.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Algorithm: The method searches for the first line that contains only a '[' character.
|
||||
/// Then, it searches for the first line that contains only a ']' character. The method
|
||||
/// returns the text between these two lines (including the brackets). When the method
|
||||
/// cannot find the JSON list, it returns an empty string.
|
||||
/// </remarks>
|
||||
/// <param name="text">The text that may contain the JSON list.</param>
|
||||
/// <returns>The extracted JSON list.</returns>
|
||||
private static ReadOnlySpan<char> ExtractJson(ReadOnlySpan<char> text)
|
||||
{
|
||||
var startIndex = -1;
|
||||
var endIndex = -1;
|
||||
var foundStart = false;
|
||||
var foundEnd = false;
|
||||
var lineStart = 0;
|
||||
|
||||
for (var i = 0; i <= text.Length; i++)
|
||||
{
|
||||
// Handle the end of the line or the end of the text:
|
||||
if (i == text.Length || text[i] == '\n')
|
||||
{
|
||||
if (IsCharacterAloneInLine(text, lineStart, i, '[') && !foundStart)
|
||||
{
|
||||
startIndex = lineStart;
|
||||
foundStart = true;
|
||||
}
|
||||
else if (IsCharacterAloneInLine(text, lineStart, i, ']') && foundStart && !foundEnd)
|
||||
{
|
||||
endIndex = i;
|
||||
foundEnd = true;
|
||||
break;
|
||||
}
|
||||
|
||||
lineStart = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundStart && foundEnd)
|
||||
{
|
||||
// Adjust endIndex for slicing, ensuring it's within bounds:
|
||||
return text.Slice(startIndex, Math.Min(text.Length, endIndex + 1) - startIndex);
|
||||
}
|
||||
|
||||
return ReadOnlySpan<char>.Empty;
|
||||
}
|
||||
|
||||
private static bool IsCharacterAloneInLine(ReadOnlySpan<char> text, int lineStart, int lineEnd, char character)
|
||||
{
|
||||
for (var i = lineStart; i < lineEnd; i++)
|
||||
if (!char.IsWhiteSpace(text[i]) && text[i] != character)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.RAG;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalContextValidation> logger, ILogger<AgentBase> baseLogger, SettingsManager settingsManager, DataSourceService dataSourceService, ThreadSafeRandom rng) : AgentBase(baseLogger, settingsManager, dataSourceService, rng)
|
||||
{
|
||||
#region Overrides of AgentBase
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Type Type => Type.WORKER;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Id => "Retrieval Context Validation";
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string JobDescription =>
|
||||
"""
|
||||
You receive a system and user prompt as well as a retrieval context as input. Your task is to decide whether this
|
||||
retrieval context is helpful in processing the prompts or not. You respond with the decision (true or false),
|
||||
your reasoning, and your confidence in this decision.
|
||||
|
||||
Your response is only one JSON object in the following format:
|
||||
|
||||
```
|
||||
{"decision": true, "reason": "Why did you choose this source?", "confidence": 0.87}
|
||||
```
|
||||
|
||||
You express your confidence as a floating-point number between 0.0 (maximum uncertainty) and
|
||||
1.0 (you are absolutely certain that this retrieval context is needed).
|
||||
|
||||
The JSON schema is:
|
||||
|
||||
```
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"decision": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"reason": {
|
||||
"type": "string"
|
||||
},
|
||||
"confidence": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"decision",
|
||||
"reason",
|
||||
"confidence"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You do not ask any follow-up questions. You do not address the user. Your response consists solely of
|
||||
that one JSON object.
|
||||
""";
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string SystemPrompt(string retrievalContext) => $"""
|
||||
{this.JobDescription}
|
||||
|
||||
{retrievalContext}
|
||||
""";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Settings.Provider? ProviderSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The retrieval context validation agent does not work with context. Use
|
||||
/// the process input method instead.
|
||||
/// </summary>
|
||||
/// <returns>The chat thread without any changes.</returns>
|
||||
public override Task<ChatThread> ProcessContext(ChatThread chatThread, IDictionary<string, string> additionalData) => Task.FromResult(chatThread);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ContentBlock> ProcessInput(ContentBlock input, IDictionary<string, string> additionalData)
|
||||
{
|
||||
if (input.Content is not ContentText text)
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
if(text.InitialRemoteWait || text.IsStreaming)
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
if(string.IsNullOrWhiteSpace(text.Text))
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
if(!additionalData.TryGetValue("retrievalContext", out var retrievalContext) || string.IsNullOrWhiteSpace(retrievalContext))
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
var thread = this.CreateChatThread(this.SystemPrompt(retrievalContext));
|
||||
var userRequest = this.AddUserRequest(thread, text.Text);
|
||||
await this.AddAIResponseAsync(thread, userRequest.UserPrompt, userRequest.Time);
|
||||
|
||||
return thread.Blocks[^1];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<bool> MadeDecision(ContentBlock input) => Task.FromResult(true);
|
||||
|
||||
/// <summary>
|
||||
/// We do not provide any context. This agent will process many retrieval contexts.
|
||||
/// This would block a huge amount of memory.
|
||||
/// </summary>
|
||||
/// <returns>An empty list.</returns>
|
||||
public override IReadOnlyCollection<ContentBlock> GetContext() => [];
|
||||
|
||||
/// <summary>
|
||||
/// We do not provide any answers. This agent will process many retrieval contexts.
|
||||
/// This would block a huge amount of memory.
|
||||
/// </summary>
|
||||
/// <returns>An empty list.</returns>
|
||||
public override IReadOnlyCollection<ContentBlock> GetAnswers() => [];
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Sets the LLM provider for the agent.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When you have to call the validation in parallel for many retrieval contexts,
|
||||
/// you can set the provider once and then call the validation method in parallel.
|
||||
/// </remarks>
|
||||
/// <param name="provider">The current LLM provider. When the user doesn't preselect an agent provider, the agent uses this provider.</param>
|
||||
public void SetLLMProvider(IProvider provider)
|
||||
{
|
||||
// We start with the provider currently selected by the user:
|
||||
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION, provider.Id, true);
|
||||
|
||||
// Assign the provider settings to the agent:
|
||||
logger.LogInformation($"The agent for the retrieval context validation uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");
|
||||
this.ProviderSettings = agentProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate all retrieval contexts against the last user and the system prompt.
|
||||
/// </summary>
|
||||
/// <param name="lastPrompt">The last user prompt.</param>
|
||||
/// <param name="chatThread">The chat thread.</param>
|
||||
/// <param name="retrievalContexts">All retrieval contexts to validate.</param>
|
||||
/// <param name="token">The cancellation token.</param>
|
||||
/// <returns>The validation results.</returns>
|
||||
public async Task<IReadOnlyList<RetrievalContextValidationResult>> ValidateRetrievalContextsAsync(IContent lastPrompt, ChatThread chatThread, IReadOnlyList<IRetrievalContext> retrievalContexts, CancellationToken token = default)
|
||||
{
|
||||
// Check if the retrieval context validation is enabled:
|
||||
if (!this.SettingsManager.ConfigurationData.AgentRetrievalContextValidation.EnableRetrievalContextValidation)
|
||||
return [];
|
||||
|
||||
logger.LogInformation($"Validating {retrievalContexts.Count:###,###,###,###} retrieval contexts.");
|
||||
|
||||
// Prepare the list of validation tasks:
|
||||
var validationTasks = new List<Task<RetrievalContextValidationResult>>(retrievalContexts.Count);
|
||||
|
||||
// Read the number of parallel validations:
|
||||
var numParallelValidations = 3;
|
||||
if(this.SettingsManager.ConfigurationData.AgentRetrievalContextValidation.PreselectAgentOptions)
|
||||
numParallelValidations = this.SettingsManager.ConfigurationData.AgentRetrievalContextValidation.NumParallelValidations;
|
||||
|
||||
numParallelValidations = Math.Max(1, numParallelValidations);
|
||||
|
||||
// Use a semaphore to limit the number of parallel validations:
|
||||
using var semaphore = new SemaphoreSlim(numParallelValidations);
|
||||
foreach (var retrievalContext in retrievalContexts)
|
||||
{
|
||||
// Wait for an available slot in the semaphore:
|
||||
await semaphore.WaitAsync(token);
|
||||
|
||||
// Start the next validation task:
|
||||
validationTasks.Add(this.ValidateRetrievalContextAsync(lastPrompt, chatThread, retrievalContext, token, semaphore));
|
||||
}
|
||||
|
||||
// Wait for all validation tasks to complete:
|
||||
return await Task.WhenAll(validationTasks);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the retrieval context against the last user and the system prompt.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Probably, you have a lot of retrieval contexts to validate. In this case, you
|
||||
/// can call this method in parallel for each retrieval context. You might use
|
||||
/// the ValidateRetrievalContextsAsync method to validate all retrieval contexts.
|
||||
/// </remarks>
|
||||
/// <param name="lastPrompt">The last user prompt.</param>
|
||||
/// <param name="chatThread">The chat thread.</param>
|
||||
/// <param name="retrievalContext">The retrieval context to validate.</param>
|
||||
/// <param name="token">The cancellation token.</param>
|
||||
/// <param name="semaphore">The optional semaphore to limit the number of parallel validations.</param>
|
||||
/// <returns>The validation result.</returns>
|
||||
public async Task<RetrievalContextValidationResult> ValidateRetrievalContextAsync(IContent lastPrompt, ChatThread chatThread, IRetrievalContext retrievalContext, CancellationToken token = default, SemaphoreSlim? semaphore = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//
|
||||
// Check if the validation was canceled. This could happen when the user
|
||||
// canceled the validation process or when the validation process took
|
||||
// too long:
|
||||
//
|
||||
if(token.IsCancellationRequested)
|
||||
return new(false, "The validation was canceled.", 1.0f, retrievalContext);
|
||||
|
||||
//
|
||||
// 1. Prepare the current system and user prompts as input for the agent:
|
||||
//
|
||||
var lastPromptContent = lastPrompt switch
|
||||
{
|
||||
ContentText text => text.Text,
|
||||
|
||||
// Image prompts may be empty, e.g., when the image is too large:
|
||||
ContentImage image => await image.AsBase64(token),
|
||||
|
||||
// Other content types are not supported yet:
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lastPromptContent))
|
||||
{
|
||||
logger.LogWarning("The last prompt is empty. The AI cannot validate the retrieval context.");
|
||||
return new(false, "The last prompt was empty.", 1.0f, retrievalContext);
|
||||
}
|
||||
|
||||
//
|
||||
// 2. Prepare the retrieval context for the agent:
|
||||
//
|
||||
var additionalData = new Dictionary<string, string>();
|
||||
var markdownRetrievalContext = await retrievalContext.AsMarkdown(token: token);
|
||||
additionalData.Add("retrievalContext", markdownRetrievalContext);
|
||||
|
||||
//
|
||||
// 3. Let the agent validate the retrieval context:
|
||||
//
|
||||
var prompt = $"""
|
||||
The system prompt is:
|
||||
|
||||
```
|
||||
{chatThread.SystemPrompt}
|
||||
```
|
||||
|
||||
The user prompt is:
|
||||
|
||||
```
|
||||
{lastPromptContent}
|
||||
```
|
||||
""";
|
||||
|
||||
// Call the agent:
|
||||
var aiResponse = await this.ProcessInput(new ContentBlock
|
||||
{
|
||||
Time = DateTimeOffset.UtcNow,
|
||||
ContentType = ContentType.TEXT,
|
||||
Role = ChatRole.USER,
|
||||
Content = new ContentText
|
||||
{
|
||||
Text = prompt,
|
||||
},
|
||||
}, additionalData);
|
||||
|
||||
if (aiResponse.Content is null)
|
||||
{
|
||||
logger.LogWarning("The agent did not return a response.");
|
||||
return new(false, "The agent did not return a response.", 1.0f, retrievalContext);
|
||||
}
|
||||
|
||||
switch (aiResponse)
|
||||
{
|
||||
|
||||
//
|
||||
// 4. Parse the agent response:
|
||||
//
|
||||
case { ContentType: ContentType.TEXT, Content: ContentText textContent }:
|
||||
{
|
||||
//
|
||||
// What we expect is one JSON object:
|
||||
//
|
||||
var validationJson = textContent.Text;
|
||||
|
||||
//
|
||||
// We know how bad LLM may be in generating JSON without surrounding text.
|
||||
// Thus, we expect the worst and try to extract the JSON list from the text:
|
||||
//
|
||||
var json = ExtractJson(validationJson);
|
||||
|
||||
try
|
||||
{
|
||||
var result = JsonSerializer.Deserialize<RetrievalContextValidationResult>(json, JSON_SERIALIZER_OPTIONS);
|
||||
return result with { RetrievalContext = retrievalContext };
|
||||
}
|
||||
catch
|
||||
{
|
||||
logger.LogWarning("The agent answered with an invalid or unexpected JSON format.");
|
||||
return new(false, "The agent answered with an invalid or unexpected JSON format.", 1.0f, retrievalContext);
|
||||
}
|
||||
}
|
||||
|
||||
case { ContentType: ContentType.TEXT }:
|
||||
logger.LogWarning("The agent answered with an unexpected inner content type.");
|
||||
return new(false, "The agent answered with an unexpected inner content type.", 1.0f, retrievalContext);
|
||||
|
||||
case { ContentType: ContentType.NONE }:
|
||||
logger.LogWarning("The agent did not return a response.");
|
||||
return new(false, "The agent did not return a response.", 1.0f, retrievalContext);
|
||||
|
||||
default:
|
||||
logger.LogWarning($"The agent answered with an unexpected content type '{aiResponse.ContentType}'.");
|
||||
return new(false, $"The agent answered with an unexpected content type '{aiResponse.ContentType}'.", 1.0f, retrievalContext);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Release the semaphore slot:
|
||||
semaphore?.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlySpan<char> ExtractJson(ReadOnlySpan<char> input)
|
||||
{
|
||||
//
|
||||
// 1. Expect the best case ;-)
|
||||
//
|
||||
if (CheckJsonObjectStart(input))
|
||||
return ExtractJsonPart(input);
|
||||
|
||||
//
|
||||
// 2. Okay, we have some garbage before the
|
||||
// JSON object. We expected that...
|
||||
//
|
||||
for (var index = 0; index < input.Length; index++)
|
||||
{
|
||||
if (input[index] is '{' && CheckJsonObjectStart(input[index..]))
|
||||
return ExtractJsonPart(input[index..]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private static bool CheckJsonObjectStart(ReadOnlySpan<char> area)
|
||||
{
|
||||
char[] expectedSymbols = ['{', '"', 'd'];
|
||||
var symbolIndex = 0;
|
||||
|
||||
foreach (var c in area)
|
||||
{
|
||||
if (symbolIndex >= expectedSymbols.Length)
|
||||
return true;
|
||||
|
||||
if (char.IsWhiteSpace(c))
|
||||
continue;
|
||||
|
||||
if (c == expectedSymbols[symbolIndex++])
|
||||
continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ReadOnlySpan<char> ExtractJsonPart(ReadOnlySpan<char> input)
|
||||
{
|
||||
var insideString = false;
|
||||
for (var index = 0; index < input.Length; index++)
|
||||
{
|
||||
if (input[index] is '"')
|
||||
{
|
||||
insideString = !insideString;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (insideString)
|
||||
continue;
|
||||
|
||||
if (input[index] is '}')
|
||||
return input[..++index];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,17 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
public sealed class AgentTextContentCleaner(SettingsManager settingsManager, IJSRuntime jsRuntime, ThreadSafeRandom rng) : AgentBase(settingsManager, jsRuntime, rng)
|
||||
public sealed class AgentTextContentCleaner(ILogger<AgentBase> logger, SettingsManager settingsManager, DataSourceService dataSourceService, ThreadSafeRandom rng) : AgentBase(logger, settingsManager, dataSourceService, rng)
|
||||
{
|
||||
private static readonly ContentBlock EMPTY_BLOCK = new()
|
||||
{
|
||||
Content = null,
|
||||
ContentType = ContentType.NONE,
|
||||
Role = ChatRole.AGENT,
|
||||
Time = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
private readonly List<ContentBlock> context = new();
|
||||
private readonly List<ContentBlock> answers = new();
|
||||
|
||||
#region Overrides of AgentBase
|
||||
|
||||
public override Settings.Provider? ProviderSettings { get; set; }
|
||||
public override AIStudio.Settings.Provider? ProviderSettings { get; set; }
|
||||
|
||||
protected override Type Type => Type.SYSTEM;
|
||||
|
||||
@@ -73,8 +65,8 @@ public sealed class AgentTextContentCleaner(SettingsManager settingsManager, IJS
|
||||
return EMPTY_BLOCK;
|
||||
|
||||
var thread = this.CreateChatThread(this.SystemPrompt(sourceURL));
|
||||
var time = this.AddUserRequest(thread, text.Text);
|
||||
await this.AddAIResponseAsync(thread, time);
|
||||
var userRequest = this.AddUserRequest(thread, text.Text);
|
||||
await this.AddAIResponseAsync(thread, userRequest.UserPrompt, userRequest.Time);
|
||||
|
||||
var answer = thread.Blocks[^1];
|
||||
this.answers.Add(answer);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using AIStudio.Tools.RAG;
|
||||
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the result of a retrieval context validation.
|
||||
/// </summary>
|
||||
/// <param name="Decision">Whether the retrieval context is useful or not.</param>
|
||||
/// <param name="Reason">The reason for the decision.</param>
|
||||
/// <param name="Confidence">The confidence of the decision.</param>
|
||||
/// <param name="RetrievalContext">The retrieval context that was validated.</param>
|
||||
public readonly record struct RetrievalContextValidationResult(bool Decision, string Reason, float Confidence, IRetrievalContext? RetrievalContext) : IConfidence;
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a selected data source, chosen by the agent.
|
||||
/// </summary>
|
||||
/// <param name="Id">The data source ID.</param>
|
||||
/// <param name="Reason">The reason for selecting the data source.</param>
|
||||
/// <param name="Confidence">The confidence of the agent in the selection.</param>
|
||||
public readonly record struct SelectedDataSource(string Id, string Reason, float Confidence) : IConfidence;
|
||||
@@ -0,0 +1,19 @@
|
||||
using AIStudio.Chat;
|
||||
|
||||
namespace AIStudio.Agents;
|
||||
|
||||
/// <summary>
|
||||
/// The created user request.
|
||||
/// </summary>
|
||||
public sealed class UserRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The time when the request was created.
|
||||
/// </summary>
|
||||
public required DateTimeOffset Time { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The user prompt.
|
||||
/// </summary>
|
||||
public required IContent UserPrompt { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
|
||||
@* ReSharper disable Html.PathError *@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>MindWork AI Studio</title>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<base href="/"/>
|
||||
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
<link href="system/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||
<link href="system/MudBlazor.Markdown/MudBlazor.Markdown.min.css" rel="stylesheet" />
|
||||
<link href="system/CodeBeam.MudBlazor.Extensions/MudExtensions.min.css" rel="stylesheet" />
|
||||
<link href="app.css" rel="stylesheet" />
|
||||
<HeadOutlet/>
|
||||
<script src="diff.js"></script>
|
||||
</head>
|
||||
|
||||
<body style="overflow: hidden;">
|
||||
<Routes @rendermode="new InteractiveServerRenderMode(prerender: false)"/>
|
||||
<script src="_framework/blazor.web.js" autostart="false"></script>
|
||||
<script src="boot.js"></script>
|
||||
<script src="system/MudBlazor/MudBlazor.min.js"></script>
|
||||
<script src="system/MudBlazor.Markdown/MudBlazor.Markdown.min.js"></script>
|
||||
<script src="system/CodeBeam.MudBlazor.Extensions/MudExtensions.min.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
@attribute [Route(Routes.ASSISTANT_AGENDA)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogAgenda>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputName" Validation="@this.ValidateName" Label="Meeting Name" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Tag" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Name the meeting, seminar, etc." Placeholder="Weekly jour fixe" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputTopic" Validation="@this.ValidateTopic" Label="Topic" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.EventNote" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Describe the topic of the meeting, seminar, etc. Is it about quantum computing, software engineering, or is it a general business meeting?" Placeholder="Project meeting" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputContent" Validation="@this.ValidateContent" Label="Content list" Variant="Variant.Outlined" Lines="6" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Bullet list the content of the meeting, seminar, etc. roughly. Use dashes (-) to separate the items." Placeholder="@PLACEHOLDER_CONTENT" Class="mb-3" Immediate="@false" DebounceInterval="1_000" OnDebounceIntervalElapsed="@this.OnContentChanged" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.ListAlt"/>
|
||||
<MudSelect T="string" Label="(Optional) What topics should be the focus?" MultiSelection="@true" @bind-SelectedValues="@this.selectedFoci" Variant="Variant.Outlined" Class="mb-3" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.ListAlt">
|
||||
@foreach (var contentLine in this.contentLines)
|
||||
{
|
||||
@if(!this.justBriefly.Contains(contentLine))
|
||||
{
|
||||
<MudSelectItem T="string" Value="@contentLine">@contentLine</MudSelectItem>
|
||||
}
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudSelect T="string" Label="(Optional) What topics should only be briefly addressed?" MultiSelection="@true" @bind-SelectedValues="@this.justBriefly" Variant="Variant.Outlined" Class="mb-3" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.ListAlt">
|
||||
@foreach (var contentLine in this.contentLines)
|
||||
{
|
||||
@if(!this.selectedFoci.Contains(contentLine))
|
||||
{
|
||||
<MudSelectItem T="string" Value="@contentLine">@contentLine</MudSelectItem>
|
||||
}
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputObjective" Validation="@this.ValidateObjective" Label="Objective" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Flag" Variant="Variant.Outlined" Lines="3" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Describe the objective(s) of the meeting, seminar, etc. What should be achieved?" Placeholder="Discuss the current project status and plan the next steps." Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputModerator" Validation="@this.ValidateModerator" Label="Moderator" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Person3" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Who will moderate the meeting, seminar, etc.?" Placeholder="Jane Doe" Class="mb-3" />
|
||||
<MudTextField T="string" @bind-Text="@this.inputDuration" Validation="@this.ValidateDuration" Label="Duration" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Schedule" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="How long will the meeting, seminar, etc. last? E.g., '2 hours', or '2 days (first day 8 hours, then 4 hours)', etc." Placeholder="2 hours" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputStartTime" Validation="@this.ValidateStartTime" Label="Start time" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Schedule" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="When will the meeting, seminar, etc. start? E.g., '9:00 AM', or '9:00 AM (CET)', etc. When the meeting is a multi-day event, specify the start time for each day." Placeholder="9:00 AM" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputWhoIsPresenting" Label="(Optional) Who is presenting?" Variant="Variant.Outlined" Lines="6" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="(Optional) List the persons who will present at the meeting, seminar, etc. Use dashes (-) to separate the items." Placeholder="@PLACEHOLDER_WHO_IS_PRESENTING" Class="mb-3"/>
|
||||
<MudTextSwitch Label="Do the participants need to get to know each other first?" @bind-Value="@this.introduceParticipants" LabelOn="Yes, introduce participants" LabelOff="No, participants know each other" />
|
||||
<EnumSelection T="NumberParticipants" @bind-Value="@this.numberParticipants" NameFunc="@(participants => participants.Name())" Icon="@Icons.Material.Filled.Group" Label="Number of participants" ValidateSelection="@this.ValidateNumberParticipants"/>
|
||||
<MudTextSwitch Label="Should the participants be involved passively or actively?" @bind-Value="@this.activeParticipation" LabelOn="Active participation, like world café, discussions, etc." LabelOff="Passive participation, like presentations, lectures, etc." />
|
||||
<MudTextSwitch Label="Is this a virtual event, e.g., a call or webinar?" @bind-Value="@this.isMeetingVirtual" LabelOn="Yes, this is a virtual event" LabelOff="No, this is a physical event" />
|
||||
@if (!this.isMeetingVirtual)
|
||||
{
|
||||
<MudPaper Class="pa-3 mb-8 border-dashed border rounded-lg">
|
||||
<MudTextField T="string" @bind-Text="@this.inputLocation" Validation="@this.ValidateLocation" Label="Location" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.MyLocation" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Where will the meeting, seminar, etc. take place?" Placeholder="Hamburg, Germany" Class="mb-3"/>
|
||||
<MudTextSwitch Label="Should there be a joint dinner?" @bind-Value="@this.goingToDinner" LabelOn="Yes, there should be a joint dinner" LabelOff="No, there should be no joint dinner" />
|
||||
<MudTextSwitch Label="Should there be a social activity?" @bind-Value="@this.doingSocialActivity" LabelOn="Yes, there should be a social activity" LabelOff="No, there should be no social activity" />
|
||||
<MudTextSwitch Label="Do participants need to arrive and depart?" @bind-Value="@this.needToArriveAndDepart" LabelOn="Yes, participants need to arrive and depart" LabelOff="No, participants do not need to arrive and depart" />
|
||||
<MudStack Row="@true" Wrap="Wrap.Wrap">
|
||||
<MudTextSlider T="int" Label="Approx. duration of the lunch break" @bind-Value="@this.durationLunchBreak" Min="30" Max="120" Step="5" Unit="minutes"/>
|
||||
<MudTextSlider T="int" Label="Approx. duration of the coffee or tea breaks" @bind-Value="@this.durationBreaks" Min="10" Max="60" Step="5" Unit="minutes"/>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidateTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,508 @@
|
||||
using System.Text;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.Agenda;
|
||||
|
||||
public partial class AssistantAgenda : AssistantBaseCore<SettingsDialogAgenda>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.AGENDA_ASSISTANT;
|
||||
|
||||
protected override string Title => "Agenda Planner";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
This agenda planner helps you create a structured agenda for your meeting or seminar. Just provide some basic
|
||||
information about the event, and the assistant will generate an agenda for you. You can also specify the
|
||||
duration, the start time, the location, the target language, and other details.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You are a friendly assistant who supports the planning and consultation of events. You receive
|
||||
metadata about an event and create an agenda from it. Additionally, you provide advice on what
|
||||
the organizer and moderator should consider. When creating the agenda, you take into account that
|
||||
time for questions and discussions needs to be scheduled. For large events, you take into account
|
||||
the logistical challenges that come with an increasing number of participants.
|
||||
|
||||
If the user is planning interactions with participants, you know various methods. For example:
|
||||
|
||||
- **Townhall Meeting**: An open assembly where participants can ask questions and provide feedback directly to leaders or speakers. Good moderation is necessary to queue contributions and hand the floor to the respective person. Additionally, one person should take notes visible to all. Ideally, this should not be the moderator.
|
||||
|
||||
- **Speed Dating**: Short, structured interaction rounds where participants get the chance to quickly introduce themselves and make initial connections. A long row of tables is needed so that two people can sit opposite each other. A moderator with a stopwatch must ensure that participants rotate and change seats every 3 to 5 minutes.
|
||||
|
||||
- **World Café**: Participants discuss in small groups at tables and rotate after set intervals to exchange thoughts and develop ideas further. Each table needs a host. Notes should be taken on a flipchart or digitally at each table. At the end, the table hosts could present their insights to all participants in a plenary session.
|
||||
|
||||
- **Fishbowl**: A group discusses in an inner circle while a larger group listens from the outside. Occasionally, listeners can move into the inner circle to actively participate.
|
||||
|
||||
- **BarCamp (Unconference)**: Participants contribute to part of the agenda themselves and can act as both presenters and listeners. Anyone can propose and lead a session. However, there should be initial moderation to guide this meta-process.
|
||||
|
||||
- **Open Space Technology**: A method for large groups where participants bring up their own topics and then work intensively in small groups. At the end, the groups can present their findings to all participants in a plenary session.
|
||||
|
||||
- **Panel Discussion**: A group of experts discusses a specific topic in front of an audience, followed by a question-and-answer session.
|
||||
|
||||
- **Breakout Sessions**: Larger groups are divided into smaller, topic-related groups to discuss specific issues more deeply and interactively.
|
||||
|
||||
- **Interactive Polling**: Real-time surveys during the meeting or seminar using digital technology to collect immediate feedback from participants. With an increasing number of participants, technical requirements also become more complex: not every Wi-Fi router can handle several hundred or thousand devices. Additionally, the moderator or speaker must have a stable network connection to display the results. It would be problematic if the speaker depends on the same Wi-Fi as the participants: if the Wi-Fi crashes due to the high number of participants, the speaker cannot show the results. Therefore, a LAN for the speaker or the use of a mobile hotspot would be a better choice.
|
||||
|
||||
- **Peer Learning Groups**: Small groups of participants work together to learn from each other and collaboratively develop solutions for specific challenges.
|
||||
|
||||
- **Role Play/Simulation**: Participants take on roles to simulate certain scenarios, gaining practical experience and promoting dynamic discussions.
|
||||
|
||||
- **Round Table Discussions**: Small group discussions on specific topics, often without formal moderation, to encourage open and equal dialogue.
|
||||
|
||||
- **Mind Mapping**: A method for visualizing ideas and concepts, which can foster creative exchange within groups.
|
||||
|
||||
- **Case Study Analysis**: Groups analyze real or hypothetical case studies and present their solutions or insights.
|
||||
|
||||
- **Silent Meeting/Writing**: Participants write down their thoughts and questions, which are then collected and discussed to balance out loud or dominant voices.
|
||||
|
||||
- **Debate**: Participants argue for or against a specific topic, often with a moderator who ensures that the discussion remains constructive.
|
||||
|
||||
- **Workshops**: Interactive sessions where participants work together on specific tasks or challenges.
|
||||
|
||||
- **Brainstorming**: A method for generating ideas in a group setting, often with a focus on quantity and creativity.
|
||||
|
||||
- **Design Thinking**: A structured approach to innovation solutions. Design thinking is structured in six phases: understand, observe, point of view, ideate, prototype, and test. Depending on the number of participants, there are two moderates needed. One moderator leads the process, the other supports the participants in their work. Design thinking may takes up to two days.
|
||||
|
||||
You output the agenda in the following Markdown format:
|
||||
|
||||
# [Agenda Title]
|
||||
- 09:00 - 09:05 (5 minutes): Welcome
|
||||
- 09:05 - 09:15 (10 minutes): Introduction
|
||||
- ...
|
||||
{this.SystemPromptSocialActivity()}
|
||||
{this.SystemPromptDinner()}
|
||||
|
||||
# Organizational notes
|
||||
[Your advice for the organizer goes here, like room setup, technical requirements, etc.]
|
||||
|
||||
# Moderation notes
|
||||
[Your advice for the moderator goes here]
|
||||
|
||||
Output the agenda in the following language: {this.PromptLanguage()}.
|
||||
""";
|
||||
|
||||
private const string PLACEHOLDER_CONTENT = """
|
||||
- Project status
|
||||
- We need to discuss how to proceed
|
||||
- Problem solving in work package 3 possible?
|
||||
- Concerns of the members
|
||||
""";
|
||||
|
||||
private const string PLACEHOLDER_WHO_IS_PRESENTING = """
|
||||
- John Doe: Project status
|
||||
- Mary Jane: Work package 3
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Create Agenda";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.CreateAgenda;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputContent = string.Empty;
|
||||
this.contentLines.Clear();
|
||||
this.selectedFoci = [];
|
||||
this.justBriefly = [];
|
||||
this.inputWhoIsPresenting = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.inputTopic = string.Empty;
|
||||
this.inputName = string.Empty;
|
||||
this.inputDuration = string.Empty;
|
||||
this.inputStartTime = string.Empty;
|
||||
this.inputObjective = string.Empty;
|
||||
this.inputModerator = string.Empty;
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
this.introduceParticipants = false;
|
||||
this.isMeetingVirtual = true;
|
||||
this.inputLocation = string.Empty;
|
||||
this.goingToDinner = false;
|
||||
this.doingSocialActivity = false;
|
||||
this.needToArriveAndDepart = false;
|
||||
this.durationLunchBreak = 0;
|
||||
this.durationBreaks = 0;
|
||||
this.activeParticipation = false;
|
||||
this.numberParticipants = NumberParticipants.NOT_SPECIFIED;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.Agenda.PreselectOptions)
|
||||
{
|
||||
this.inputTopic = this.SettingsManager.ConfigurationData.Agenda.PreselectTopic;
|
||||
this.inputName = this.SettingsManager.ConfigurationData.Agenda.PreselectName;
|
||||
this.inputDuration = this.SettingsManager.ConfigurationData.Agenda.PreselectDuration;
|
||||
this.inputStartTime = this.SettingsManager.ConfigurationData.Agenda.PreselectStartTime;
|
||||
this.inputObjective = this.SettingsManager.ConfigurationData.Agenda.PreselectObjective;
|
||||
this.inputModerator = this.SettingsManager.ConfigurationData.Agenda.PreselectModerator;
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.Agenda.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.Agenda.PreselectedOtherLanguage;
|
||||
this.introduceParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectIntroduceParticipants;
|
||||
this.isMeetingVirtual = this.SettingsManager.ConfigurationData.Agenda.PreselectIsMeetingVirtual;
|
||||
this.inputLocation = this.SettingsManager.ConfigurationData.Agenda.PreselectLocation;
|
||||
this.goingToDinner = this.SettingsManager.ConfigurationData.Agenda.PreselectJointDinner;
|
||||
this.doingSocialActivity = this.SettingsManager.ConfigurationData.Agenda.PreselectSocialActivity;
|
||||
this.needToArriveAndDepart = this.SettingsManager.ConfigurationData.Agenda.PreselectArriveAndDepart;
|
||||
this.durationLunchBreak = this.SettingsManager.ConfigurationData.Agenda.PreselectLunchTime;
|
||||
this.durationBreaks = this.SettingsManager.ConfigurationData.Agenda.PreselectBreakTime;
|
||||
this.activeParticipation = this.SettingsManager.ConfigurationData.Agenda.PreselectActiveParticipation;
|
||||
this.numberParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectNumberParticipants;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string inputTopic = string.Empty;
|
||||
private string inputName = string.Empty;
|
||||
private string inputContent = string.Empty;
|
||||
private string inputDuration = string.Empty;
|
||||
private string inputStartTime = string.Empty;
|
||||
private IEnumerable<string> selectedFoci = new HashSet<string>();
|
||||
private IEnumerable<string> justBriefly = new HashSet<string>();
|
||||
private string inputObjective = string.Empty;
|
||||
private string inputModerator = string.Empty;
|
||||
private CommonLanguages selectedTargetLanguage;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
private bool introduceParticipants;
|
||||
private bool isMeetingVirtual = true;
|
||||
private string inputLocation = string.Empty;
|
||||
private bool goingToDinner;
|
||||
private bool doingSocialActivity;
|
||||
private bool needToArriveAndDepart;
|
||||
private int durationLunchBreak;
|
||||
private int durationBreaks;
|
||||
private bool activeParticipation;
|
||||
private NumberParticipants numberParticipants;
|
||||
private string inputWhoIsPresenting = string.Empty;
|
||||
|
||||
private readonly List<string> contentLines = [];
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_AGENDA_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputContent = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnContentChanged(string content)
|
||||
{
|
||||
var previousSelectedFoci = new HashSet<string>();
|
||||
var previousJustBriefly = new HashSet<string>();
|
||||
|
||||
this.contentLines.Clear();
|
||||
foreach (var line in content.AsSpan().EnumerateLines())
|
||||
{
|
||||
var trimmedLine = line.Trim();
|
||||
if (trimmedLine.StartsWith("-"))
|
||||
trimmedLine = trimmedLine[1..].Trim();
|
||||
|
||||
if (trimmedLine.Length == 0)
|
||||
continue;
|
||||
|
||||
var finalLine = trimmedLine.ToString();
|
||||
if(this.selectedFoci.Any(x => x.StartsWith(finalLine, StringComparison.InvariantCultureIgnoreCase)))
|
||||
previousSelectedFoci.Add(finalLine);
|
||||
|
||||
if(this.justBriefly.Any(x => x.StartsWith(finalLine, StringComparison.InvariantCultureIgnoreCase)))
|
||||
previousJustBriefly.Add(finalLine);
|
||||
|
||||
this.contentLines.Add(finalLine);
|
||||
}
|
||||
|
||||
this.selectedFoci = previousSelectedFoci;
|
||||
this.justBriefly = previousJustBriefly;
|
||||
}
|
||||
|
||||
private string? ValidateLocation(string location)
|
||||
{
|
||||
if(!this.isMeetingVirtual && string.IsNullOrWhiteSpace(location))
|
||||
return "Please provide a location for the meeting or the seminar.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateNumberParticipants(NumberParticipants selectedSize)
|
||||
{
|
||||
if(selectedSize is NumberParticipants.NOT_SPECIFIED)
|
||||
return "Please select the number of participants.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateTargetLanguage(CommonLanguages language)
|
||||
{
|
||||
if(language is CommonLanguages.AS_IS)
|
||||
return "Please select a target language for the agenda.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateDuration(string duration)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(duration))
|
||||
return "Please provide a duration for the meeting or the seminar, e.g. '2 hours', or '2 days (8 hours and 4 hours)', etc.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateStartTime(string startTime)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(startTime))
|
||||
return "Please provide a start time for the meeting or the seminar. When the meeting is a multi-day event, specify the start time for each day, e.g. '9:00 AM, 10:00 AM', etc.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateTopic(string topic)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(topic))
|
||||
return "Please provide a topic for the agenda. What is the meeting or the seminar about?";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateName(string name)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(name))
|
||||
return "Please provide a name for the meeting or the seminar.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateContent(string content)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(content))
|
||||
return "Please provide some content for the agenda. What are the main points of the meeting or the seminar?";
|
||||
|
||||
var lines = content.Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var line in lines)
|
||||
if(!line.TrimStart().StartsWith('-'))
|
||||
return "Please start each line of your content list with a dash (-) to create a bullet point list.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateObjective(string objective)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(objective))
|
||||
return "Please provide an objective for the meeting or the seminar. What do you want to achieve?";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateModerator(string moderator)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(moderator))
|
||||
return "Please provide a moderator for the meeting or the seminar. Who will lead the discussion?";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task CreateAgenda()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
Create an agenda for the meeting or seminar wit the title '{this.inputName}' using the following details:
|
||||
|
||||
- The overall topic is '{this.inputTopic}'.
|
||||
- The objective of the meeting is '{this.inputObjective}'.
|
||||
- The moderator is '{this.inputModerator}'.
|
||||
- The planned duration is '{this.inputDuration}'.
|
||||
- The planned start time is '{this.inputStartTime}'.
|
||||
{this.PromptGettingToKnowEachOther()}
|
||||
- The number of participants is '{this.numberParticipants.Name()}'.
|
||||
{this.PromptActiveParticipation()}
|
||||
{this.PromptVirtualMeeting()}
|
||||
{this.PromptPhysicalMeeting()}
|
||||
|
||||
Here is draft what was planned for the meeting:
|
||||
{this.inputContent}
|
||||
|
||||
Please do not follow this draft strictly. It is just a suggestion.
|
||||
{this.PromptFoci()}
|
||||
{this.PromptBriefly()}
|
||||
{this.PromptWhoIsPresenting()}
|
||||
""");
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
|
||||
private string PromptLanguage()
|
||||
{
|
||||
if(this.selectedTargetLanguage is CommonLanguages.AS_IS)
|
||||
return "Use the same language as the input.";
|
||||
|
||||
if(this.selectedTargetLanguage is CommonLanguages.OTHER)
|
||||
return this.customTargetLanguage;
|
||||
|
||||
return this.selectedTargetLanguage.Name();
|
||||
}
|
||||
|
||||
private string PromptPhysicalMeeting()
|
||||
{
|
||||
if(this.isMeetingVirtual)
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
- The meeting takes place at the following location: '{this.inputLocation}'.
|
||||
{this.PromptJoiningDinner()}
|
||||
{this.PromptSocialActivity()}
|
||||
{this.PromptArriveAndDepart()}
|
||||
- In case a lunch break is necessary, the break should about {this.durationLunchBreak} minutes long.
|
||||
- In case any breaks are necessary, the breaks should be about {this.durationBreaks} minutes long.
|
||||
""";
|
||||
}
|
||||
|
||||
private string PromptArriveAndDepart()
|
||||
{
|
||||
if (this.needToArriveAndDepart)
|
||||
return "- The participants should have time to arrive and depart.";
|
||||
|
||||
return "- The participants do not need to arrive and depart.";
|
||||
}
|
||||
|
||||
private string PromptSocialActivity()
|
||||
{
|
||||
if (this.doingSocialActivity)
|
||||
return "- The participants will engage in a social activity after the meeting or seminar. This can be a team-building exercise, a sightseeing tour, or a visit to a local attraction. Please make a recommendation for an activity at '{this.inputLocation}'.";
|
||||
|
||||
return "- The participants will not engage in a social activity after the meeting or seminar.";
|
||||
}
|
||||
|
||||
private string SystemPromptSocialActivity()
|
||||
{
|
||||
if(this.doingSocialActivity)
|
||||
return """
|
||||
- 16:00 Departure to the social event [Consider the time needed to get to the location].
|
||||
- 17:00 [Insert your advice for the social activity here].
|
||||
""";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string SystemPromptDinner()
|
||||
{
|
||||
if(this.goingToDinner)
|
||||
return """
|
||||
- 19:00 Departure to the restaurant [Consider the time needed to get to the restaurant].
|
||||
- 20:00 [Insert your advice for the dinner here.].
|
||||
""";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string PromptJoiningDinner()
|
||||
{
|
||||
if (this.goingToDinner)
|
||||
return $"- The participants will join for a dinner after the meeting or seminar. Please make a recommendation for a restaurant at '{this.inputLocation}'.";
|
||||
|
||||
return "- The participants will not join for a dinner after the meeting or seminar.";
|
||||
}
|
||||
|
||||
private string PromptVirtualMeeting()
|
||||
{
|
||||
if (this.isMeetingVirtual)
|
||||
return "- The meeting or seminar will be held virtually, e.g, a call or webinar. The participants will join online.";
|
||||
|
||||
return "- The meeting or seminar will be held in person.";
|
||||
}
|
||||
|
||||
private string PromptActiveParticipation()
|
||||
{
|
||||
if (this.activeParticipation)
|
||||
return "- The participants should actively participate in the meeting or seminar. This can be done through discussions, questions, and contributions to the content.";
|
||||
|
||||
return "- The participants do not need to actively participate.";
|
||||
}
|
||||
|
||||
private string PromptGettingToKnowEachOther()
|
||||
{
|
||||
if (this.introduceParticipants)
|
||||
return "- The participants should introduce themselves to get to know each other. This can be done in a round or in pairs. The moderator should ensure that everyone has the opportunity to speak.";
|
||||
|
||||
return "- The participants do not need to introduce themselves.";
|
||||
}
|
||||
|
||||
private string PromptFoci()
|
||||
{
|
||||
if (this.selectedFoci.Any())
|
||||
{
|
||||
return $"""
|
||||
|
||||
Out of this content, the following points should be focused on:
|
||||
{this.ConvertItemsToMarkdown(this.selectedFoci)}
|
||||
""";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string PromptBriefly()
|
||||
{
|
||||
if (this.justBriefly.Any())
|
||||
{
|
||||
return $"""
|
||||
|
||||
The following points should be just briefly mentioned:
|
||||
{this.ConvertItemsToMarkdown(this.justBriefly)}
|
||||
""";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string PromptWhoIsPresenting()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(this.inputWhoIsPresenting))
|
||||
{
|
||||
return $"""
|
||||
|
||||
The following persons will present the content:
|
||||
{this.inputWhoIsPresenting}
|
||||
""";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string ConvertItemsToMarkdown(IEnumerable<string> items)
|
||||
{
|
||||
var markdown = new StringBuilder();
|
||||
foreach (var item in items)
|
||||
markdown.AppendLine($"- {item}");
|
||||
|
||||
return markdown.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace AIStudio.Assistants.Agenda;
|
||||
|
||||
public enum NumberParticipants
|
||||
{
|
||||
NOT_SPECIFIED,
|
||||
|
||||
PEER_TO_PEER, // 2 participants
|
||||
|
||||
SMALL_GROUP, // 3 - 5 participants
|
||||
LARGE_GROUP, // 6 - 12 participants
|
||||
MULTIPLE_SMALL_GROUPS, // 13 - 20 participants
|
||||
MULTIPLE_LARGE_GROUPS, // 21 - 30 participants
|
||||
|
||||
SYMPOSIUM, // 31 - 100 participants
|
||||
CONFERENCE, // 101 - 200 participants
|
||||
CONGRESS, // 201 - 1000 participants
|
||||
LARGE_EVENT, // 1000+ participants
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace AIStudio.Assistants.Agenda;
|
||||
|
||||
public static class NumberParticipantsExtensions
|
||||
{
|
||||
public static string Name(this NumberParticipants numberParticipants) => numberParticipants switch
|
||||
{
|
||||
NumberParticipants.NOT_SPECIFIED => "Please select how many participants are expected",
|
||||
|
||||
NumberParticipants.PEER_TO_PEER => "2 (peer to peer)",
|
||||
|
||||
NumberParticipants.SMALL_GROUP => "3 - 5 (small group)",
|
||||
NumberParticipants.LARGE_GROUP => "6 - 12 (large group)",
|
||||
NumberParticipants.MULTIPLE_SMALL_GROUPS => "13 - 20 (multiple small groups)",
|
||||
NumberParticipants.MULTIPLE_LARGE_GROUPS => "21 - 30 (multiple large groups)",
|
||||
|
||||
NumberParticipants.SYMPOSIUM => "31 - 100 (symposium)",
|
||||
NumberParticipants.CONFERENCE => "101 - 200 (conference)",
|
||||
NumberParticipants.CONGRESS => "201 - 1,000 (congress)",
|
||||
|
||||
NumberParticipants.LARGE_EVENT => "1,000+ (large event)",
|
||||
|
||||
_ => "Unknown"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
@using AIStudio.Chat
|
||||
@inherits AssistantLowerBase
|
||||
@typeparam TSettings
|
||||
|
||||
<div class="inner-scrolling-context">
|
||||
|
||||
<MudText Typo="Typo.h3" Class="mb-2 mr-3">
|
||||
@(this.Title)
|
||||
</MudText>
|
||||
|
||||
<InnerScrolling>
|
||||
<ChildContent>
|
||||
<MudForm @ref="@(this.form)" @bind-IsValid="@(this.inputIsValid)" @bind-Errors="@(this.inputIssues)" FieldChanged="@this.TriggerFormChange" Class="pr-2">
|
||||
<MudGrid Class="mb-2">
|
||||
<MudItem xs="10">
|
||||
<MudText Typo="Typo.body1" Align="Align.Justify">
|
||||
@this.Description
|
||||
</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="2" Class="d-flex justify-end align-start">
|
||||
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Settings" OnClick="() => this.OpenSettingsDialog()"/>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@if (this.Body is not null)
|
||||
{
|
||||
<CascadingValue Value="@this">
|
||||
@this.Body
|
||||
</CascadingValue>
|
||||
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.Start" Class="mb-3">
|
||||
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" OnClick="() => this.SubmitAction()" Style="@this.SubmitButtonStyle">
|
||||
@this.SubmitText
|
||||
</MudButton>
|
||||
@if (this.isProcessing && this.cancellationTokenSource is not null)
|
||||
{
|
||||
<MudTooltip Text="Stop generation">
|
||||
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="() => this.CancelStreaming()"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
</MudStack>
|
||||
}
|
||||
</MudForm>
|
||||
<Issues IssuesData="@(this.inputIssues)"/>
|
||||
|
||||
@if (this.ShowDedicatedProgress && this.isProcessing)
|
||||
{
|
||||
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="mb-6" />
|
||||
}
|
||||
|
||||
<div id="@RESULT_DIV_ID" class="mr-2 mt-3">
|
||||
</div>
|
||||
|
||||
<div id="@BEFORE_RESULT_DIV_ID" class="mt-3">
|
||||
</div>
|
||||
|
||||
@if (this.ShowResult && !this.ShowEntireChatThread && this.resultingContentBlock is not null)
|
||||
{
|
||||
<ContentBlockComponent Role="@(this.resultingContentBlock.Role)" Type="@(this.resultingContentBlock.ContentType)" Time="@(this.resultingContentBlock.Time)" Content="@(this.resultingContentBlock.Content)"/>
|
||||
}
|
||||
|
||||
@if(this.ShowResult && this.ShowEntireChatThread && this.chatThread is not null)
|
||||
{
|
||||
foreach (var block in this.chatThread.Blocks.OrderBy(n => n.Time))
|
||||
{
|
||||
@if (!block.HideFromUser)
|
||||
{
|
||||
<ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content"/>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<div id="@AFTER_RESULT_DIV_ID" class="mt-3">
|
||||
</div>
|
||||
</ChildContent>
|
||||
<FooterContent>
|
||||
<MudStack Row="@true" Wrap="Wrap.Wrap" Class="ma-1">
|
||||
|
||||
@if (!this.FooterButtons.Any(x => x.Type is ButtonTypes.SEND_TO))
|
||||
{
|
||||
@if (this.ShowSendTo)
|
||||
{
|
||||
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
|
||||
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
|
||||
{
|
||||
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, new())">
|
||||
@assistant.Name()
|
||||
</MudMenuItem>
|
||||
}
|
||||
</MudMenu>
|
||||
}
|
||||
}
|
||||
|
||||
@foreach (var button in this.FooterButtons)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case ButtonData buttonData when !string.IsNullOrWhiteSpace(buttonData.Tooltip):
|
||||
<MudTooltip Text="@buttonData.Tooltip">
|
||||
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
|
||||
@buttonData.Text
|
||||
</MudButton>
|
||||
</MudTooltip>
|
||||
break;
|
||||
|
||||
case ButtonData buttonData:
|
||||
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
|
||||
@buttonData.Text
|
||||
</MudButton>
|
||||
break;
|
||||
|
||||
case SendToButton sendToButton:
|
||||
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
|
||||
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
|
||||
{
|
||||
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, sendToButton)">
|
||||
@assistant.Name()
|
||||
</MudMenuItem>
|
||||
}
|
||||
</MudMenu>
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@if (this.ShowCopyResult)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="() => this.CopyToClipboard()">
|
||||
Copy result
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
@if (this.ShowReset)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@Icons.Material.Filled.Refresh" OnClick="() => this.InnerResetForm()">
|
||||
Reset
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
@if (this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence)
|
||||
{
|
||||
<ConfidenceInfo Mode="PopoverTriggerMode.BUTTON" LLMProvider="@this.providerSettings.UsedLLMProvider"/>
|
||||
}
|
||||
|
||||
@if (this.AllowProfiles && this.ShowProfileSelection)
|
||||
{
|
||||
<ProfileSelection MarginLeft="" @bind-CurrentProfile="@this.currentProfile"/>
|
||||
}
|
||||
</MudStack>
|
||||
</FooterContent>
|
||||
</InnerScrolling>
|
||||
</div>
|
||||
@@ -0,0 +1,405 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
using MudBlazor.Utilities;
|
||||
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
||||
|
||||
namespace AIStudio.Assistants;
|
||||
|
||||
public abstract partial class AssistantBase<TSettings> : AssistantLowerBase, IMessageBusReceiver, IDisposable where TSettings : IComponent
|
||||
{
|
||||
[Inject]
|
||||
protected SettingsManager SettingsManager { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JsRuntime { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ThreadSafeRandom RNG { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected NavigationManager NavigationManager { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ILogger<AssistantBase<TSettings>> Logger { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private MudTheme ColorTheme { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private MessageBus MessageBus { get; init; } = null!;
|
||||
|
||||
protected abstract string Title { get; }
|
||||
|
||||
protected abstract string Description { get; }
|
||||
|
||||
protected abstract string SystemPrompt { get; }
|
||||
|
||||
public abstract Tools.Components Component { get; }
|
||||
|
||||
protected virtual Func<string> Result2Copy => () => this.resultingContentBlock is null ? string.Empty : this.resultingContentBlock.Content switch
|
||||
{
|
||||
ContentText textBlock => textBlock.Text,
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
protected abstract void ResetForm();
|
||||
|
||||
protected abstract bool MightPreselectValues();
|
||||
|
||||
protected abstract string SubmitText { get; }
|
||||
|
||||
protected abstract Func<Task> SubmitAction { get; }
|
||||
|
||||
protected virtual bool SubmitDisabled => false;
|
||||
|
||||
private protected virtual RenderFragment? Body => null;
|
||||
|
||||
protected virtual bool ShowResult => true;
|
||||
|
||||
protected virtual bool ShowEntireChatThread => false;
|
||||
|
||||
protected virtual bool AllowProfiles => true;
|
||||
|
||||
protected virtual bool ShowProfileSelection => true;
|
||||
|
||||
protected virtual bool ShowDedicatedProgress => false;
|
||||
|
||||
protected virtual bool ShowSendTo => true;
|
||||
|
||||
protected virtual bool ShowCopyResult => true;
|
||||
|
||||
protected virtual bool ShowReset => true;
|
||||
|
||||
protected virtual ChatThread ConvertToChatThread => this.chatThread ?? new();
|
||||
|
||||
protected virtual IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected AIStudio.Settings.Provider providerSettings;
|
||||
protected MudForm? form;
|
||||
protected bool inputIsValid;
|
||||
protected Profile currentProfile = Profile.NO_PROFILE;
|
||||
protected ChatThread? chatThread;
|
||||
protected IContent? lastUserPrompt;
|
||||
|
||||
private readonly Timer formChangeTimer = new(TimeSpan.FromSeconds(1.6));
|
||||
|
||||
private CancellationTokenSource? cancellationTokenSource;
|
||||
private ContentBlock? resultingContentBlock;
|
||||
private string[] inputIssues = [];
|
||||
private bool isProcessing;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
this.formChangeTimer.AutoReset = false;
|
||||
this.formChangeTimer.Elapsed += async (_, _) =>
|
||||
{
|
||||
this.formChangeTimer.Stop();
|
||||
await this.OnFormChange();
|
||||
};
|
||||
|
||||
this.MightPreselectValues();
|
||||
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
|
||||
this.currentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
|
||||
|
||||
this.MessageBus.RegisterComponent(this);
|
||||
this.MessageBus.ApplyFilters(this, [], [ Event.COLOR_THEME_CHANGED ]);
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
// Configure the spellchecking for the user input:
|
||||
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
|
||||
|
||||
await base.OnParametersSetAsync();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
// Reset the validation when not editing and on the first render.
|
||||
// We don't want to show validation errors when the user opens the dialog.
|
||||
if(firstRender)
|
||||
this.form?.ResetValidation();
|
||||
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IMessageBusReceiver
|
||||
|
||||
public string ComponentName => nameof(AssistantBase<TSettings>);
|
||||
|
||||
public Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data)
|
||||
{
|
||||
switch (triggeredEvent)
|
||||
{
|
||||
case Event.COLOR_THEME_CHANGED:
|
||||
this.StateHasChanged();
|
||||
break;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||
{
|
||||
return Task.FromResult<TResult?>(default);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string SubmitButtonStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.providerSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).StyleBorder(this.SettingsManager) : string.Empty;
|
||||
|
||||
protected string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
if(provider.UsedLLMProvider == LLMProviders.NONE)
|
||||
return "Please select a provider.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void TriggerFormChange(FormFieldChangedEventArgs _)
|
||||
{
|
||||
this.formChangeTimer.Stop();
|
||||
this.formChangeTimer.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after any form field has changed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is called after a delay of 1.6 seconds. This is to prevent
|
||||
/// the method from being called too often. This method is called after
|
||||
/// the user has stopped typing or selecting options.
|
||||
/// </remarks>
|
||||
protected virtual Task OnFormChange() => Task.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Add an issue to the UI.
|
||||
/// </summary>
|
||||
/// <param name="issue">The issue to add.</param>
|
||||
protected void AddInputIssue(string issue)
|
||||
{
|
||||
Array.Resize(ref this.inputIssues, this.inputIssues.Length + 1);
|
||||
this.inputIssues[^1] = issue;
|
||||
this.inputIsValid = false;
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
protected void CreateChatThread()
|
||||
{
|
||||
this.chatThread = new()
|
||||
{
|
||||
SelectedProvider = this.providerSettings.Id,
|
||||
SelectedProfile = this.AllowProfiles ? this.currentProfile.Id : Profile.NO_PROFILE.Id,
|
||||
SystemPrompt = this.SystemPrompt,
|
||||
WorkspaceId = Guid.Empty,
|
||||
ChatId = Guid.NewGuid(),
|
||||
Name = $"Assistant - {this.Title}",
|
||||
Seed = this.RNG.Next(),
|
||||
Blocks = [],
|
||||
};
|
||||
}
|
||||
|
||||
protected Guid CreateChatThread(Guid workspaceId, string name)
|
||||
{
|
||||
var chatId = Guid.NewGuid();
|
||||
this.chatThread = new()
|
||||
{
|
||||
SelectedProvider = this.providerSettings.Id,
|
||||
SelectedProfile = this.AllowProfiles ? this.currentProfile.Id : Profile.NO_PROFILE.Id,
|
||||
SystemPrompt = this.SystemPrompt,
|
||||
WorkspaceId = workspaceId,
|
||||
ChatId = chatId,
|
||||
Name = name,
|
||||
Seed = this.RNG.Next(),
|
||||
Blocks = [],
|
||||
};
|
||||
|
||||
return chatId;
|
||||
}
|
||||
|
||||
protected DateTimeOffset AddUserRequest(string request, bool hideContentFromUser = false)
|
||||
{
|
||||
var time = DateTimeOffset.Now;
|
||||
this.lastUserPrompt = new ContentText
|
||||
{
|
||||
Text = request,
|
||||
};
|
||||
|
||||
this.chatThread!.Blocks.Add(new ContentBlock
|
||||
{
|
||||
Time = time,
|
||||
ContentType = ContentType.TEXT,
|
||||
HideFromUser = hideContentFromUser,
|
||||
Role = ChatRole.USER,
|
||||
Content = this.lastUserPrompt,
|
||||
});
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideContentFromUser = false)
|
||||
{
|
||||
var aiText = new ContentText
|
||||
{
|
||||
// We have to wait for the remote
|
||||
// for the content stream:
|
||||
InitialRemoteWait = true,
|
||||
};
|
||||
|
||||
this.resultingContentBlock = new ContentBlock
|
||||
{
|
||||
Time = time,
|
||||
ContentType = ContentType.TEXT,
|
||||
Role = ChatRole.AI,
|
||||
Content = aiText,
|
||||
HideFromUser = hideContentFromUser,
|
||||
};
|
||||
|
||||
if (this.chatThread is not null)
|
||||
{
|
||||
this.chatThread.Blocks.Add(this.resultingContentBlock);
|
||||
this.chatThread.SelectedProvider = this.providerSettings.Id;
|
||||
}
|
||||
|
||||
this.isProcessing = true;
|
||||
this.StateHasChanged();
|
||||
|
||||
using (this.cancellationTokenSource = new())
|
||||
{
|
||||
// Use the selected provider to get the AI response.
|
||||
// By awaiting this line, we wait for the entire
|
||||
// content to be streamed.
|
||||
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(this.Logger), this.providerSettings.Model, this.lastUserPrompt, this.chatThread, this.cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
this.cancellationTokenSource = null;
|
||||
this.isProcessing = false;
|
||||
this.StateHasChanged();
|
||||
|
||||
// Return the AI response:
|
||||
return aiText.Text;
|
||||
}
|
||||
|
||||
private async Task CancelStreaming()
|
||||
{
|
||||
if (this.cancellationTokenSource is not null)
|
||||
if(!this.cancellationTokenSource.IsCancellationRequested)
|
||||
await this.cancellationTokenSource.CancelAsync();
|
||||
}
|
||||
|
||||
protected async Task CopyToClipboard()
|
||||
{
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy());
|
||||
}
|
||||
|
||||
private static string? GetButtonIcon(string icon)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(icon))
|
||||
return null;
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
protected async Task OpenSettingsDialog()
|
||||
{
|
||||
var dialogParameters = new DialogParameters();
|
||||
await this.DialogService.ShowAsync<TSettings>(null, dialogParameters, DialogOptions.FULLSCREEN);
|
||||
}
|
||||
|
||||
protected Task SendToAssistant(Tools.Components destination, SendToButton sendToButton)
|
||||
{
|
||||
if (!destination.AllowSendTo())
|
||||
return Task.CompletedTask;
|
||||
|
||||
var contentToSend = sendToButton == default ? string.Empty : sendToButton.UseResultingContentBlockData switch
|
||||
{
|
||||
false => sendToButton.GetText(),
|
||||
true => this.resultingContentBlock?.Content switch
|
||||
{
|
||||
ContentText textBlock => textBlock.Text,
|
||||
_ => string.Empty,
|
||||
},
|
||||
};
|
||||
|
||||
var sendToData = destination.GetData();
|
||||
switch (destination)
|
||||
{
|
||||
case Tools.Components.CHAT:
|
||||
var convertedChatThread = this.ConvertToChatThread;
|
||||
convertedChatThread = convertedChatThread with { SelectedProvider = this.providerSettings.Id };
|
||||
MessageBus.INSTANCE.DeferMessage(this, sendToData.Event, convertedChatThread);
|
||||
break;
|
||||
|
||||
default:
|
||||
MessageBus.INSTANCE.DeferMessage(this, sendToData.Event, contentToSend);
|
||||
break;
|
||||
}
|
||||
|
||||
this.NavigationManager.NavigateTo(sendToData.Route);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task InnerResetForm()
|
||||
{
|
||||
this.resultingContentBlock = null;
|
||||
this.providerSettings = default;
|
||||
|
||||
await this.JsRuntime.ClearDiv(RESULT_DIV_ID);
|
||||
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);
|
||||
|
||||
this.ResetForm();
|
||||
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
|
||||
|
||||
this.inputIsValid = false;
|
||||
this.inputIssues = [];
|
||||
|
||||
this.form?.ResetValidation();
|
||||
this.StateHasChanged();
|
||||
this.form?.ResetValidation();
|
||||
}
|
||||
|
||||
private string GetResetColor() => this.SettingsManager.IsDarkMode switch
|
||||
{
|
||||
true => $"background-color: #804000",
|
||||
false => $"background-color: {this.ColorTheme.GetCurrentPalette(this.SettingsManager).Warning.Value}",
|
||||
};
|
||||
|
||||
private string GetSendToColor() => this.SettingsManager.IsDarkMode switch
|
||||
{
|
||||
true => $"background-color: #004080",
|
||||
false => $"background-color: {this.ColorTheme.GetCurrentPalette(this.SettingsManager).InfoLighten}",
|
||||
};
|
||||
|
||||
#region Implementation of IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.MessageBus.Unregister(this);
|
||||
this.formChangeTimer.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
namespace AIStudio.Assistants;
|
||||
|
||||
//
|
||||
// See https://stackoverflow.com/a/77300384/2258393 for why this class is needed
|
||||
// See https://stackoverflow.com/a/77300384/2258393 for why this class is necessary
|
||||
//
|
||||
|
||||
public abstract class AssistantBaseCore : AssistantBase
|
||||
public abstract class AssistantBaseCore<TSettings> : AssistantBase<TSettings> where TSettings : IComponent
|
||||
{
|
||||
private protected sealed override RenderFragment Body => this.BuildRenderTree;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Assistants;
|
||||
|
||||
public abstract class AssistantLowerBase : ComponentBase
|
||||
{
|
||||
protected static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new();
|
||||
|
||||
internal const string RESULT_DIV_ID = "assistantResult";
|
||||
internal const string BEFORE_RESULT_DIV_ID = "beforeAssistantResult";
|
||||
internal const string AFTER_RESULT_DIV_ID = "afterAssistantResult";
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
@attribute [Route(Routes.ASSISTANT_BIAS)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogAssistantBias>
|
||||
|
||||
<MudText Typo="Typo.body1">
|
||||
<b>Links:</b>
|
||||
</MudText>
|
||||
<MudList T="string" Class="mb-6">
|
||||
<MudListItem T="string" Icon="@Icons.Material.Filled.Link" Target="_blank" Href="https://en.wikipedia.org/wiki/List_of_cognitive_biases">Wikipedia list of cognitive biases</MudListItem>
|
||||
<MudListItem T="string" Icon="@Icons.Material.Filled.Link" Target="_blank" Href="https://commons.wikimedia.org/wiki/File:Cognitive_Bias_Codex_With_Definitions_1-2,_an_Extension_of_the_work_of_John_Manoogian_by_Brian_Rene_Morrissette.png">Extended bias poster</MudListItem>
|
||||
<MudListItem T="string" Icon="@Icons.Material.Filled.Link" Target="_blank" Href="https://betterhumans.pub/cognitive-bias-cheat-sheet-55a472476b18">Blog post of Buster Benson: "Cognitive bias cheat sheet"</MudListItem>
|
||||
</MudList>
|
||||
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidateTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,165 @@
|
||||
using System.Text;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
namespace AIStudio.Assistants.BiasDay;
|
||||
|
||||
public partial class BiasOfTheDayAssistant : AssistantBaseCore<SettingsDialogAssistantBias>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.BIAS_DAY_ASSISTANT;
|
||||
|
||||
protected override string Title => "Bias of the Day";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Learn about a different cognitive bias every day. You can also ask the LLM your questions. The idea behind
|
||||
"Bias of the Day" is based on work by Buster Benson, John Manoogian III, and Brian Rene Morrissette. Buster
|
||||
Benson grouped the biases, and the original texts come from Wikipedia. Brian Rene Morrissette condensed them
|
||||
into a shorter version. Finally, John Manoogian III created the original poster based on Benson's work and
|
||||
Morrissette's texts. Thorsten Sommer compared all texts for integration into AI Studio with the current Wikipedia
|
||||
versions, updated them, and added source references. The idea of learning about one bias each day based on John's
|
||||
poster comes from Drew Nelson.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt => $"""
|
||||
You are a friendly, helpful expert on cognitive bias. You studied psychology and
|
||||
have a lot of experience. You explain a bias every day. Today's bias belongs to
|
||||
the category: "{this.biasOfTheDay.Category.ToName()}". We have the following
|
||||
thoughts on this category:
|
||||
|
||||
{this.biasOfTheDay.Category.GetThoughts()}
|
||||
|
||||
Today's bias is:
|
||||
{this.biasOfTheDay.Description}
|
||||
{this.SystemPromptSources()}
|
||||
Important: you use the following language: {this.SystemPromptLanguage()}. Please
|
||||
ask the user a personal question at the end to encourage them to think about
|
||||
this bias.
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Show me the bias of the day";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.TellBias;
|
||||
|
||||
protected override bool ShowSendTo => false;
|
||||
|
||||
protected override bool ShowCopyResult => false;
|
||||
|
||||
protected override bool ShowReset => false;
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.BiasOfTheDay.PreselectOptions)
|
||||
{
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.BiasOfTheDay.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.BiasOfTheDay.PreselectedOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Bias biasOfTheDay = BiasCatalog.NONE;
|
||||
private CommonLanguages selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
|
||||
private string? ValidateTargetLanguage(CommonLanguages language)
|
||||
{
|
||||
if(language is CommonLanguages.AS_IS)
|
||||
return "Please select a target language for the bias.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string SystemPromptSources()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (this.biasOfTheDay.Links.Count > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Please share the following sources with the user as a Markdown list:");
|
||||
foreach (var link in this.biasOfTheDay.Links)
|
||||
sb.AppendLine($"- {link}");
|
||||
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
if(this.selectedTargetLanguage is CommonLanguages.OTHER)
|
||||
return this.customTargetLanguage;
|
||||
|
||||
return this.selectedTargetLanguage.Name();
|
||||
}
|
||||
|
||||
private async Task TellBias()
|
||||
{
|
||||
bool useDrawnBias = false;
|
||||
if(this.SettingsManager.ConfigurationData.BiasOfTheDay.RestrictOneBiasPerDay)
|
||||
{
|
||||
if(this.SettingsManager.ConfigurationData.BiasOfTheDay.DateLastBiasDrawn == DateOnly.FromDateTime(DateTime.Now))
|
||||
{
|
||||
var biasChat = new LoadChat
|
||||
{
|
||||
WorkspaceId = KnownWorkspaces.BIAS_WORKSPACE_ID,
|
||||
ChatId = this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayChatId,
|
||||
};
|
||||
|
||||
if (WorkspaceBehaviour.IsChatExisting(biasChat))
|
||||
{
|
||||
MessageBus.INSTANCE.DeferMessage(this, Event.LOAD_CHAT, biasChat);
|
||||
this.NavigationManager.NavigateTo(Routes.CHAT);
|
||||
return;
|
||||
}
|
||||
else
|
||||
useDrawnBias = true;
|
||||
}
|
||||
}
|
||||
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.biasOfTheDay = useDrawnBias ?
|
||||
BiasCatalog.ALL_BIAS[this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayId] :
|
||||
BiasCatalog.GetRandomBias(this.SettingsManager.ConfigurationData.BiasOfTheDay.UsedBias);
|
||||
|
||||
var chatId = this.CreateChatThread(KnownWorkspaces.BIAS_WORKSPACE_ID, this.biasOfTheDay.Name);
|
||||
this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayId = this.biasOfTheDay.Id;
|
||||
this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayChatId = chatId;
|
||||
this.SettingsManager.ConfigurationData.BiasOfTheDay.DateLastBiasDrawn = DateOnly.FromDateTime(DateTime.Now);
|
||||
await this.SettingsManager.StoreSettings();
|
||||
var time = this.AddUserRequest(
|
||||
"""
|
||||
Please tell me about the bias of the day.
|
||||
""", true);
|
||||
|
||||
// Start the AI response without waiting for it to finish:
|
||||
_ = this.AddAIResponseAsync(time);
|
||||
await this.SendToAssistant(Tools.Components.CHAT, default);
|
||||
}
|
||||
}
|
||||
+6
-18
@@ -1,12 +1,12 @@
|
||||
@page "/assistant/coding"
|
||||
@using AIStudio.Settings
|
||||
@inherits AssistantBaseCore
|
||||
@attribute [Route(Routes.ASSISTANT_CODING)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogCoding>
|
||||
|
||||
<MudExpansionPanels Class="mb-3">
|
||||
@for (var contextIndex = 0; contextIndex < this.codingContexts.Count; contextIndex++)
|
||||
{
|
||||
var codingContext = this.codingContexts[contextIndex];
|
||||
<ExpansionPanel HeaderText="@codingContext.Id" HeaderIcon="@Icons.Material.Filled.Code">
|
||||
var index = contextIndex;
|
||||
<ExpansionPanel HeaderText="@codingContext.Id" HeaderIcon="@Icons.Material.Filled.Code" ShowEndButton="@true" EndButtonColor="Color.Error" EndButtonIcon="@Icons.Material.Filled.Delete" EndButtonTooltip="Delete context" EndButtonClickAsync="@(() => this.DeleteContext(index))">
|
||||
<CodingContextItem @bind-CodingContext="@codingContext"/>
|
||||
</ExpansionPanel>
|
||||
}
|
||||
@@ -16,9 +16,7 @@
|
||||
</MudButton>
|
||||
|
||||
<MudStack Row="@false" Class="mb-3">
|
||||
<MudSwitch T="bool" @bind-Value="@this.provideCompilerMessages" Color="Color.Primary">
|
||||
@(this.provideCompilerMessages ? "Provide compiler messages" : "Provide no compiler messages")
|
||||
</MudSwitch>
|
||||
<MudTextSwitch Label="Do you want to provide compiler messages?" @bind-Value="@this.provideCompilerMessages" LabelOn="Yes, provide compiler messages" LabelOff="No, there are no compiler messages" />
|
||||
@if (this.provideCompilerMessages)
|
||||
{
|
||||
<MudTextField T="string" @bind-Text="@this.compilerMessages" Validation="@this.ValidatingCompilerMessages" AdornmentIcon="@Icons.Material.Filled.Error" Adornment="Adornment.Start" Label="Compiler messages" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
@@ -26,14 +24,4 @@
|
||||
</MudStack>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.questions" Validation="@this.ValidateQuestions" AdornmentIcon="@Icons.Material.Filled.QuestionMark" Adornment="Adornment.Start" Label="Your question(s)" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
|
||||
<MudSelect T="Provider" @bind-Value="@this.providerSettings" Validation="@this.ValidatingProvider" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Apps" Margin="Margin.Dense" Label="Provider" Class="mb-3 rounded-lg" Variant="Variant.Outlined">
|
||||
@foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
||||
{
|
||||
<MudSelectItem Value="@provider"/>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" OnClick="() => this.GetSupport()" Class="mb-3">
|
||||
Get support
|
||||
</MudButton>
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
+58
-12
@@ -1,9 +1,13 @@
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
public partial class AssistantCoding : AssistantBaseCore
|
||||
namespace AIStudio.Assistants.Coding;
|
||||
|
||||
public partial class AssistantCoding : AssistantBaseCore<SettingsDialogCoding>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.CODING_ASSISTANT;
|
||||
|
||||
protected override string Title => "Coding Assistant";
|
||||
|
||||
protected override string Description =>
|
||||
@@ -24,6 +28,34 @@ public partial class AssistantCoding : AssistantBaseCore
|
||||
When the user asks in a different language than English, you answer in the same language!
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Get Support";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.GetSupport;
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.codingContexts.Clear();
|
||||
this.compilerMessages = string.Empty;
|
||||
this.questions = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.provideCompilerMessages = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.Coding.PreselectOptions)
|
||||
{
|
||||
this.provideCompilerMessages = this.SettingsManager.ConfigurationData.Coding.PreselectCompilerMessages;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private readonly List<CodingContext> codingContexts = new();
|
||||
private bool provideCompilerMessages;
|
||||
private string compilerMessages = string.Empty;
|
||||
@@ -33,11 +65,9 @@ public partial class AssistantCoding : AssistantBaseCore
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.PreselectCodingOptions)
|
||||
{
|
||||
this.provideCompilerMessages = this.SettingsManager.ConfigurationData.PreselectCodingCompilerMessages;
|
||||
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.PreselectedCodingProvider);
|
||||
}
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_CODING_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.questions = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
@@ -68,11 +98,23 @@ public partial class AssistantCoding : AssistantBaseCore
|
||||
this.codingContexts.Add(new()
|
||||
{
|
||||
Id = $"Context {this.codingContexts.Count + 1}",
|
||||
Language = this.SettingsManager.ConfigurationData.PreselectCodingOptions ? this.SettingsManager.ConfigurationData.PreselectedCodingLanguage : default,
|
||||
OtherLanguage = this.SettingsManager.ConfigurationData.PreselectCodingOptions ? this.SettingsManager.ConfigurationData.PreselectedCodingOtherLanguage : string.Empty,
|
||||
Language = this.SettingsManager.ConfigurationData.Coding.PreselectOptions ? this.SettingsManager.ConfigurationData.Coding.PreselectedProgrammingLanguage : default,
|
||||
OtherLanguage = this.SettingsManager.ConfigurationData.Coding.PreselectOptions ? this.SettingsManager.ConfigurationData.Coding.PreselectedOtherProgrammingLanguage : string.Empty,
|
||||
});
|
||||
}
|
||||
|
||||
private ValueTask DeleteContext(int index)
|
||||
{
|
||||
if(this.codingContexts.Count < index + 1)
|
||||
return ValueTask.CompletedTask;
|
||||
|
||||
this.codingContexts.RemoveAt(index);
|
||||
this.form?.ResetValidation();
|
||||
|
||||
this.StateHasChanged();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task GetSupport()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
@@ -87,9 +129,13 @@ public partial class AssistantCoding : AssistantBaseCore
|
||||
foreach (var codingContext in this.codingContexts)
|
||||
{
|
||||
sbContext.AppendLine($"ID: {codingContext.Id}");
|
||||
sbContext.AppendLine($"Language: {codingContext.Language.Name()}");
|
||||
sbContext.AppendLine($"Other Language: {codingContext.OtherLanguage}");
|
||||
sbContext.AppendLine($"Content:");
|
||||
|
||||
if(codingContext.Language is not CommonCodingLanguages.OTHER)
|
||||
sbContext.AppendLine($"Language: {codingContext.Language.Name()}");
|
||||
else
|
||||
sbContext.AppendLine($"Language: {codingContext.OtherLanguage}");
|
||||
|
||||
sbContext.AppendLine("Content:");
|
||||
sbContext.AppendLine("```");
|
||||
sbContext.AppendLine(codingContext.Code);
|
||||
sbContext.AppendLine("```");
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
namespace AIStudio.Assistants.Coding;
|
||||
|
||||
public sealed class CodingContext(string id, CommonCodingLanguages language, string otherLanguage, string code)
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<MudTextField T="string" @bind-Text="@this.CodingContext.Id" AdornmentIcon="@Icons.Material.Filled.Numbers" Adornment="Adornment.Start" Label="(Optional) Identifier" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
<MudStack Row="@true" AlignItems="AlignItems.Center" Class="mb-3">
|
||||
<MudStack Row="@true" Class="mb-3">
|
||||
<MudSelect T="CommonCodingLanguages" @bind-Value="@this.CodingContext.Language" AdornmentIcon="@Icons.Material.Filled.Code" Adornment="Adornment.Start" Label="Language" Variant="Variant.Outlined" Margin="Margin.Dense">
|
||||
@foreach (var language in Enum.GetValues<CommonCodingLanguages>())
|
||||
{
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
namespace AIStudio.Assistants.Coding;
|
||||
|
||||
public partial class CodingContextItem : ComponentBase
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
namespace AIStudio.Assistants.Coding;
|
||||
|
||||
public static class CommonCodingLanguageExtensions
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
namespace AIStudio.Assistants.Coding;
|
||||
|
||||
public enum CommonCodingLanguages
|
||||
{
|
||||
@@ -0,0 +1,23 @@
|
||||
@attribute [Route(Routes.ASSISTANT_EMAIL)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogWritingEMails>
|
||||
|
||||
<MudTextSwitch Label="Is there a history, a previous conversation?" @bind-Value="@this.provideHistory" LabelOn="Yes, I provide the previous conversation" LabelOff="No, I don't provide a previous conversation" />
|
||||
@if (this.provideHistory)
|
||||
{
|
||||
<MudPaper Class="pa-3 mb-8 border-dashed border rounded-lg">
|
||||
<MudTextField T="string" @bind-Text="@this.inputHistory" Validation="@this.ValidateHistory" Label="Previous conversation" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Provide the previous conversation, e.g., the last e-mail, the last chat, etc." Class="mb-3" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.DocumentScanner"/>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputGreeting" Label="(Optional) The greeting phrase to use" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Person" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Placeholder="Dear Colleagues" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputBulletPoints" Validation="@this.ValidateBulletPoints" AdornmentIcon="@Icons.Material.Filled.ListAlt" Adornment="Adornment.Start" Label="Your bullet points" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Bullet list the content of the e-mail roughly. Use dashes (-) to separate the items." Immediate="@false" DebounceInterval="1_000" OnDebounceIntervalElapsed="@this.OnContentChanged" Placeholder="@PLACEHOLDER_BULLET_POINTS"/>
|
||||
<MudSelect T="string" Label="(Optional) Are any of your points particularly important?" MultiSelection="@true" @bind-SelectedValues="@this.selectedFoci" Variant="Variant.Outlined" Class="mb-3" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.ListAlt">
|
||||
@foreach (var contentLine in this.bulletPointsLines)
|
||||
{
|
||||
<MudSelectItem T="string" Value="@contentLine">@contentLine</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudTextField T="string" @bind-Text="@this.inputName" Label="(Optional) Your name for the closing salutation" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Person" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Your name for the closing salutation of your e-mail." Class="mb-3"/>
|
||||
<EnumSelection T="WritingStyles" NameFunc="@(style => style.Name())" @bind-Value="@this.selectedWritingStyle" Icon="@Icons.Material.Filled.Edit" Label="Select the writing style" ValidateSelection="@this.ValidateWritingStyle"/>
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidateTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,250 @@
|
||||
using System.Text;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.EMail;
|
||||
|
||||
public partial class AssistantEMail : AssistantBaseCore<SettingsDialogWritingEMails>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.EMAIL_ASSISTANT;
|
||||
|
||||
protected override string Title => "E-Mail";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Provide a list of bullet points and some basic information for an e-mail. The assistant will generate an e-mail based on that input.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You are an automated system that writes emails. {this.SystemPromptHistory()} The user provides you with bullet points on what
|
||||
he want to address in the response. Regarding the writing style of the email: {this.selectedWritingStyle.Prompt()}
|
||||
{this.SystemPromptGreeting()} {this.SystemPromptName()} You write the email in the following language: {this.SystemPromptLanguage()}.
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Create email";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.CreateMail;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputBulletPoints = string.Empty;
|
||||
this.bulletPointsLines.Clear();
|
||||
this.selectedFoci = [];
|
||||
this.provideHistory = false;
|
||||
this.inputHistory = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.inputName = string.Empty;
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
this.selectedWritingStyle = WritingStyles.NONE;
|
||||
this.inputGreeting = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.EMail.PreselectOptions)
|
||||
{
|
||||
this.inputName = this.SettingsManager.ConfigurationData.EMail.SenderName;
|
||||
this.inputGreeting = this.SettingsManager.ConfigurationData.EMail.Greeting;
|
||||
this.selectedWritingStyle = this.SettingsManager.ConfigurationData.EMail.PreselectedWritingStyle;
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.EMail.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.EMail.PreselectOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private const string PLACEHOLDER_BULLET_POINTS = """
|
||||
- The last meeting was good
|
||||
- Thank you for feedback
|
||||
- Next is milestone 3
|
||||
- I need your input by next Wednesday
|
||||
""";
|
||||
|
||||
private WritingStyles selectedWritingStyle = WritingStyles.NONE;
|
||||
private string inputGreeting = string.Empty;
|
||||
private string inputBulletPoints = string.Empty;
|
||||
private readonly List<string> bulletPointsLines = [];
|
||||
private IEnumerable<string> selectedFoci = new HashSet<string>();
|
||||
private string inputName = string.Empty;
|
||||
private CommonLanguages selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
private bool provideHistory;
|
||||
private string inputHistory = string.Empty;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_EMAIL_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputBulletPoints = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidateBulletPoints(string content)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(content))
|
||||
return "Please provide some content for the e-mail.";
|
||||
|
||||
var lines = content.Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var line in lines)
|
||||
if(!line.TrimStart().StartsWith('-'))
|
||||
return "Please start each line of your content list with a dash (-) to create a bullet point list.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateTargetLanguage(CommonLanguages language)
|
||||
{
|
||||
if(language is CommonLanguages.AS_IS)
|
||||
return "Please select a target language for the e-mail.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateWritingStyle(WritingStyles style)
|
||||
{
|
||||
if(style == WritingStyles.NONE)
|
||||
return "Please select a writing style for the e-mail.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateHistory(string history)
|
||||
{
|
||||
if(this.provideHistory && string.IsNullOrWhiteSpace(history))
|
||||
return "Please provide some history for the e-mail.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void OnContentChanged(string content)
|
||||
{
|
||||
this.bulletPointsLines.Clear();
|
||||
var previousSelectedFoci = new HashSet<string>();
|
||||
foreach (var line in content.AsSpan().EnumerateLines())
|
||||
{
|
||||
var trimmedLine = line.Trim();
|
||||
if (trimmedLine.StartsWith("-"))
|
||||
trimmedLine = trimmedLine[1..].Trim();
|
||||
|
||||
if (trimmedLine.Length == 0)
|
||||
continue;
|
||||
|
||||
var finalLine = trimmedLine.ToString();
|
||||
if(this.selectedFoci.Any(x => x.StartsWith(finalLine, StringComparison.InvariantCultureIgnoreCase)))
|
||||
previousSelectedFoci.Add(finalLine);
|
||||
|
||||
this.bulletPointsLines.Add(finalLine);
|
||||
}
|
||||
|
||||
this.selectedFoci = previousSelectedFoci;
|
||||
}
|
||||
|
||||
private string SystemPromptHistory()
|
||||
{
|
||||
if (this.provideHistory)
|
||||
return "You receive the previous conversation as context.";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string SystemPromptGreeting()
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(this.inputGreeting))
|
||||
return $"Your greeting should consider the following formulation: {this.inputGreeting}.";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string SystemPromptName()
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(this.inputName))
|
||||
return $"For the closing phrase of the email, please use the following name: {this.inputName}.";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
if(this.selectedTargetLanguage is CommonLanguages.AS_IS)
|
||||
return "Use the same language as the input";
|
||||
|
||||
if(this.selectedTargetLanguage is CommonLanguages.OTHER)
|
||||
return this.customTargetLanguage;
|
||||
|
||||
return this.selectedTargetLanguage.Name();
|
||||
}
|
||||
|
||||
private string PromptFoci()
|
||||
{
|
||||
if(!this.selectedFoci.Any())
|
||||
return string.Empty;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("I want to amplify the following points:");
|
||||
foreach (var focus in this.selectedFoci)
|
||||
sb.AppendLine($"- {focus}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string PromptHistory()
|
||||
{
|
||||
if(!this.provideHistory)
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
The previous conversation was:
|
||||
|
||||
```
|
||||
{this.inputHistory}
|
||||
```
|
||||
""";
|
||||
}
|
||||
|
||||
private async Task CreateMail()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
{this.PromptHistory()}
|
||||
|
||||
My bullet points for the e-mail are:
|
||||
|
||||
{this.inputBulletPoints}
|
||||
|
||||
{this.PromptFoci()}
|
||||
""");
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AIStudio.Assistants.EMail;
|
||||
|
||||
public enum WritingStyles
|
||||
{
|
||||
NONE = 0,
|
||||
|
||||
BUSINESS_FORMAL,
|
||||
BUSINESS_INFORMAL,
|
||||
ACADEMIC,
|
||||
PERSONAL,
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace AIStudio.Assistants.EMail;
|
||||
|
||||
public static class WritingStylesExtensions
|
||||
{
|
||||
public static string Name(this WritingStyles style) => style switch
|
||||
{
|
||||
WritingStyles.ACADEMIC => "Academic",
|
||||
WritingStyles.PERSONAL => "Personal",
|
||||
WritingStyles.BUSINESS_FORMAL => "Business formal",
|
||||
WritingStyles.BUSINESS_INFORMAL => "Business informal",
|
||||
|
||||
_ => "Not specified",
|
||||
};
|
||||
|
||||
public static string Prompt(this WritingStyles style) => style switch
|
||||
{
|
||||
WritingStyles.ACADEMIC => "Use an academic style for communication in an academic context like between students and professors.",
|
||||
WritingStyles.PERSONAL => "Use a personal style for communication between friends and family.",
|
||||
WritingStyles.BUSINESS_FORMAL => "Use a formal business style for this e-mail.",
|
||||
WritingStyles.BUSINESS_INFORMAL => "Use an informal business style for this e-mail.",
|
||||
|
||||
_ => "Use a formal business style for this e-mail.",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public enum AllowedLLMProviders
|
||||
{
|
||||
NONE,
|
||||
|
||||
ANY,
|
||||
SELF_HOSTED,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public static class AllowedLLMProvidersExtensions
|
||||
{
|
||||
public static string Description(this AllowedLLMProviders provider) => provider switch
|
||||
{
|
||||
AllowedLLMProviders.NONE => "Please select what kind of LLM provider are allowed for this data source",
|
||||
AllowedLLMProviders.ANY => "Any LLM provider is allowed: users might choose a cloud-based or a self-hosted provider",
|
||||
AllowedLLMProviders.SELF_HOSTED => "Self-hosted LLM providers are allowed: users cannot choose any cloud-based provider",
|
||||
|
||||
_ => "Unknown option was selected"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
@attribute [Route(Routes.ASSISTANT_ERI)]
|
||||
@using AIStudio.Settings.DataModel
|
||||
@using MudExtensions
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogERIServer>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
You can imagine it like this: Hypothetically, when Wikipedia implemented the ERI, it would vectorize
|
||||
all pages using an embedding method. All of Wikipedia’s data would remain with Wikipedia, including the
|
||||
vector database (decentralized approach). Then, any AI Studio user could add Wikipedia as a data source to
|
||||
significantly reduce the hallucination of the LLM in knowledge questions.
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudText Typo="Typo.body1">
|
||||
<b>Related links:</b>
|
||||
</MudText>
|
||||
<MudList T="string" Class="mb-6">
|
||||
<MudListItem T="string" Icon="@Icons.Material.Filled.Link" Target="_blank" Href="https://github.com/MindWorkAI/ERI">ERI repository with example implementation in .NET and C#</MudListItem>
|
||||
<MudListItem T="string" Icon="@Icons.Material.Filled.Link" Target="_blank" Href="https://mindworkai.org/swagger-ui.html">Interactive documentation aka Swagger UI</MudListItem>
|
||||
</MudList>
|
||||
|
||||
<PreviewPrototype/>
|
||||
<div class="mb-6"></div>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-3">
|
||||
ERI server presets
|
||||
</MudText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
Here you have the option to save different configurations for various ERI servers and switch between them. This is useful if
|
||||
you are responsible for multiple ERI servers.
|
||||
</MudJustifiedText>
|
||||
|
||||
@if(this.SettingsManager.ConfigurationData.ERI.ERIServers.Count is 0)
|
||||
{
|
||||
<MudText Typo="Typo.body1" Class="mb-3">
|
||||
You have not yet added any ERI server presets.
|
||||
</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudList Disabled="@this.AreServerPresetsBlocked" T="DataERIServer" Class="mb-1" SelectedValue="@this.selectedERIServer" SelectedValueChanged="@this.SelectedERIServerChanged">
|
||||
@foreach (var server in this.SettingsManager.ConfigurationData.ERI.ERIServers)
|
||||
{
|
||||
<MudListItem T="DataERIServer" Icon="@Icons.Material.Filled.Settings" Value="@server">
|
||||
@server.ServerName
|
||||
</MudListItem>
|
||||
}
|
||||
</MudList>
|
||||
}
|
||||
|
||||
<MudStack Row="@true" Class="mt-1">
|
||||
<MudButton Disabled="@this.AreServerPresetsBlocked" OnClick="@this.AddERIServer" Variant="Variant.Filled" Color="Color.Primary">
|
||||
Add ERI server preset
|
||||
</MudButton>
|
||||
<MudButton OnClick="@this.RemoveERIServer" Disabled="@(this.AreServerPresetsBlocked || this.IsNoneERIServerSelected)" Variant="Variant.Filled" Color="Color.Error">
|
||||
Delete this server preset
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@if(this.AreServerPresetsBlocked)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3 mt-3">
|
||||
Hint: to allow this assistant to manage multiple presets, you must enable the preselection of values in the settings.
|
||||
</MudJustifiedText>
|
||||
}
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-3 mt-6">
|
||||
Auto save
|
||||
</MudText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
The ERI specification will change over time. You probably want to keep your ERI server up to date. This means you might want to
|
||||
regenerate the code for your ERI server. To avoid having to make all inputs each time, all your inputs and decisions can be
|
||||
automatically saved. Would you like this?
|
||||
</MudJustifiedText>
|
||||
|
||||
@if(this.AreServerPresetsBlocked)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
Hint: to allow this assistant to automatically save your changes, you must enable the preselection of values in the settings.
|
||||
</MudJustifiedText>
|
||||
}
|
||||
|
||||
<MudTextSwitch Label="Should we automatically save any input made?" Disabled="@this.AreServerPresetsBlocked" @bind-Value="@this.autoSave" LabelOn="Yes, please save my inputs" LabelOff="No, I will enter everything again or configure it manually in the settings" />
|
||||
|
||||
<hr style="width: 100%; border-width: 0.25ch;" class="mt-6"/>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-6 mb-1">
|
||||
Common ERI server settings
|
||||
</MudText>
|
||||
<MudTextField T="string" Disabled="@this.IsNoneERIServerSelected" @bind-Text="@this.serverName" Validation="@this.ValidateServerName" Immediate="@true" Label="ERI server name" HelperText="Please give your ERI server a name that provides information about the data source and/or its intended purpose. The name will be displayed to users in AI Studio." Counter="60" MaxLength="60" Variant="Variant.Outlined" Margin="Margin.Normal" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3" OnKeyUp="() => this.ServerNameWasChanged()"/>
|
||||
<MudTextField T="string" Disabled="@this.IsNoneERIServerSelected" @bind-Text="@this.serverDescription" Validation="@this.ValidateServerDescription" Immediate="@true" Label="ERI server description" HelperText="Please provide a brief description of your ERI server. Describe or explain what your ERI server does and what data it uses for this purpose. This description will be shown to users in AI Studio." Counter="512" MaxLength="512" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
|
||||
<MudStack Row="@true" Class="mb-3">
|
||||
<MudSelect Disabled="@this.IsNoneERIServerSelected" T="ProgrammingLanguages" @bind-Value="@this.selectedProgrammingLanguage" AdornmentIcon="@Icons.Material.Filled.Code" Adornment="Adornment.Start" Label="Programming language" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateProgrammingLanguage">
|
||||
@foreach (var language in Enum.GetValues<ProgrammingLanguages>())
|
||||
{
|
||||
<MudSelectItem Value="@language">@language.Name()</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
@if (this.selectedProgrammingLanguage is ProgrammingLanguages.OTHER)
|
||||
{
|
||||
<MudTextField Disabled="@this.IsNoneERIServerSelected" T="string" @bind-Text="@this.otherProgrammingLanguage" Validation="@this.ValidateOtherLanguage" Label="Other language" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row="@true" AlignItems="AlignItems.Center" Class="mb-3">
|
||||
<MudSelect Disabled="@this.IsNoneERIServerSelected" T="ERIVersion" @bind-Value="@this.selectedERIVersion" Label="ERI specification version" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateERIVersion">
|
||||
@foreach (var version in Enum.GetValues<ERIVersion>())
|
||||
{
|
||||
<MudSelectItem Value="@version">@version</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" Disabled="@(!this.selectedERIVersion.WasSpecificationSelected() || this.IsNoneERIServerSelected)" Href="@this.selectedERIVersion.SpecificationURL()" Target="_blank">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Link" Class="mr-2"/> Download specification
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-9 mb-3">
|
||||
Data source settings
|
||||
</MudText>
|
||||
|
||||
<MudStack Row="@false" Spacing="1" Class="mb-3">
|
||||
<MudSelect Disabled="@this.IsNoneERIServerSelected" T="DataSources" @bind-Value="@this.selectedDataSource" AdornmentIcon="@Icons.Material.Filled.Dataset" Adornment="Adornment.Start" Label="Data source" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateDataSource" SelectedValuesChanged="@this.DataSourceWasChanged">
|
||||
@foreach (var dataSource in Enum.GetValues<DataSources>())
|
||||
{
|
||||
<MudSelectItem Value="@dataSource">@dataSource.Name()</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
@if (this.selectedDataSource is DataSources.CUSTOM)
|
||||
{
|
||||
<MudTextField Disabled="@this.IsNoneERIServerSelected" T="string" @bind-Text="@this.otherDataSource" Validation="@this.ValidateOtherDataSource" Label="Describe your data source" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
@if(this.selectedDataSource > DataSources.FILE_SYSTEM)
|
||||
{
|
||||
<MudTextField Disabled="@this.IsNoneERIServerSelected" T="string" @bind-Text="@this.dataSourceProductName" Label="Data source: product name" Validation="@this.ValidateDataSourceProductName" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
}
|
||||
|
||||
@if (this.NeedHostnamePort())
|
||||
{
|
||||
<div class="mb-3">
|
||||
<MudStack Row="@true">
|
||||
<MudTextField Disabled="@this.IsNoneERIServerSelected" T="string" @bind-Text="@this.dataSourceHostname" Label="Data source: hostname" Validation="@this.ValidateHostname" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<MudNumericField Disabled="@this.IsNoneERIServerSelected" Label="Data source: port" Immediate="@true" Min="1" Max="65535" Validation="@this.ValidatePort" @bind-Value="@this.dataSourcePort" Variant="Variant.Outlined" Margin="Margin.Dense" OnKeyUp="() => this.DataSourcePortWasTyped()"/>
|
||||
</MudStack>
|
||||
@if (this.dataSourcePort < 1024)
|
||||
{
|
||||
<MudText Typo="Typo.body2">
|
||||
<b>Warning:</b> Ports below 1024 are reserved for system services. Your ERI server need to run with elevated permissions (root user).
|
||||
</MudText>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-9 mb-3">
|
||||
Authentication settings
|
||||
</MudText>
|
||||
|
||||
<MudStack Row="@false" Spacing="1" Class="mb-1">
|
||||
<MudSelectExtended
|
||||
T="Auth"
|
||||
Disabled="@this.IsNoneERIServerSelected"
|
||||
ShrinkLabel="@true"
|
||||
MultiSelection="@true"
|
||||
MultiSelectionTextFunc="@this.GetMultiSelectionAuthText"
|
||||
SelectedValues="@this.selectedAuthenticationMethods"
|
||||
Validation="@this.ValidateAuthenticationMethods"
|
||||
SelectedValuesChanged="@this.AuthenticationMethodWasChanged"
|
||||
Label="Authentication method(s)"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense">
|
||||
@foreach (var authMethod in Enum.GetValues<Auth>())
|
||||
{
|
||||
<MudSelectItemExtended Value="@authMethod">@authMethod.Name()</MudSelectItemExtended>
|
||||
}
|
||||
</MudSelectExtended>
|
||||
<MudTextField Disabled="@this.IsNoneERIServerSelected" T="string" @bind-Text="@this.authDescription" Label="@this.AuthDescriptionTitle()" Validation="@this.ValidateAuthDescription" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
</MudStack>
|
||||
|
||||
@if (this.selectedAuthenticationMethods.Contains(Auth.KERBEROS))
|
||||
{
|
||||
<MudSelect Disabled="@this.IsNoneERIServerSelected" T="OperatingSystem" @bind-Value="@this.selectedOperatingSystem" Label="Operating system on which your ERI will run" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateOperatingSystem" Class="mb-1">
|
||||
@foreach (var os in Enum.GetValues<OperatingSystem>())
|
||||
{
|
||||
<MudSelectItem Value="@os">@os.Name()</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
}
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-11 mb-3">
|
||||
Data protection settings
|
||||
</MudText>
|
||||
|
||||
<MudSelect Disabled="@this.IsNoneERIServerSelected" T="AllowedLLMProviders" @bind-Value="@this.allowedLLMProviders" Label="Allowed LLM providers for this data source" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateAllowedLLMProviders" Class="mb-1">
|
||||
@foreach (var option in Enum.GetValues<AllowedLLMProviders>())
|
||||
{
|
||||
<MudSelectItem Value="@option">@option.Description()</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-11 mb-3">
|
||||
Embedding settings
|
||||
</MudText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-2">
|
||||
You will likely use one or more embedding methods to encode the meaning of your data into a typically high-dimensional vector
|
||||
space. In this case, you will use a vector database to store and search these vectors (called embeddings). However, you don't
|
||||
have to use embedding methods. When your retrieval method works without any embedding, you can ignore this section. An example: You
|
||||
store files on a file server, and your retrieval method works exclusively with file names in the file system, so you don't
|
||||
need embeddings.
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
You can specify more than one embedding method. This can be useful when you want to use different embeddings for different queries
|
||||
or data types. For example, one embedding for texts, another for images, and a third for videos, etc.
|
||||
</MudJustifiedText>
|
||||
|
||||
@if (!this.IsNoneERIServerSelected)
|
||||
{
|
||||
<MudTable Items="@this.embeddings" Hover="@true" Class="border-dashed border rounded-lg">
|
||||
<ColGroup>
|
||||
<col/>
|
||||
<col style="width: 34em;"/>
|
||||
<col style="width: 34em;"/>
|
||||
</ColGroup>
|
||||
<HeaderContent>
|
||||
<MudTh>Name</MudTh>
|
||||
<MudTh>Type</MudTh>
|
||||
<MudTh Style="text-align: left;">Actions</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.EmbeddingName</MudTd>
|
||||
<MudTd>@context.EmbeddingType</MudTd>
|
||||
<MudTd Style="text-align: left;">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditEmbedding(context)">
|
||||
Edit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteEmbedding(context)">
|
||||
Delete
|
||||
</MudButton>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
@if (this.embeddings.Count == 0)
|
||||
{
|
||||
<MudText Typo="Typo.h6" Class="mt-3">No embedding methods configured yet.</MudText>
|
||||
}
|
||||
}
|
||||
|
||||
<MudButton Disabled="@this.IsNoneERIServerSelected" Variant="Variant.Filled" Color="@Color.Primary" StartIcon="@Icons.Material.Filled.AddRoad" Class="mt-3 mb-6" OnClick="@this.AddEmbedding">
|
||||
Add Embedding Method
|
||||
</MudButton>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-6 mb-1">
|
||||
Data retrieval settings
|
||||
</MudText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-2">
|
||||
For your ERI server, you need to retrieve data that matches a chat or prompt in some way. We call this the retrieval process.
|
||||
You must describe at least one such process. You may offer several retrieval processes from which users can choose. This allows
|
||||
you to test with beta users which process works better. Or you might generally want to give users the choice so they can select
|
||||
the process that best suits their circumstances.
|
||||
</MudJustifiedText>
|
||||
|
||||
@if (!this.IsNoneERIServerSelected)
|
||||
{
|
||||
<MudTable Items="@this.retrievalProcesses" Hover="@true" Class="border-dashed border rounded-lg">
|
||||
<ColGroup>
|
||||
<col/>
|
||||
<col style="width: 34em;"/>
|
||||
</ColGroup>
|
||||
<HeaderContent>
|
||||
<MudTh>Name</MudTh>
|
||||
<MudTh Style="text-align: left;">Actions</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.Name</MudTd>
|
||||
<MudTd Style="text-align: left;">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditRetrievalProcess(context)">
|
||||
Edit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteRetrievalProcess(context)">
|
||||
Delete
|
||||
</MudButton>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
@if (this.retrievalProcesses.Count == 0)
|
||||
{
|
||||
<MudText Typo="Typo.h6" Class="mt-3">No retrieval process configured yet.</MudText>
|
||||
}
|
||||
}
|
||||
|
||||
<MudButton Disabled="@this.IsNoneERIServerSelected" Variant="Variant.Filled" Color="@Color.Primary" StartIcon="@Icons.Material.Filled.AddRoad" Class="mt-3 mb-6" OnClick="@this.AddRetrievalProcess">
|
||||
Add Retrieval Process
|
||||
</MudButton>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-1">
|
||||
You can integrate additional libraries. Perhaps you want to evaluate the prompts in advance using a machine learning method or analyze them with a text
|
||||
mining approach? Or maybe you want to preprocess images in the prompts? For such advanced scenarios, you can specify which libraries you want to use here.
|
||||
It's best to describe which library you want to integrate for which purpose. This way, the LLM that writes the ERI server for you can try to use these
|
||||
libraries effectively. This should result in less rework being necessary. If you don't know the necessary libraries, you can instead attempt to describe
|
||||
the intended use. The LLM can then attempt to choose suitable libraries. However, hallucinations can occur, and fictional libraries might be selected.
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudTextField Disabled="@this.IsNoneERIServerSelected" T="string" @bind-Text="@this.additionalLibraries" Label="(Optional) Additional libraries" HelperText="Do you want to include additional libraries? Then name them and briefly describe what you want to achieve with them." Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="12" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-9 mb-1">
|
||||
Provider selection for generation
|
||||
</MudText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-2">
|
||||
The task of writing the ERI server for you is very complex. Therefore, a very powerful LLM is needed to successfully accomplish this task.
|
||||
Small local models will probably not be sufficient. Instead, try using a large cloud-based or a large self-hosted model.
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-2">
|
||||
<b>Important:</b> The LLM may need to generate many files. This reaches the request limit of most providers. Typically, only a certain number
|
||||
of requests can be made per minute, and only a maximum number of tokens can be generated per minute. AI Studio automatically considers this.
|
||||
<b>However, generating all the files takes a certain amount of time.</b> Local or self-hosted models may work without these limitations
|
||||
and can generate responses faster. AI Studio dynamically adapts its behavior and always tries to achieve the fastest possible data processing.
|
||||
</MudJustifiedText>
|
||||
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mt-9 mb-1">
|
||||
Write code to file system
|
||||
</MudText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-2">
|
||||
AI Studio can save the generated code to the file system. You can select a base folder for this. AI Studio ensures that no files are created
|
||||
outside of this base folder. Furthermore, we recommend that you create a Git repository in this folder. This way, you can see what changes the
|
||||
AI has made in which files.
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-2">
|
||||
When you rebuild / re-generate the ERI server code, AI Studio proceeds as follows: All files generated last time will be deleted. All
|
||||
other files you have created remain. Then, the AI generates the new files. <b>But beware:</b> It may happen that the AI generates a
|
||||
file this time that you manually created last time. In this case, your manually created file will then be overwritten. Therefore,
|
||||
you should always create a Git repository and commit or revert all changes before using this assistant. With a diff visualization,
|
||||
you can immediately see where the AI has made changes. It is best to use an IDE suitable for your selected language for this purpose.
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudTextSwitch Label="Should we write the generated code to the file system?" Disabled="@this.IsNoneERIServerSelected" @bind-Value="@this.writeToFilesystem" LabelOn="Yes, please write or update all generated code to the file system" LabelOff="No, just show me the code" />
|
||||
<SelectDirectory Label="Base directory where to write the code" @bind-Directory="@this.baseDirectory" Disabled="@(this.IsNoneERIServerSelected || !this.writeToFilesystem)" DirectoryDialogTitle="Select the target directory for the ERI server" Validation="@this.ValidateDirectory" />
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public enum Auth
|
||||
{
|
||||
NONE,
|
||||
KERBEROS,
|
||||
USERNAME_PASSWORD,
|
||||
TOKEN,
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public static class AuthExtensions
|
||||
{
|
||||
public static string Name(this Auth auth) => auth switch
|
||||
{
|
||||
Auth.NONE => "No login necessary: useful for public data sources",
|
||||
|
||||
Auth.KERBEROS => "Login by single-sign-on (SSO) using Kerberos: very complex to implement and to operate, useful for many users",
|
||||
Auth.USERNAME_PASSWORD => "Login by username and password: simple to implement and to operate, useful for few users; easy to use for users",
|
||||
Auth.TOKEN => "Login by token: simple to implement and to operate, useful for few users; unusual for many users",
|
||||
|
||||
_ => "Unknown login method"
|
||||
};
|
||||
|
||||
public static string ToPrompt(this Auth auth) => auth switch
|
||||
{
|
||||
Auth.NONE => "No login is necessary, the data source is public.",
|
||||
|
||||
Auth.KERBEROS => "Login by single-sign-on (SSO) using Kerberos.",
|
||||
Auth.USERNAME_PASSWORD => "Login by username and password.",
|
||||
Auth.TOKEN => "Login by static token per user.",
|
||||
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public enum DataSources
|
||||
{
|
||||
NONE,
|
||||
CUSTOM,
|
||||
|
||||
FILE_SYSTEM,
|
||||
|
||||
OBJECT_STORAGE,
|
||||
KEY_VALUE_STORE,
|
||||
DOCUMENT_STORE,
|
||||
RELATIONAL_DATABASE,
|
||||
GRAPH_DATABASE,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public static class DataSourcesExtensions
|
||||
{
|
||||
public static string Name(this DataSources dataSource) => dataSource switch
|
||||
{
|
||||
DataSources.NONE => "No data source selected",
|
||||
DataSources.CUSTOM => "Custom description",
|
||||
|
||||
DataSources.FILE_SYSTEM => "File system (local or network share)",
|
||||
DataSources.OBJECT_STORAGE => "Object storage, like Amazon S3, MinIO, etc.",
|
||||
DataSources.KEY_VALUE_STORE => "Key-Value store, like Redis, etc.",
|
||||
DataSources.DOCUMENT_STORE => "Document store, like MongoDB, etc.",
|
||||
DataSources.RELATIONAL_DATABASE => "Relational database, like MySQL, PostgreSQL, etc.",
|
||||
DataSources.GRAPH_DATABASE => "Graph database, like Neo4j, ArangoDB, etc.",
|
||||
|
||||
_ => "Unknown data source"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public enum ERIVersion
|
||||
{
|
||||
NONE,
|
||||
|
||||
V1,
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public static class ERIVersionExtensions
|
||||
{
|
||||
public static async Task<string> ReadSpecification(this ERIVersion version, HttpClient httpClient)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = version.SpecificationURL();
|
||||
using var response = await httpClient.GetAsync(url);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static string SpecificationURL(this ERIVersion version)
|
||||
{
|
||||
var nameLower = version.ToString().ToLowerInvariant();
|
||||
var filename = $"{nameLower}.json";
|
||||
return $"specs/eri/{filename}";
|
||||
}
|
||||
|
||||
public static bool WasSpecificationSelected(this ERIVersion version) => version != ERIVersion.NONE;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
/// <summary>
|
||||
/// Represents information about the used embedding for a data source.
|
||||
/// </summary>
|
||||
/// <param name="EmbeddingType">What kind of embedding is used. For example, "Transformer Embedding," "Contextual Word
|
||||
/// Embedding," "Graph Embedding," etc.</param>
|
||||
/// <param name="EmbeddingName">Name the embedding used. This can be a library, a framework, or the name of the used
|
||||
/// algorithm.</param>
|
||||
/// <param name="Description">A short description of the embedding. Describe what the embedding is doing.</param>
|
||||
/// <param name="UsedWhen">Describe when the embedding is used. For example, when the user prompt contains certain
|
||||
/// keywords, or anytime?</param>
|
||||
/// <param name="Link">A link to the embedding's documentation or the source code. Might be null.</param>
|
||||
public readonly record struct EmbeddingInfo(
|
||||
string EmbeddingType,
|
||||
string EmbeddingName,
|
||||
string Description,
|
||||
string UsedWhen,
|
||||
string? Link);
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public enum OperatingSystem
|
||||
{
|
||||
NONE,
|
||||
|
||||
WINDOWS,
|
||||
LINUX,
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public static class OperatingSystemExtensions
|
||||
{
|
||||
public static string Name(this OperatingSystem os) => os switch
|
||||
{
|
||||
OperatingSystem.NONE => "No operating system specified",
|
||||
|
||||
OperatingSystem.WINDOWS => "Windows",
|
||||
OperatingSystem.LINUX => "Linux",
|
||||
|
||||
_ => "Unknown operating system"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public enum ProgrammingLanguages
|
||||
{
|
||||
NONE,
|
||||
|
||||
C,
|
||||
CPP,
|
||||
CSHARP,
|
||||
GO,
|
||||
JAVA,
|
||||
JAVASCRIPT,
|
||||
JULIA,
|
||||
MATLAB,
|
||||
PHP,
|
||||
PYTHON,
|
||||
RUST,
|
||||
|
||||
OTHER,
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public static class ProgrammingLanguagesExtensions
|
||||
{
|
||||
public static string Name(this ProgrammingLanguages language) => language switch
|
||||
{
|
||||
ProgrammingLanguages.NONE => "No programming language selected",
|
||||
|
||||
ProgrammingLanguages.C => "C",
|
||||
ProgrammingLanguages.CPP => "C++",
|
||||
ProgrammingLanguages.CSHARP => "C#",
|
||||
ProgrammingLanguages.GO => "Go",
|
||||
ProgrammingLanguages.JAVA => "Java",
|
||||
ProgrammingLanguages.JAVASCRIPT => "JavaScript",
|
||||
ProgrammingLanguages.JULIA => "Julia",
|
||||
ProgrammingLanguages.MATLAB => "MATLAB",
|
||||
ProgrammingLanguages.PHP => "PHP",
|
||||
ProgrammingLanguages.PYTHON => "Python",
|
||||
ProgrammingLanguages.RUST => "Rust",
|
||||
|
||||
ProgrammingLanguages.OTHER => "Other",
|
||||
_ => "Unknown"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
/// <summary>
|
||||
/// Information about a retrieval process, which this data source implements.
|
||||
/// </summary>
|
||||
/// <param name="Name">The name of the retrieval process, e.g., "Keyword-Based Wikipedia Article Retrieval".</param>
|
||||
/// <param name="Description">A short description of the retrieval process. What kind of retrieval process is it?</param>
|
||||
/// <param name="Link">A link to the retrieval process's documentation, paper, Wikipedia article, or the source code. Might be null.</param>
|
||||
/// <param name="ParametersDescription">A dictionary that describes the parameters of the retrieval process. The key is the parameter name,
|
||||
/// and the value is a description of the parameter. Although each parameter will be sent as a string, the description should indicate the
|
||||
/// expected type and range, e.g., 0.0 to 1.0 for a float parameter.</param>
|
||||
/// <param name="Embeddings">A list of embeddings used in this retrieval process. It might be empty in case no embedding is used.</param>
|
||||
public readonly record struct RetrievalInfo(
|
||||
string Name,
|
||||
string Description,
|
||||
string? Link,
|
||||
Dictionary<string, string>? ParametersDescription,
|
||||
List<EmbeddingInfo>? Embeddings);
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace AIStudio.Assistants.ERI;
|
||||
|
||||
public sealed class RetrievalParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the parameter.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The description of the parameter.
|
||||
/// </summary>
|
||||
public string Description { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@attribute [Route(Routes.ASSISTANT_GRAMMAR_SPELLING)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogGrammarSpelling>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputText" Validation="@this.ValidateText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input to check" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelectingOptional())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,137 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.GrammarSpelling;
|
||||
|
||||
public partial class AssistantGrammarSpelling : AssistantBaseCore<SettingsDialogGrammarSpelling>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.GRAMMAR_SPELLING_ASSISTANT;
|
||||
|
||||
protected override string Title => "Grammar & Spelling Checker";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Check the grammar and spelling of a text.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You are an expert in languages and their rules. For example, you know how US and UK English or German in
|
||||
Germany and German in Austria differ. You receive text as input. You check the spelling and grammar of
|
||||
this text according to the rules of {this.SystemPromptLanguage()}. You never add information. You
|
||||
never ask the user for additional information. You do not attempt to improve the wording of the text.
|
||||
Your response includes only the corrected text. Do not explain your changes. If no changes are needed,
|
||||
you return the text unchanged.
|
||||
""";
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override bool ShowDedicatedProgress => true;
|
||||
|
||||
protected override Func<string> Result2Copy => () => this.correctedText;
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons =>
|
||||
[
|
||||
new SendToButton
|
||||
{
|
||||
Self = Tools.Components.GRAMMAR_SPELLING_ASSISTANT,
|
||||
UseResultingContentBlockData = false,
|
||||
GetText = () => string.IsNullOrWhiteSpace(this.correctedText) ? this.inputText : this.correctedText
|
||||
},
|
||||
];
|
||||
|
||||
protected override string SubmitText => "Proofread";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.ProofreadText;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputText = string.Empty;
|
||||
this.correctedText = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectOptions)
|
||||
{
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputText = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string inputText = string.Empty;
|
||||
private CommonLanguages selectedTargetLanguage;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
private string correctedText = string.Empty;
|
||||
|
||||
private string? ValidateText(string text)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(text))
|
||||
return "Please provide a text as input. You might copy the desired text from a document or a website.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
var lang = this.selectedTargetLanguage switch
|
||||
{
|
||||
CommonLanguages.AS_IS => "the source language",
|
||||
CommonLanguages.OTHER => this.customTargetLanguage,
|
||||
|
||||
_ => $"{this.selectedTargetLanguage.Name()}",
|
||||
};
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lang))
|
||||
return "the source language";
|
||||
|
||||
return lang;
|
||||
}
|
||||
|
||||
private async Task ProofreadText()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(this.inputText);
|
||||
|
||||
this.correctedText = await this.AddAIResponseAsync(time);
|
||||
await this.JsRuntime.GenerateAndShowDiff(this.inputText, this.correctedText);
|
||||
}
|
||||
}
|
||||
+3
-14
@@ -1,6 +1,5 @@
|
||||
@page "/assistant/icons"
|
||||
@using AIStudio.Settings
|
||||
@inherits AssistantBaseCore
|
||||
@attribute [Route(Routes.ASSISTANT_ICON_FINDER)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogIconFinder>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputContext" Validation="@this.ValidatingContext" AdornmentIcon="@Icons.Material.Filled.Description" Adornment="Adornment.Start" Label="Your context" Variant="Variant.Outlined" Lines="3" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
|
||||
@@ -16,14 +15,4 @@
|
||||
<MudButton Href="@this.selectedIconSource.URL()" Target="_blank" Variant="Variant.Filled" Size="Size.Medium">Open website</MudButton>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
<MudSelect T="Provider" @bind-Value="@this.providerSettings" Validation="@this.ValidatingProvider" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Apps" Margin="Margin.Dense" Label="Provider" Class="mb-3 rounded-lg" Variant="Variant.Outlined">
|
||||
@foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
||||
{
|
||||
<MudSelectItem Value="@provider"/>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Class="mb-3" OnClick="() => this.FindIcon()">
|
||||
Find icon
|
||||
</MudButton>
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
+49
-19
@@ -1,24 +1,10 @@
|
||||
namespace AIStudio.Components.Pages.IconFinder;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
public partial class AssistantIconFinder : AssistantBaseCore
|
||||
namespace AIStudio.Assistants.IconFinder;
|
||||
|
||||
public partial class AssistantIconFinder : AssistantBaseCore<SettingsDialogIconFinder>
|
||||
{
|
||||
private string inputContext = string.Empty;
|
||||
private IconSources selectedIconSource;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.PreselectIconOptions)
|
||||
{
|
||||
this.selectedIconSource = this.SettingsManager.ConfigurationData.PreselectedIconSource;
|
||||
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.PreselectedIconProvider);
|
||||
}
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
public override Tools.Components Component => Tools.Components.ICON_FINDER_ASSISTANT;
|
||||
|
||||
protected override string Title => "Icon Finder";
|
||||
|
||||
@@ -41,6 +27,50 @@ public partial class AssistantIconFinder : AssistantBaseCore
|
||||
quotation marks.
|
||||
""";
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Find Icon";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.FindIcon;
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputContext = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedIconSource = IconSources.GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.IconFinder.PreselectOptions)
|
||||
{
|
||||
this.selectedIconSource = this.SettingsManager.ConfigurationData.IconFinder.PreselectedSource;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string inputContext = string.Empty;
|
||||
private IconSources selectedIconSource;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_ICON_FINDER_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputContext = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidatingContext(string context)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(context))
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.IconFinder;
|
||||
namespace AIStudio.Assistants.IconFinder;
|
||||
|
||||
public static class IconSourceExtensions
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.IconFinder;
|
||||
namespace AIStudio.Assistants.IconFinder;
|
||||
|
||||
public enum IconSources
|
||||
{
|
||||
@@ -0,0 +1,15 @@
|
||||
@attribute [Route(Routes.ASSISTANT_JOB_POSTING)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogJobPostings>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputCompanyName" Label="(Optional) The company name" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Warehouse" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputCountryLegalFramework" Label="Provide the country, where the company is located" Validation="@this.ValidateCountryLegalFramework" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Flag" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3" HelperText="This is important to consider the legal framework of the country."/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputMandatoryInformation" Label="(Optional) Provide mandatory information" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.TextSnippet" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Mandatory information that your company requires for all job postings. This can include the company description, etc." />
|
||||
<MudTextField T="string" @bind-Text="@this.inputJobDescription" Label="Job description" Validation="@this.ValidateJobDescription" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Settings" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Describe what the person is supposed to do in the company. This might be just short bullet points." />
|
||||
<MudTextField T="string" @bind-Text="@this.inputQualifications" Label="(Optional) Provide necessary job qualifications" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Settings" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Describe what the person should bring to the table. This might be just short bullet points." />
|
||||
<MudTextField T="string" @bind-Text="@this.inputResponsibilities" Label="(Optional) Provide job responsibilities" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Settings" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES" HelperText="Describe the responsibilities the person should take on in the company." />
|
||||
<MudTextField T="string" @bind-Text="@this.inputWorkLocation" Label="(Optional) Provide the work location" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.MyLocation" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputEntryDate" Label="(Optional) Provide the entry date" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.DateRange" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputValidUntil" Label="(Optional) Provide the date until the job posting is valid" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.DateRange" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
|
||||
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelectingOptional())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,291 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.JobPosting;
|
||||
|
||||
public partial class AssistantJobPostings : AssistantBaseCore<SettingsDialogJobPostings>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.JOB_POSTING_ASSISTANT;
|
||||
|
||||
protected override string Title => "Job Posting";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Provide some key points about the job you want to post. The AI will then
|
||||
formulate a suggestion that you can finalize.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You are an experienced specialist in personnel matters. You write job postings.
|
||||
You follow the usual guidelines in the country of the posting. You ensure that
|
||||
no individuals are discriminated against or excluded by the job posting. You do
|
||||
not ask any questions and you do not repeat the task. You provide your response
|
||||
in a Markdown format. Missing information necessary for the job posting, you try
|
||||
to derive from the other details provided.
|
||||
|
||||
Structure of your response:
|
||||
---
|
||||
# <TITLE>
|
||||
<Description of the job and the company>
|
||||
|
||||
# <TASKS>
|
||||
<Describe what takes the job entails>
|
||||
|
||||
# <QUALIFICATIONS>
|
||||
<What qualifications are required>
|
||||
|
||||
# <RESPONSIBILITIES>
|
||||
<What responsibilities are associated with the job>
|
||||
|
||||
<When available, closing details such as the entry date etc.>
|
||||
|
||||
---
|
||||
|
||||
You write the job posting in the following language: {this.SystemPromptLanguage()}.
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Create the job posting";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.CreateJobPosting;
|
||||
|
||||
protected override bool SubmitDisabled => false;
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputEntryDate = string.Empty;
|
||||
this.inputValidUntil = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
this.inputMandatoryInformation = string.Empty;
|
||||
this.inputJobDescription = string.Empty;
|
||||
this.inputQualifications = string.Empty;
|
||||
this.inputResponsibilities = string.Empty;
|
||||
this.inputCompanyName = string.Empty;
|
||||
this.inputWorkLocation = string.Empty;
|
||||
this.inputCountryLegalFramework = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.JobPostings.PreselectOptions)
|
||||
{
|
||||
this.inputMandatoryInformation = this.SettingsManager.ConfigurationData.JobPostings.PreselectedMandatoryInformation;
|
||||
if(string.IsNullOrWhiteSpace(this.inputJobDescription))
|
||||
this.inputJobDescription = this.SettingsManager.ConfigurationData.JobPostings.PreselectedJobDescription;
|
||||
this.inputQualifications = this.SettingsManager.ConfigurationData.JobPostings.PreselectedQualifications;
|
||||
this.inputResponsibilities = this.SettingsManager.ConfigurationData.JobPostings.PreselectedResponsibilities;
|
||||
this.inputCompanyName = this.SettingsManager.ConfigurationData.JobPostings.PreselectedCompanyName;
|
||||
this.inputWorkLocation = this.SettingsManager.ConfigurationData.JobPostings.PreselectedWorkLocation;
|
||||
this.inputCountryLegalFramework = this.SettingsManager.ConfigurationData.JobPostings.PreselectedCountryLegalFramework;
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.JobPostings.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.JobPostings.PreselectOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string inputMandatoryInformation = string.Empty;
|
||||
private string inputJobDescription = string.Empty;
|
||||
private string inputQualifications = string.Empty;
|
||||
private string inputResponsibilities = string.Empty;
|
||||
private string inputCompanyName = string.Empty;
|
||||
private string inputEntryDate = string.Empty;
|
||||
private string inputValidUntil = string.Empty;
|
||||
private string inputWorkLocation = string.Empty;
|
||||
private string inputCountryLegalFramework = string.Empty;
|
||||
private CommonLanguages selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_JOB_POSTING_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputJobDescription = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom target language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateJobDescription(string jobDescription)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(jobDescription))
|
||||
return "Please provide a job description.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCountryLegalFramework(string countryLegalFramework)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(countryLegalFramework))
|
||||
return "Please provide the country where the job is posted (legal framework).";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
if(this.selectedTargetLanguage is CommonLanguages.AS_IS)
|
||||
return "Use the same language as the input";
|
||||
|
||||
if(this.selectedTargetLanguage is CommonLanguages.OTHER)
|
||||
return this.customTargetLanguage;
|
||||
|
||||
return this.selectedTargetLanguage.Name();
|
||||
}
|
||||
|
||||
private string UserPromptMandatoryInformation()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputMandatoryInformation))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Mandatory Information
|
||||
{this.inputMandatoryInformation}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptJobDescription()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputJobDescription))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Job Description
|
||||
{this.inputJobDescription}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptQualifications()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputQualifications))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Qualifications
|
||||
{this.inputQualifications}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptResponsibilities()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputResponsibilities))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Responsibilities
|
||||
{this.inputResponsibilities}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptCompanyName()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputCompanyName))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Company Name
|
||||
{this.inputCompanyName}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptEntryDate()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputEntryDate))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Entry Date
|
||||
{this.inputEntryDate}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptValidUntil()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputValidUntil))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Job Posting Valid Until
|
||||
{this.inputValidUntil}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptWorkLocation()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputWorkLocation))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Work Location
|
||||
{this.inputWorkLocation}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private string UserPromptCountryLegalFramework()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputCountryLegalFramework))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
# Country where the job is posted (legal framework)
|
||||
{this.inputCountryLegalFramework}
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private async Task CreateJobPosting()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
{this.UserPromptCompanyName()}
|
||||
{this.UserPromptCountryLegalFramework()}
|
||||
{this.UserPromptMandatoryInformation()}
|
||||
{this.UserPromptJobDescription()}
|
||||
{this.UserPromptQualifications()}
|
||||
{this.UserPromptResponsibilities()}
|
||||
{this.UserPromptWorkLocation()}
|
||||
{this.UserPromptEntryDate()}
|
||||
{this.UserPromptValidUntil()}
|
||||
""");
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
@attribute [Route(Routes.ASSISTANT_LEGAL_CHECK)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogLegalCheck>
|
||||
|
||||
@if (!this.SettingsManager.ConfigurationData.LegalCheck.HideWebContentReader)
|
||||
{
|
||||
<ReadWebContent @bind-Content="@this.inputLegalDocument" ProviderSettings="@this.providerSettings" @bind-AgentIsRunning="@this.isAgentRunning" Preselect="@(this.SettingsManager.ConfigurationData.LegalCheck.PreselectOptions && this.SettingsManager.ConfigurationData.LegalCheck.PreselectWebContentReader)" PreselectContentCleanerAgent="@(this.SettingsManager.ConfigurationData.LegalCheck.PreselectOptions && this.SettingsManager.ConfigurationData.LegalCheck.PreselectContentCleanerAgent)"/>
|
||||
}
|
||||
|
||||
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputLegalDocument" Validation="@this.ValidatingLegalDocument" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Legal document" Variant="Variant.Outlined" Lines="12" AutoGrow="@true" MaxLines="24" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputQuestions" Validation="@this.ValidatingQuestions" AdornmentIcon="@Icons.Material.Filled.QuestionAnswer" Adornment="Adornment.Start" Label="Your questions" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,101 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.LegalCheck;
|
||||
|
||||
public partial class AssistantLegalCheck : AssistantBaseCore<SettingsDialogLegalCheck>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.LEGAL_CHECK_ASSISTANT;
|
||||
|
||||
protected override string Title => "Legal Check";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Provide a legal document and ask a question about it. This assistant does not
|
||||
replace legal advice. Consult a lawyer to get professional advice. Remember
|
||||
that LLMs can invent answers and facts. Please do not rely on this answers.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
"""
|
||||
You are an expert in legal matters. You have studied international law and are familiar with the law in
|
||||
various countries. You receive a legal document and answer the user's questions. You are a friendly and
|
||||
professional assistant. You respond to the user in the language in which the questions were asked. If
|
||||
you are unsure, unfamiliar with the legal area, or do not know the answers, you inform the user.
|
||||
Never invent facts!
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Ask your questions";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.AksQuestions;
|
||||
|
||||
protected override bool SubmitDisabled => this.isAgentRunning;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputLegalDocument = string.Empty;
|
||||
this.inputQuestions = string.Empty;
|
||||
this.MightPreselectValues();
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues() => false;
|
||||
|
||||
private bool isAgentRunning;
|
||||
private string inputLegalDocument = string.Empty;
|
||||
private string inputQuestions = string.Empty;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_LEGAL_CHECK_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputQuestions = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidatingLegalDocument(string text)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(text))
|
||||
return "Please provide a legal document as input. You might copy the desired text from a document or a website.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidatingQuestions(string text)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(text))
|
||||
return "Please provide your questions as input.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task AksQuestions()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
# The legal document
|
||||
{this.inputLegalDocument}
|
||||
|
||||
# The questions
|
||||
{this.inputQuestions}
|
||||
""");
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@attribute [Route(Routes.ASSISTANT_MY_TASKS)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogMyTasks>
|
||||
|
||||
<ProfileFormSelection Validation="@this.ValidateProfile" @bind-Profile="@this.currentProfile"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Text or email" Variant="Variant.Outlined" Lines="12" AutoGrow="@true" MaxLines="24" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelectingOptional())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,130 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
using AIStudio.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.MyTasks;
|
||||
|
||||
public partial class AssistantMyTasks : AssistantBaseCore<SettingsDialogMyTasks>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.MY_TASKS_ASSISTANT;
|
||||
|
||||
protected override string Title => "My Tasks";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
You received a cryptic email that was sent to many recipients and you are now wondering
|
||||
if you need to do something? Copy the email into the input field. You also need to select
|
||||
a personal profile. In this profile, you should describe your role in the organization.
|
||||
The AI will then try to give you hints on what your tasks might be.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You are a friendly and professional business expert. You receive business emails, protocols,
|
||||
reports, etc. as input. Additionally, you know the user's role in the organization. The user
|
||||
wonders if any tasks arise for them in their role based on the text. You now try to give hints
|
||||
and advice on whether and what the user should do. When you believe there are no tasks for the
|
||||
user, you tell them this. You consider typical business etiquette in your advice.
|
||||
|
||||
You write your advice in the following language: {this.SystemPromptLanguage()}.
|
||||
""";
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Analyze text";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.AnalyzeText;
|
||||
|
||||
protected override bool ShowProfileSelection => false;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputText = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.MyTasks.PreselectOptions)
|
||||
{
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.MyTasks.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.MyTasks.PreselectOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string inputText = string.Empty;
|
||||
private CommonLanguages selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_MY_TASKS_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputText = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidatingText(string text)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(text))
|
||||
return "Please provide some text as input. For example, an email.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateProfile(Profile profile)
|
||||
{
|
||||
if(profile == default || profile == Profile.NO_PROFILE)
|
||||
return "Please select one of your profiles.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
if(this.selectedTargetLanguage is CommonLanguages.AS_IS)
|
||||
return "Use the same language as the input";
|
||||
|
||||
if(this.selectedTargetLanguage is CommonLanguages.OTHER)
|
||||
return this.customTargetLanguage;
|
||||
|
||||
return this.selectedTargetLanguage.Name();
|
||||
}
|
||||
|
||||
private async Task AnalyzeText()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(this.inputText);
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@attribute [Route(Routes.ASSISTANT_REWRITE)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogRewrite>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputText" Validation="@this.ValidateText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input to improve" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelectingOptional())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom language" />
|
||||
<EnumSelection T="WritingStyles" NameFunc="@(style => style.Name())" @bind-Value="@this.selectedWritingStyle" Icon="@Icons.Material.Filled.Edit" Label="Writing style" AllowOther="@false" />
|
||||
<EnumSelection T="SentenceStructure" NameFunc="@(voice => voice.Name())" @bind-Value="@this.selectedSentenceStructure" Icon="@Icons.Material.Filled.Person4" Label="Sentence structure" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,144 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.RewriteImprove;
|
||||
|
||||
public partial class AssistantRewriteImprove : AssistantBaseCore<SettingsDialogRewrite>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.REWRITE_ASSISTANT;
|
||||
|
||||
protected override string Title => "Rewrite & Improve Text";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Rewrite and improve your text. Please note, that the capabilities of the different LLM providers will vary.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You are an expert in language and style. You receive a text as input. First, you review the text. If no
|
||||
changes are needed, you return the text without modifications. If a change is necessary, you improve the
|
||||
text. You can also correct spelling and grammar issues. You never add additional information. You never
|
||||
ask the user for additional information. Your response only contains the improved text. You do not explain
|
||||
your changes. If no changes are needed, you return the text unchanged.
|
||||
The style of the text: {this.selectedWritingStyle.Prompt()}.{this.selectedSentenceStructure.Prompt()}
|
||||
You follow the rules according to {this.SystemPromptLanguage()} in all your changes.
|
||||
""";
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override bool ShowDedicatedProgress => true;
|
||||
|
||||
protected override Func<string> Result2Copy => () => this.rewrittenText;
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons =>
|
||||
[
|
||||
new SendToButton
|
||||
{
|
||||
Self = Tools.Components.REWRITE_ASSISTANT,
|
||||
UseResultingContentBlockData = false,
|
||||
GetText = () => string.IsNullOrWhiteSpace(this.rewrittenText) ? this.inputText : this.rewrittenText,
|
||||
},
|
||||
];
|
||||
|
||||
protected override string SubmitText => "Improve";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.RewriteText;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputText = string.Empty;
|
||||
this.rewrittenText = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
this.selectedWritingStyle = WritingStyles.NOT_SPECIFIED;
|
||||
this.selectedSentenceStructure = SentenceStructure.NOT_SPECIFIED;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.RewriteImprove.PreselectOptions)
|
||||
{
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedOtherLanguage;
|
||||
this.selectedWritingStyle = this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedWritingStyle;
|
||||
this.selectedSentenceStructure = this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedSentenceStructure;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_REWRITE_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputText = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string inputText = string.Empty;
|
||||
private CommonLanguages selectedTargetLanguage;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
private string rewrittenText = string.Empty;
|
||||
private WritingStyles selectedWritingStyle;
|
||||
private SentenceStructure selectedSentenceStructure;
|
||||
|
||||
private string? ValidateText(string text)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(text))
|
||||
return "Please provide a text as input. You might copy the desired text from a document or a website.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
var lang = this.selectedTargetLanguage switch
|
||||
{
|
||||
CommonLanguages.AS_IS => "the source language",
|
||||
CommonLanguages.OTHER => this.customTargetLanguage,
|
||||
|
||||
_ => $"{this.selectedTargetLanguage.Name()}",
|
||||
};
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lang))
|
||||
return "the source language";
|
||||
|
||||
return lang;
|
||||
}
|
||||
|
||||
private async Task RewriteText()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(this.inputText);
|
||||
|
||||
this.rewrittenText = await this.AddAIResponseAsync(time);
|
||||
await this.JsRuntime.GenerateAndShowDiff(this.inputText, this.rewrittenText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Assistants.RewriteImprove;
|
||||
|
||||
public enum SentenceStructure
|
||||
{
|
||||
NOT_SPECIFIED = 0,
|
||||
|
||||
ACTIVE,
|
||||
PASSIVE,
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AIStudio.Assistants.RewriteImprove;
|
||||
|
||||
public static class SentenceStructureExtensions
|
||||
{
|
||||
public static string Name(this SentenceStructure sentenceStructure) => sentenceStructure switch
|
||||
{
|
||||
SentenceStructure.ACTIVE => "Active voice",
|
||||
SentenceStructure.PASSIVE => "Passive voice",
|
||||
|
||||
_ => "Not Specified",
|
||||
};
|
||||
|
||||
public static string Prompt(this SentenceStructure sentenceStructure) => sentenceStructure switch
|
||||
{
|
||||
SentenceStructure.ACTIVE => " Use an active voice for the sentence structure.",
|
||||
SentenceStructure.PASSIVE => " Use a passive voice for the sentence structure.",
|
||||
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace AIStudio.Assistants.RewriteImprove;
|
||||
|
||||
public enum WritingStyles
|
||||
{
|
||||
NOT_SPECIFIED = 0,
|
||||
|
||||
EVERYDAY,
|
||||
BUSINESS,
|
||||
SCIENTIFIC,
|
||||
JOURNALISTIC,
|
||||
LITERARY,
|
||||
TECHNICAL,
|
||||
MARKETING,
|
||||
ACADEMIC,
|
||||
LEGAL,
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace AIStudio.Assistants.RewriteImprove;
|
||||
|
||||
public static class WritingStylesExtensions
|
||||
{
|
||||
public static string Name(this WritingStyles style) => style switch
|
||||
{
|
||||
WritingStyles.EVERYDAY => "Everyday (personal texts, social media)",
|
||||
WritingStyles.BUSINESS => "Business (business emails, reports, presentations)",
|
||||
WritingStyles.SCIENTIFIC => "Scientific (scientific papers, research reports)",
|
||||
WritingStyles.JOURNALISTIC => "Journalistic (magazines, newspapers, news)",
|
||||
WritingStyles.LITERARY => "Literary (fiction, poetry)",
|
||||
WritingStyles.TECHNICAL => "Technical (manuals, documentation)",
|
||||
WritingStyles.MARKETING => "Marketing (advertisements, sales texts)",
|
||||
WritingStyles.ACADEMIC => "Academic (essays, seminar papers)",
|
||||
WritingStyles.LEGAL => "Legal (legal texts, contracts)",
|
||||
|
||||
_ => "Not specified",
|
||||
};
|
||||
|
||||
public static string Prompt(this WritingStyles style) => style switch
|
||||
{
|
||||
WritingStyles.EVERYDAY => "Use a everyday style like for personal texts, social media, and informal communication.",
|
||||
WritingStyles.BUSINESS => "Use a business style like for business emails, reports, and presentations. Most important is clarity and professionalism.",
|
||||
WritingStyles.SCIENTIFIC => "Use a scientific style like for scientific papers, research reports, and academic writing. Most important is precision and objectivity.",
|
||||
WritingStyles.JOURNALISTIC => "Use a journalistic style like for magazines, newspapers, and news. Most important is readability and engaging content.",
|
||||
WritingStyles.LITERARY => "Use a literary style like for fiction, poetry, and creative writing. Most important is creativity and emotional impact.",
|
||||
WritingStyles.TECHNICAL => "Use a technical style like for manuals, documentation, and technical writing. Most important is clarity and precision.",
|
||||
WritingStyles.MARKETING => "Use a marketing style like for advertisements, sales texts, and promotional content. Most important is persuasiveness and engagement.",
|
||||
WritingStyles.ACADEMIC => "Use a academic style like for essays, seminar papers, and academic writing. Most important is clarity and objectivity.",
|
||||
WritingStyles.LEGAL => "Use a legal style like for legal texts, contracts, and official documents. Most important is precision and legal correctness. Use formal legal language.",
|
||||
|
||||
_ => "Keep the style of the text as it is.",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@attribute [Route(Routes.ASSISTANT_SYNONYMS)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogSynonyms>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.Spellcheck" Adornment="Adornment.Start" Label="Your word or phrase" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputContext" AdornmentIcon="@Icons.Material.Filled.Description" Adornment="Adornment.Start" Lines="2" AutoGrow="@false" Label="(Optional) The context for the given word or phrase" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelectingOptional())" @bind-Value="@this.selectedLanguage" Icon="@Icons.Material.Filled.Translate" Label="Language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
@@ -0,0 +1,171 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.Synonym;
|
||||
|
||||
public partial class AssistantSynonyms : AssistantBaseCore<SettingsDialogSynonyms>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.SYNONYMS_ASSISTANT;
|
||||
|
||||
protected override string Title => "Synonyms";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
Find synonyms for words or phrases.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
$"""
|
||||
You have a PhD in linguistics. Therefore, you are an expert in the {this.SystemPromptLanguage()} language.
|
||||
You receive a word or phrase as input. You might also receive some context. You then provide
|
||||
a list of synonyms as a Markdown list.
|
||||
|
||||
First, derive possible meanings from the word, phrase, and context, when available. Then, provide
|
||||
possible synonyms for each meaning.
|
||||
|
||||
Example for the word "learn" and the language English (US):
|
||||
|
||||
Derive possible meanings (*this list is not part of the output*):
|
||||
- Meaning "to learn"
|
||||
- Meaning "to retain"
|
||||
|
||||
Next, provide possible synonyms for each meaning, which is your output:
|
||||
|
||||
# Meaning "to learn"
|
||||
- absorb
|
||||
- study
|
||||
- acquire
|
||||
- advance
|
||||
- practice
|
||||
|
||||
# Meaning "to retain"
|
||||
- remember
|
||||
- note
|
||||
- realize
|
||||
|
||||
You do not ask follow-up questions and never repeat the task instructions. When you do not know
|
||||
any synonyms for the given word or phrase, you state this. Your output is always in
|
||||
the {this.SystemPromptLanguage()} language.
|
||||
""";
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Find synonyms";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.FindSynonyms;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputText = string.Empty;
|
||||
this.inputContext = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)
|
||||
{
|
||||
this.selectedLanguage = this.SettingsManager.ConfigurationData.Synonyms.PreselectedLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.Synonyms.PreselectedOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string inputText = string.Empty;
|
||||
private string inputContext = string.Empty;
|
||||
private CommonLanguages selectedLanguage;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_SYNONYMS_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputContext = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidatingText(string text)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(text))
|
||||
return "Please provide a word or phrase as input.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
return "Please provide a custom language.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string SystemPromptLanguage()
|
||||
{
|
||||
var lang = this.selectedLanguage switch
|
||||
{
|
||||
CommonLanguages.AS_IS => "source",
|
||||
CommonLanguages.OTHER => this.customTargetLanguage,
|
||||
|
||||
_ => $"{this.selectedLanguage.Name()}",
|
||||
};
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lang))
|
||||
return "source";
|
||||
|
||||
return lang;
|
||||
}
|
||||
|
||||
private string UserPromptContext()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(this.inputContext))
|
||||
return string.Empty;
|
||||
|
||||
return $"""
|
||||
The given context is:
|
||||
|
||||
```
|
||||
{this.inputContext}
|
||||
```
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
private async Task FindSynonyms()
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
{this.UserPromptContext()}
|
||||
The given word or phrase is:
|
||||
|
||||
```
|
||||
{this.inputText}
|
||||
```
|
||||
""");
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
@attribute [Route(Routes.ASSISTANT_SUMMARIZER)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogTextSummarizer>
|
||||
|
||||
@if (!this.SettingsManager.ConfigurationData.TextSummarizer.HideWebContentReader)
|
||||
{
|
||||
<ReadWebContent @bind-Content="@this.inputText" ProviderSettings="@this.providerSettings" @bind-AgentIsRunning="@this.isAgentRunning" Preselect="@(this.SettingsManager.ConfigurationData.TextSummarizer.PreselectOptions && this.SettingsManager.ConfigurationData.TextSummarizer.PreselectWebContentReader)" PreselectContentCleanerAgent="@(this.SettingsManager.ConfigurationData.TextSummarizer.PreselectOptions && this.SettingsManager.ConfigurationData.TextSummarizer.PreselectContentCleanerAgent)"/>
|
||||
}
|
||||
|
||||
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.Name())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" @bind-OtherInput="@this.customTargetLanguage" OtherValue="CommonLanguages.OTHER" LabelOther="Custom target language" ValidateOther="@this.ValidateCustomLanguage" />
|
||||
<EnumSelection T="Complexity" NameFunc="@(complexity => complexity.Name())" @bind-Value="@this.selectedComplexity" Icon="@Icons.Material.Filled.Layers" Label="Target complexity" AllowOther="@true" @bind-OtherInput="@this.expertInField" OtherValue="Complexity.SCIENTIFIC_LANGUAGE_OTHER_EXPERTS" LabelOther="Your expertise" ValidateOther="@this.ValidateExpertInField" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
+51
-12
@@ -1,9 +1,12 @@
|
||||
using AIStudio.Tools;
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Components.Pages.TextSummarizer;
|
||||
namespace AIStudio.Assistants.TextSummarizer;
|
||||
|
||||
public partial class AssistantTextSummarizer : AssistantBaseCore
|
||||
public partial class AssistantTextSummarizer : AssistantBaseCore<SettingsDialogTextSummarizer>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.TEXT_SUMMARIZER_ASSISTANT;
|
||||
|
||||
protected override string Title => "Text Summarizer";
|
||||
|
||||
protected override string Description =>
|
||||
@@ -23,6 +26,47 @@ public partial class AssistantTextSummarizer : AssistantBaseCore
|
||||
a summary with the requested complexity. In any case, do not add any information.
|
||||
""";
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Summarize";
|
||||
|
||||
protected override Func<Task> SubmitAction => this.SummarizeText;
|
||||
|
||||
protected override bool SubmitDisabled => this.isAgentRunning;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputText = string.Empty;
|
||||
if(!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
this.selectedComplexity = Complexity.NO_CHANGE;
|
||||
this.expertInField = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.TextSummarizer.PreselectOptions)
|
||||
{
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedOtherLanguage;
|
||||
this.selectedComplexity = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedComplexity;
|
||||
this.expertInField = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedExpertInField;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string inputText = string.Empty;
|
||||
private bool isAgentRunning;
|
||||
private CommonLanguages selectedTargetLanguage;
|
||||
@@ -34,14 +78,9 @@ public partial class AssistantTextSummarizer : AssistantBaseCore
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if(this.SettingsManager.ConfigurationData.PreselectTextSummarizerOptions)
|
||||
{
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.PreselectedTextSummarizerTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.PreselectedTextSummarizerOtherLanguage;
|
||||
this.selectedComplexity = this.SettingsManager.ConfigurationData.PreselectedTextSummarizerComplexity;
|
||||
this.expertInField = this.SettingsManager.ConfigurationData.PreselectedTextSummarizerExpertInField;
|
||||
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.PreselectedTextSummarizerProvider);
|
||||
}
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_TEXT_SUMMARIZER_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputText = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
@@ -81,7 +120,7 @@ public partial class AssistantTextSummarizer : AssistantBaseCore
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
{this.selectedTargetLanguage.Prompt(this.customTargetLanguage)}
|
||||
{this.selectedTargetLanguage.PromptSummarizing(this.customTargetLanguage)}
|
||||
{this.selectedComplexity.Prompt(this.expertInField)}
|
||||
|
||||
Please summarize the following text:
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.TextSummarizer;
|
||||
namespace AIStudio.Assistants.TextSummarizer;
|
||||
|
||||
public enum Complexity
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace AIStudio.Components.Pages.TextSummarizer;
|
||||
namespace AIStudio.Assistants.TextSummarizer;
|
||||
|
||||
public static class ComplexityExtensions
|
||||
{
|
||||
@@ -0,0 +1,20 @@
|
||||
@attribute [Route(Routes.ASSISTANT_TRANSLATION)]
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogTranslation>
|
||||
|
||||
@if (!this.SettingsManager.ConfigurationData.Translation.HideWebContentReader)
|
||||
{
|
||||
<ReadWebContent @bind-Content="@this.inputText" ProviderSettings="@this.providerSettings" @bind-AgentIsRunning="@this.isAgentRunning" Preselect="@(this.SettingsManager.ConfigurationData.Translation.PreselectOptions && this.SettingsManager.ConfigurationData.Translation.PreselectWebContentReader)" PreselectContentCleanerAgent="@(this.SettingsManager.ConfigurationData.Translation.PreselectOptions && this.SettingsManager.ConfigurationData.Translation.PreselectContentCleanerAgent)"/>
|
||||
}
|
||||
|
||||
<MudTextSwitch Label="Live translation" @bind-Value="@this.liveTranslation" LabelOn="Live translation" LabelOff="No live translation"/>
|
||||
@if (this.liveTranslation)
|
||||
{
|
||||
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" Immediate="@true" DebounceInterval="@this.SettingsManager.ConfigurationData.Translation.DebounceIntervalMilliseconds" OnDebounceIntervalElapsed="() => this.TranslateText(force: false)" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
}
|
||||
|
||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidatingTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
+52
-12
@@ -1,9 +1,12 @@
|
||||
using AIStudio.Tools;
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Components.Pages.Translation;
|
||||
namespace AIStudio.Assistants.Translation;
|
||||
|
||||
public partial class AssistantTranslation : AssistantBaseCore
|
||||
public partial class AssistantTranslation : AssistantBaseCore<SettingsDialogTranslation>
|
||||
{
|
||||
public override Tools.Components Component => Tools.Components.TRANSLATION_ASSISTANT;
|
||||
|
||||
protected override string Title => "Translation";
|
||||
|
||||
protected override string Description =>
|
||||
@@ -19,6 +22,46 @@ public partial class AssistantTranslation : AssistantBaseCore
|
||||
language requires, e.g., shorter sentences, you should split the text into shorter sentences.
|
||||
""";
|
||||
|
||||
protected override bool AllowProfiles => false;
|
||||
|
||||
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||
|
||||
protected override string SubmitText => "Translate";
|
||||
|
||||
protected override Func<Task> SubmitAction => () => this.TranslateText(true);
|
||||
|
||||
protected override bool SubmitDisabled => this.isAgentRunning;
|
||||
|
||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||
{
|
||||
SystemPrompt = SystemPrompts.DEFAULT,
|
||||
};
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.inputText = string.Empty;
|
||||
this.inputTextLastTranslation = string.Empty;
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.liveTranslation = false;
|
||||
this.selectedTargetLanguage = CommonLanguages.AS_IS;
|
||||
this.customTargetLanguage = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.Translation.PreselectOptions)
|
||||
{
|
||||
this.liveTranslation = this.SettingsManager.ConfigurationData.Translation.PreselectLiveTranslation;
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.Translation.PreselectedTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.Translation.PreselectOtherLanguage;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool liveTranslation;
|
||||
private bool isAgentRunning;
|
||||
private string inputText = string.Empty;
|
||||
@@ -30,13 +73,9 @@ public partial class AssistantTranslation : AssistantBaseCore
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.PreselectTranslationOptions)
|
||||
{
|
||||
this.liveTranslation = this.SettingsManager.ConfigurationData.PreselectLiveTranslation;
|
||||
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.PreselectedTranslationTargetLanguage;
|
||||
this.customTargetLanguage = this.SettingsManager.ConfigurationData.PreselectTranslationOtherLanguage;
|
||||
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.PreselectedTranslationProvider);
|
||||
}
|
||||
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_TRANSLATION_ASSISTANT).FirstOrDefault();
|
||||
if (deferredContent is not null)
|
||||
this.inputText = deferredContent;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
@@ -66,9 +105,10 @@ public partial class AssistantTranslation : AssistantBaseCore
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private async Task TranslateText(bool force)
|
||||
{
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
@@ -79,7 +119,7 @@ public partial class AssistantTranslation : AssistantBaseCore
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
{this.selectedTargetLanguage.Prompt(this.customTargetLanguage)}
|
||||
{this.selectedTargetLanguage.PromptTranslation(this.customTargetLanguage)}
|
||||
|
||||
The given text is:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@using AIStudio
|
||||
@using AIStudio.Tools
|
||||
@using AIStudio.Components
|
||||
@using MudBlazor
|
||||
@@ -1,9 +1,14 @@
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.ERIClient.DataModel;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// Data structure for a chat thread.
|
||||
/// </summary>
|
||||
public sealed class ChatThread
|
||||
public sealed record ChatThread
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier of the chat thread.
|
||||
@@ -15,6 +20,36 @@ public sealed class ChatThread
|
||||
/// </summary>
|
||||
public Guid WorkspaceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the provider selected for the chat thread.
|
||||
/// </summary>
|
||||
public string SelectedProvider { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the profile selected for the chat thread.
|
||||
/// </summary>
|
||||
public string SelectedProfile { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The data source options for this chat thread.
|
||||
/// </summary>
|
||||
public DataSourceOptions DataSourceOptions { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// The AI-selected data sources for this chat thread.
|
||||
/// </summary>
|
||||
public IReadOnlyList<DataSourceAgentSelected> AISelectedDataSources { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The augmented data for this chat thread. Will be inserted into the system prompt.
|
||||
/// </summary>
|
||||
public string AugmentedData { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The data security to use, derived from the data sources used so far.
|
||||
/// </summary>
|
||||
public DataSourceSecurity DataSecurity { get; set; } = DataSourceSecurity.NOT_SPECIFIED;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the chat thread. Usually generated by an AI model or manually edited by the user.
|
||||
/// </summary>
|
||||
@@ -34,4 +69,155 @@ public sealed class ChatThread
|
||||
/// The content blocks of the chat thread.
|
||||
/// </summary>
|
||||
public List<ContentBlock> Blocks { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the system prompt for the chat thread.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The actual system prompt depends on the selected profile. If no profile is selected,
|
||||
/// the system prompt is returned as is. When a profile is selected, the system prompt
|
||||
/// is extended with the profile chosen.
|
||||
/// </remarks>
|
||||
/// <param name="settingsManager">The settings manager instance to use.</param>
|
||||
/// <param name="chatThread">The chat thread to prepare the system prompt for.</param>
|
||||
/// <param name="logger">The logger instance to use.</param>
|
||||
/// <returns>The prepared system prompt.</returns>
|
||||
public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread chatThread, ILogger logger)
|
||||
{
|
||||
var isAugmentedDataAvailable = !string.IsNullOrWhiteSpace(chatThread.AugmentedData);
|
||||
var systemPromptWithAugmentedData = isAugmentedDataAvailable switch
|
||||
{
|
||||
true => $"""
|
||||
{chatThread.SystemPrompt}
|
||||
|
||||
{chatThread.AugmentedData}
|
||||
""",
|
||||
|
||||
false => chatThread.SystemPrompt,
|
||||
};
|
||||
|
||||
if(isAugmentedDataAvailable)
|
||||
logger.LogInformation("Augmented data is available for the chat thread.");
|
||||
else
|
||||
logger.LogInformation("No augmented data is available for the chat thread.");
|
||||
|
||||
//
|
||||
// Prepare the system prompt:
|
||||
//
|
||||
string systemPromptText;
|
||||
var logMessage = $"Using no profile for chat thread '{chatThread.Name}'.";
|
||||
if (string.IsNullOrWhiteSpace(chatThread.SelectedProfile))
|
||||
systemPromptText = systemPromptWithAugmentedData;
|
||||
else
|
||||
{
|
||||
if(!Guid.TryParse(chatThread.SelectedProfile, out var profileId))
|
||||
systemPromptText = systemPromptWithAugmentedData;
|
||||
else
|
||||
{
|
||||
if(chatThread.SelectedProfile == Profile.NO_PROFILE.Id || profileId == Guid.Empty)
|
||||
systemPromptText = systemPromptWithAugmentedData;
|
||||
else
|
||||
{
|
||||
var profile = settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == chatThread.SelectedProfile);
|
||||
if(profile == default)
|
||||
systemPromptText = systemPromptWithAugmentedData;
|
||||
else
|
||||
{
|
||||
logMessage = $"Using profile '{profile.Name}' for chat thread '{chatThread.Name}'.";
|
||||
systemPromptText = $"""
|
||||
{systemPromptWithAugmentedData}
|
||||
|
||||
{profile.ToSystemPrompt()}
|
||||
""";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogInformation(logMessage);
|
||||
return systemPromptText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a content block from this chat thread.
|
||||
/// </summary>
|
||||
/// <param name="content">The content block to remove.</param>
|
||||
/// <param name="removeForRegenerate">Indicates whether the content block is removed for
|
||||
/// regeneration purposes. True, when the content block is removed for regeneration purposes,
|
||||
/// which will not remove the previous user block if it is hidden from the user.</param>
|
||||
public void Remove(IContent content, bool removeForRegenerate = false)
|
||||
{
|
||||
var block = this.Blocks.FirstOrDefault(x => x.Content == content);
|
||||
if(block is null)
|
||||
return;
|
||||
|
||||
//
|
||||
// Remove the previous user block if it is hidden from the user. Otherwise,
|
||||
// the experience might be confusing for the user.
|
||||
//
|
||||
// Explanation, using the ERI assistant as an example:
|
||||
// - The ERI assistant generates for every file a hidden user prompt.
|
||||
// - In the UI, the user can only see the AI's responses, not the hidden user prompts.
|
||||
// - Now, the user removes one AI response
|
||||
// - The hidden user prompt is still there, but the user can't see it.
|
||||
// - Since the user prompt is hidden, neither is it possible to remove nor edit it.
|
||||
// - This method solves this issue by removing the hidden user prompt when the AI response is removed.
|
||||
//
|
||||
if (block.Role is ChatRole.AI && !removeForRegenerate)
|
||||
{
|
||||
var sortedBlocks = this.Blocks.OrderBy(x => x.Time).ToList();
|
||||
var index = sortedBlocks.IndexOf(block);
|
||||
if (index > 0)
|
||||
{
|
||||
var previousBlock = sortedBlocks[index - 1];
|
||||
if (previousBlock.Role is ChatRole.USER && previousBlock.HideFromUser)
|
||||
this.Blocks.Remove(previousBlock);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the block from the chat thread:
|
||||
this.Blocks.Remove(block);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms this chat thread to an ERI chat thread.
|
||||
/// </summary>
|
||||
/// <param name="token">The cancellation token.</param>
|
||||
/// <returns>The ERI chat thread.</returns>
|
||||
public async Task<Tools.ERIClient.DataModel.ChatThread> ToERIChatThread(CancellationToken token = default)
|
||||
{
|
||||
//
|
||||
// Transform the content blocks:
|
||||
//
|
||||
var contentBlocks = new List<Tools.ERIClient.DataModel.ContentBlock>(this.Blocks.Count);
|
||||
foreach (var block in this.Blocks)
|
||||
{
|
||||
var (contentData, contentType) = block.Content switch
|
||||
{
|
||||
ContentImage image => (await image.AsBase64(token), Tools.ERIClient.DataModel.ContentType.IMAGE),
|
||||
ContentText text => (text.Text, Tools.ERIClient.DataModel.ContentType.TEXT),
|
||||
|
||||
_ => (string.Empty, Tools.ERIClient.DataModel.ContentType.UNKNOWN),
|
||||
};
|
||||
|
||||
contentBlocks.Add(new Tools.ERIClient.DataModel.ContentBlock
|
||||
{
|
||||
Role = block.Role switch
|
||||
{
|
||||
ChatRole.AI => Role.AI,
|
||||
ChatRole.USER => Role.USER,
|
||||
ChatRole.AGENT => Role.AGENT,
|
||||
ChatRole.SYSTEM => Role.SYSTEM,
|
||||
ChatRole.NONE => Role.NONE,
|
||||
|
||||
_ => Role.UNKNOWN,
|
||||
},
|
||||
|
||||
Content = contentData,
|
||||
Type = contentType,
|
||||
});
|
||||
}
|
||||
|
||||
return new Tools.ERIClient.DataModel.ChatThread { ContentBlocks = contentBlocks };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using AIStudio.Provider.SelfHosted;
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public static class ChatThreadExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the specified provider is allowed for the chat thread.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We don't check if the provider is allowed to use the data sources of the chat thread.
|
||||
/// That kind of check is done in the RAG process itself.<br/><br/>
|
||||
///
|
||||
/// One thing which is not so obvious: after RAG was used on this thread, the entire chat
|
||||
/// thread is kind of a data source by itself. Why? Because the augmentation data collected
|
||||
/// from the data sources is stored in the chat thread. This means we must check if the
|
||||
/// selected provider is allowed to use this thread's data.
|
||||
/// </remarks>
|
||||
/// <param name="chatThread">The chat thread to check.</param>
|
||||
/// <param name="provider">The provider to check.</param>
|
||||
/// <returns>True, when the provider is allowed for the chat thread. False, otherwise.</returns>
|
||||
public static bool IsLLMProviderAllowed<T>(this ChatThread? chatThread, T provider)
|
||||
{
|
||||
// No chat thread available means we have a new chat. That's fine:
|
||||
if (chatThread is null)
|
||||
return true;
|
||||
|
||||
// The chat thread is available, but the data security is not specified.
|
||||
// Means, we never used RAG or RAG was enabled, but no data sources were selected.
|
||||
// That's fine as well:
|
||||
if (chatThread.DataSecurity is DataSourceSecurity.NOT_SPECIFIED)
|
||||
return true;
|
||||
|
||||
//
|
||||
// Is the provider self-hosted?
|
||||
//
|
||||
var isSelfHostedProvider = provider switch
|
||||
{
|
||||
ProviderSelfHosted => true,
|
||||
AIStudio.Settings.Provider p => p.IsSelfHosted,
|
||||
|
||||
_ => false,
|
||||
};
|
||||
|
||||
//
|
||||
// Check the chat data security against the selected provider:
|
||||
//
|
||||
return isSelfHostedProvider switch
|
||||
{
|
||||
// The provider is self-hosted -- we can use any data source:
|
||||
true => true,
|
||||
|
||||
// The provider is not self-hosted -- it depends on the data security of the chat thread:
|
||||
false => chatThread.DataSecurity is not DataSourceSecurity.SELF_HOSTED,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,15 @@ public class ContentBlock
|
||||
/// <summary>
|
||||
/// The content of the block.
|
||||
/// </summary>
|
||||
public IContent? Content { get; init; } = null;
|
||||
public IContent? Content { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The role of the content block in the chat thread, e.g., user, AI, etc.
|
||||
/// </summary>
|
||||
public ChatRole Role { get; init; } = ChatRole.NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Should the content block be hidden from the user?
|
||||
/// </summary>
|
||||
public bool HideFromUser { get; set; }
|
||||
}
|
||||
@@ -12,7 +12,33 @@
|
||||
<MudText Typo="Typo.body1">@this.Role.ToName() (@this.Time)</MudText>
|
||||
</CardHeaderContent>
|
||||
<CardHeaderActions>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="@this.CopyToClipboard" />
|
||||
@if (this.IsSecondToLastBlock && this.Role is ChatRole.USER && this.EditLastUserBlockFunc is not null)
|
||||
{
|
||||
<MudTooltip Text="Edit" Placement="Placement.Bottom">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Color="Color.Default" OnClick="@this.EditLastUserBlock"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
@if (this.IsLastContentBlock && this.Role is ChatRole.USER && this.EditLastBlockFunc is not null)
|
||||
{
|
||||
<MudTooltip Text="Edit" Placement="Placement.Bottom">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Color="Color.Default" OnClick="@this.EditLastBlock"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
@if (this.IsLastContentBlock && this.Role is ChatRole.AI && this.RegenerateFunc is not null)
|
||||
{
|
||||
<MudTooltip Text="Regenerate" Placement="Placement.Bottom">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Recycling" Color="Color.Default" Disabled="@(!this.RegenerateEnabled())" OnClick="@this.RegenerateBlock"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
@if (this.RemoveBlockFunc is not null)
|
||||
{
|
||||
<MudTooltip Text="Removes this block" Placement="Placement.Bottom">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="@this.RemoveBlock"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
<MudTooltip Text="Copies the content to the clipboard" Placement="Placement.Bottom">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="@this.CopyToClipboard"/>
|
||||
</MudTooltip>
|
||||
</CardHeaderActions>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
@@ -44,7 +70,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudMarkdown Value="@textContent.Text" OverrideHeaderTypo="@Markdown.OverrideHeaderTypo"/>
|
||||
<MudMarkdown Value="@textContent.Text" OverrideHeaderTypo="@Markdown.OverrideHeaderTypo" CodeBlockTheme="@this.CodeColorPalette"/>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,9 +78,9 @@
|
||||
break;
|
||||
|
||||
case ContentType.IMAGE:
|
||||
if (this.Content is ContentImage imageContent)
|
||||
if (this.Content is ContentImage { SourceType: ContentImageSource.URL or ContentImageSource.LOCAL_PATH } imageContent)
|
||||
{
|
||||
<MudImage Src="@imageContent.URL"/>
|
||||
<MudImage Src="@imageContent.Source"/>
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AIStudio.Tools;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -39,14 +40,38 @@ public partial class ContentBlockComponent : ComponentBase
|
||||
[Parameter]
|
||||
public string Class { get; set; } = string.Empty;
|
||||
|
||||
[Inject]
|
||||
private Rust Rust { get; init; } = null!;
|
||||
[Parameter]
|
||||
public bool IsLastContentBlock { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsSecondToLastBlock { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<IContent, Task>? RemoveBlockFunc { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<IContent, Task>? RegenerateFunc { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<IContent, Task>? EditLastBlockFunc { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<IContent, Task>? EditLastUserBlockFunc { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<bool> RegenerateEnabled { get; set; } = () => false;
|
||||
|
||||
[Inject]
|
||||
private IJSRuntime JsRuntime { get; init; } = null!;
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private SettingsManager SettingsManager { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
private bool HideContent { get; set; }
|
||||
|
||||
@@ -67,7 +92,7 @@ public partial class ContentBlockComponent : ComponentBase
|
||||
private async Task AfterStreaming()
|
||||
{
|
||||
// Might be called from a different thread, so we need to invoke the UI thread:
|
||||
await this.InvokeAsync(() =>
|
||||
await this.InvokeAsync(async () =>
|
||||
{
|
||||
//
|
||||
// Issue we try to solve: When the content changes during streaming,
|
||||
@@ -86,6 +111,9 @@ public partial class ContentBlockComponent : ComponentBase
|
||||
|
||||
// Let Blazor update the UI, i.e., to see the render tree diff:
|
||||
this.StateHasChanged();
|
||||
|
||||
// Inform the chat that the streaming is done:
|
||||
await MessageBus.INSTANCE.SendMessage<bool>(this, Event.CHAT_STREAMING_DONE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,7 +128,7 @@ public partial class ContentBlockComponent : ComponentBase
|
||||
{
|
||||
case ContentType.TEXT:
|
||||
var textContent = (ContentText) this.Content;
|
||||
await this.Rust.CopyText2Clipboard(this.JsRuntime, this.Snackbar, textContent.Text);
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, textContent.Text);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -115,4 +143,68 @@ public partial class ContentBlockComponent : ComponentBase
|
||||
}
|
||||
|
||||
private string CardClasses => $"my-2 rounded-lg {this.Class}";
|
||||
|
||||
private CodeBlockTheme CodeColorPalette => this.SettingsManager.IsDarkMode ? CodeBlockTheme.Dark : CodeBlockTheme.Default;
|
||||
|
||||
private async Task RemoveBlock()
|
||||
{
|
||||
if (this.RemoveBlockFunc is null)
|
||||
return;
|
||||
|
||||
var remove = await this.DialogService.ShowMessageBox(
|
||||
"Remove Message",
|
||||
"Do you really want to remove this message?",
|
||||
"Yes, remove it",
|
||||
"No, keep it");
|
||||
|
||||
if (remove.HasValue && remove.Value)
|
||||
await this.RemoveBlockFunc(this.Content);
|
||||
}
|
||||
|
||||
private async Task RegenerateBlock()
|
||||
{
|
||||
if (this.RegenerateFunc is null)
|
||||
return;
|
||||
|
||||
if(this.Role is not ChatRole.AI)
|
||||
return;
|
||||
|
||||
var regenerate = await this.DialogService.ShowMessageBox(
|
||||
"Regenerate Message",
|
||||
"Do you really want to regenerate this message?",
|
||||
"Yes, regenerate it",
|
||||
"No, keep it");
|
||||
|
||||
if (regenerate.HasValue && regenerate.Value)
|
||||
await this.RegenerateFunc(this.Content);
|
||||
}
|
||||
|
||||
private async Task EditLastBlock()
|
||||
{
|
||||
if (this.EditLastBlockFunc is null)
|
||||
return;
|
||||
|
||||
if(this.Role is not ChatRole.USER)
|
||||
return;
|
||||
|
||||
await this.EditLastBlockFunc(this.Content);
|
||||
}
|
||||
|
||||
private async Task EditLastUserBlock()
|
||||
{
|
||||
if (this.EditLastUserBlockFunc is null)
|
||||
return;
|
||||
|
||||
if(this.Role is not ChatRole.USER)
|
||||
return;
|
||||
|
||||
var edit = await this.DialogService.ShowMessageBox(
|
||||
"Edit Message",
|
||||
"Do you really want to edit this message? In order to edit this message, the AI response will be deleted.",
|
||||
"Yes, remove the AI response and edit it",
|
||||
"No, keep it");
|
||||
|
||||
if (edit.HasValue && edit.Value)
|
||||
await this.EditLastUserBlockFunc(this.Content);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an image inside the chat.
|
||||
/// </summary>
|
||||
public sealed class ContentImage : IContent
|
||||
public sealed class ContentImage : IContent, IImageSource
|
||||
{
|
||||
#region Implementation of IContent
|
||||
|
||||
@@ -29,7 +28,7 @@ public sealed class ContentImage : IContent
|
||||
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task CreateFromProviderAsync(IProvider provider, IJSRuntime jsRuntime, SettingsManager settings, Model chatModel, ChatThread chatChatThread, CancellationToken token = default)
|
||||
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -37,12 +36,15 @@ public sealed class ContentImage : IContent
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The URL of the image.
|
||||
/// The type of the image source.
|
||||
/// </summary>
|
||||
public string URL { get; set; } = string.Empty;
|
||||
/// <remarks>
|
||||
/// Is the image source a URL, a local file path, a base64 string, etc.?
|
||||
/// </remarks>
|
||||
public required ContentImageSource SourceType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The local path of the image.
|
||||
/// The image source.
|
||||
/// </summary>
|
||||
public string LocalPath { get; set; } = string.Empty;
|
||||
public required string Source { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public enum ContentImageSource
|
||||
{
|
||||
URL,
|
||||
LOCAL_PATH,
|
||||
BASE64,
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.RAG.RAGProcesses;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
@@ -35,18 +36,43 @@ public sealed class ContentText : IContent
|
||||
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task CreateFromProviderAsync(IProvider provider, IJSRuntime jsRuntime, SettingsManager settings, Model chatModel, ChatThread? chatThread, CancellationToken token = default)
|
||||
public async Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatThread, CancellationToken token = default)
|
||||
{
|
||||
if(chatThread is null)
|
||||
return;
|
||||
return new();
|
||||
|
||||
if(!chatThread.IsLLMProviderAllowed(provider))
|
||||
{
|
||||
var logger = Program.SERVICE_PROVIDER.GetService<ILogger<ContentText>>()!;
|
||||
logger.LogError("The provider is not allowed for this chat thread due to data security reasons. Skipping the AI process.");
|
||||
return chatThread;
|
||||
}
|
||||
|
||||
// Store the last time we got a response. We use this later,
|
||||
// Call the RAG process. Right now, we only have one RAG process:
|
||||
if (lastPrompt is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var rag = new AISrcSelWithRetCtxVal();
|
||||
chatThread = await rag.ProcessAsync(provider, lastPrompt, chatThread, token);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var logger = Program.SERVICE_PROVIDER.GetService<ILogger<ContentText>>()!;
|
||||
logger.LogError(e, "Skipping the RAG process due to an error.");
|
||||
}
|
||||
}
|
||||
|
||||
// Store the last time we got a response. We use this later
|
||||
// to determine whether we should notify the UI about the
|
||||
// new content or not. Depends on the energy saving mode
|
||||
// the user chose.
|
||||
var last = DateTimeOffset.Now;
|
||||
|
||||
// Start another thread by using a task, to uncouple
|
||||
// Get the settings manager:
|
||||
var settings = Program.SERVICE_PROVIDER.GetService<SettingsManager>()!;
|
||||
|
||||
// Start another thread by using a task to uncouple
|
||||
// the UI thread from the AI processing:
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
@@ -54,7 +80,7 @@ public sealed class ContentText : IContent
|
||||
this.InitialRemoteWait = true;
|
||||
|
||||
// Iterate over the responses from the AI:
|
||||
await foreach (var deltaText in provider.StreamChatCompletion(jsRuntime, settings, chatModel, chatThread, token))
|
||||
await foreach (var deltaText in provider.StreamChatCompletion(chatModel, chatThread, settings, token))
|
||||
{
|
||||
// When the user cancels the request, we stop the loop:
|
||||
if (token.IsCancellationRequested)
|
||||
@@ -70,7 +96,7 @@ public sealed class ContentText : IContent
|
||||
// Notify the UI that the content has changed,
|
||||
// depending on the energy saving mode:
|
||||
var now = DateTimeOffset.Now;
|
||||
switch (settings.ConfigurationData.IsSavingEnergy)
|
||||
switch (settings.ConfigurationData.App.IsSavingEnergy)
|
||||
{
|
||||
// Energy saving mode is off. We notify the UI
|
||||
// as fast as possible -- no matter the odds:
|
||||
@@ -89,13 +115,14 @@ public sealed class ContentText : IContent
|
||||
}
|
||||
|
||||
// Stop the waiting animation (in case the loop
|
||||
// was stopped or no content was received):
|
||||
// was stopped, or no content was received):
|
||||
this.InitialRemoteWait = false;
|
||||
this.IsStreaming = false;
|
||||
}, token);
|
||||
|
||||
// Inform the UI that the streaming is done:
|
||||
await this.StreamingDone();
|
||||
return chatThread;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
@@ -42,5 +41,16 @@ public interface IContent
|
||||
/// <summary>
|
||||
/// Uses the provider to create the content.
|
||||
/// </summary>
|
||||
public Task CreateFromProviderAsync(IProvider provider, IJSRuntime jsRuntime, SettingsManager settings, Model chatModel, ChatThread chatChatThread, CancellationToken token = default);
|
||||
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the corresponding ERI content type.
|
||||
/// </summary>
|
||||
public Tools.ERIClient.DataModel.ContentType ToERIContentType => this switch
|
||||
{
|
||||
ContentText => Tools.ERIClient.DataModel.ContentType.TEXT,
|
||||
ContentImage => Tools.ERIClient.DataModel.ContentType.IMAGE,
|
||||
|
||||
_ => Tools.ERIClient.DataModel.ContentType.UNKNOWN,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public interface IImageSource
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the image source.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Is the image source a URL, a local file path, a base64 string, etc.?
|
||||
/// </remarks>
|
||||
public ContentImageSource SourceType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The image source.
|
||||
/// </summary>
|
||||
public string Source { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public static class IImageSourceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Read the image content as a base64 string.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The images are directly converted to base64 strings. The maximum
|
||||
/// size of the image is around 10 MB. If the image is larger, the method
|
||||
/// returns an empty string.
|
||||
///
|
||||
/// As of now, this method does no sort of image processing. LLMs usually
|
||||
/// do not work with arbitrary image sizes. In the future, we might have
|
||||
/// to resize the images before sending them to the model.
|
||||
/// </remarks>
|
||||
/// <param name="image">The image source.</param>
|
||||
/// <param name="token">The cancellation token.</param>
|
||||
/// <returns>The image content as a base64 string; might be empty.</returns>
|
||||
public static async Task<string> AsBase64(this IImageSource image, CancellationToken token = default)
|
||||
{
|
||||
switch (image.SourceType)
|
||||
{
|
||||
case ContentImageSource.BASE64:
|
||||
return image.Source;
|
||||
|
||||
case ContentImageSource.URL:
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
using var response = await httpClient.GetAsync(image.Source, HttpCompletionOption.ResponseHeadersRead, token);
|
||||
if(response.IsSuccessStatusCode)
|
||||
{
|
||||
// Read the length of the content:
|
||||
var lengthBytes = response.Content.Headers.ContentLength;
|
||||
if(lengthBytes > 10_000_000)
|
||||
return string.Empty;
|
||||
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync(token);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
case ContentImageSource.LOCAL_PATH:
|
||||
if(File.Exists(image.Source))
|
||||
{
|
||||
// Read the content length:
|
||||
var length = new FileInfo(image.Source).Length;
|
||||
if(length > 10_000_000)
|
||||
return string.Empty;
|
||||
|
||||
var bytes = await File.ReadAllBytesAsync(image.Source, token);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public static class KnownWorkspaces
|
||||
{
|
||||
public static readonly Guid BIAS_WORKSPACE_ID = Guid.Parse("82050a4e-ee92-43d7-8ee5-ab512f847e02");
|
||||
public static readonly Guid ERI_SERVER_WORKSPACE_ID = Guid.Parse("8ec09cd3-9da7-4736-b245-2d8b67fc342f");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public static class SystemPrompts
|
||||
{
|
||||
public const string DEFAULT = "You are a helpful assistant!";
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
@* ReSharper disable Html.PathError *@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>MindWork AI Studio</title>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<base href="/"/>
|
||||
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
<link href="system/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||
<link href="system/MudBlazor.Markdown/MudBlazor.Markdown.min.css" rel="stylesheet" />
|
||||
<link href="app.css" rel="stylesheet" />
|
||||
<HeadOutlet/>
|
||||
</head>
|
||||
|
||||
<body style="overflow: hidden;">
|
||||
<Routes @rendermode="new InteractiveServerRenderMode(prerender: false)"/>
|
||||
<script src="_framework/blazor.web.js" autostart="false"></script>
|
||||
<script src="boot.js"></script>
|
||||
<script src="system/MudBlazor/MudBlazor.min.js"></script>
|
||||
<script src="system/MudBlazor.Markdown/MudBlazor.Markdown.min.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loaded 100 of 1158 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user