Skip to content

Commit 363a2d1

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth
2 parents 39f9daf + 90828f7 commit 363a2d1

File tree

23 files changed

+272
-140
lines changed

23 files changed

+272
-140
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- badgeTooltip - now you can add a tooltip to the badge to explain what it means
1515
- ability to authorize not only subscription on websocket but filter out whom users message will be published (updated doc)
1616
- added ability to refresh menu item badge from the backend using websocket publish
17+
- fix bugs when e.g. UR (urdu) can't be recognized by LLM (define names explicitly)
18+
- make user menu switch shorter
1719

1820
# Improved
1921

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* [Full API reference](https://adminforth.dev/docs/api/).
1212

1313
<div align="center">
14-
<img src="https://github.com/user-attachments/assets/5921f5f3-feef-40a8-9b82-3df19ac2eedd" alt="Image description" width="800px">
14+
<img src="https://github.com/user-attachments/assets/f507a46b-f282-4f81-97e0-32fceb002ded"
15+
alt="Image description" width="800px">
1516
</div>
1617

1718
Features:

adminforth/adapters/completion-adapter-open-ai-chat-gpt/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export default class CompletionAdapterOpenAIChatGPT
88

99
constructor(options: AdapterOptions) {
1010
this.options = options;
11-
if (!options.openAiApiKey) {
11+
}
12+
13+
validate() {
14+
if (!this.options.openAiApiKey) {
1215
throw new Error("openAiApiKey is required");
1316
}
1417
}

adminforth/adapters/completion-adapter-open-ai-chat-gpt/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/adapters/completion-adapter-open-ai-chat-gpt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adminforth/completion-adapter-open-ai-chat-gpt",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"type": "module",

adminforth/adapters/email-adapter-aws-ses/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ export default class EmailAdapterAwsSes implements EmailAdapter {
77

88
constructor(options: AdapterOptions) {
99
this.options = options;
10-
if (!options.region) {
10+
}
11+
12+
validate() {
13+
if (!this.options.region) {
1114
throw new Error("AWS SES region is required");
1215
}
13-
if (!options.accessKeyId) {
16+
if (!this.options.accessKeyId) {
1417
throw new Error("AWS SES accessKeyId is required");
1518
}
16-
if (!options.secretAccessKey) {
19+
if (!this.options.secretAccessKey) {
1720
throw new Error("AWS SES secretAccessKey is required");
1821
}
1922
}

adminforth/adapters/email-adapter-aws-ses/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/adapters/email-adapter-aws-ses/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adminforth/email-adapter-aws-ses",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"type": "module",

adminforth/documentation/docs/tutorial/06-Advanced/01-plugin-development.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,76 @@ import SubComponent from '@@/plugins/ChatGptPlugin/subComponent.vue';
628628
</script>
629629
```
630630

631-
Pay attention that `ChatGptPlugin` is a class name of your plugin so it should be used in path.
631+
Pay attention that `ChatGptPlugin` is a class name of your plugin so it should be used in path.
632+
633+
634+
## Using Adapters
635+
636+
637+
There are couple of adapter interfaces in AdminForth like `EmailAdapter` for sending emails and `CompletionAdapter`.
638+
Adapter is a way to provide same function from different vendors. For example plugin created in this guide uses exactly OpenAI API to get completion.
639+
But in fact OpenAI is not only one API provider for completion, so `CompletionAdapter` interface is created to be easily extended.
640+
Here is code from AdminForth:
641+
642+
```ts
643+
export interface CompletionAdapter {
644+
645+
validate();
646+
647+
complete(
648+
content: string,
649+
stop: string[],
650+
maxTokens: number,
651+
): Promise<{
652+
content?: string;
653+
finishReason?: string;
654+
error?: string;
655+
}>;
656+
}
657+
```
658+
659+
To use adapter in plugin you should define it in plugin options:
660+
661+
```ts title='./af-plugin-any-complete/types.ts'
662+
663+
import { CompletionAdapter } from "adminforth";
664+
665+
export interface PluginOptions {
666+
...
667+
668+
//diff-add
669+
/**
670+
//diff-add
671+
* Adapter for completion
672+
//diff-add
673+
*/
674+
//diff-add
675+
adapter: CompletionAdapter;
676+
}
677+
```
678+
679+
Then, in your plugin you should call `this.options.validate()`, this function will throw error if adminforth app developer did not pass
680+
required parameter (e.g. API token for OpenAI). You can do it in `modifyResourceConfig` but, then it will be called at build time (e.g. in Dockerfile). However build time not always has access to all environment variables including `OPENAI_API_KEY`.
681+
682+
So we recommend calling validation in `validateConfigAfterDiscover` method because it called only in runtime on app start and not in build time.
683+
684+
```ts title='./af-plugin-any-complete/index.ts'
685+
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
686+
//diff-add
687+
this.options.adapter.validate();
688+
689+
...
690+
}
691+
```
692+
693+
If some issue with config will happen, validate method will throw error and instance will be crashed so AdminForth app developer will see error message in console and will have to fix it before starting app.
694+
695+
Now you can simply use adapter:
696+
697+
```ts title='./af-plugin-any-complete/index.ts'
698+
handler: async (a) => {
699+
...
700+
const resp = await this.options.adapter.complete(content, ['.'], this.options.expert?.maxTokens || 50);
701+
...
702+
}
703+
```

adminforth/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)