mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: enhance llm helper support
This commit is contained in:
parent
28ff1b474a
commit
9479e40370
@ -8,9 +8,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "patch-package",
|
"postinstall": "patch-package",
|
||||||
"build:clean": "rm -rf src/.hexabot",
|
"build:clean": "rm -rf src/.hexabot",
|
||||||
"build:channels": "mkdir -p src/.hexabot/channels && find node_modules/ -name 'hexabot-channel-*' -exec cp -R {} src/.hexabot/channels/ \\;",
|
"build:channels": "mkdir -p src/.hexabot/extensions/channels && find node_modules/ -name 'hexabot-channel-*' -exec cp -R {} src/.hexabot/extensions/channels/ \\;",
|
||||||
"build:helpers": "mkdir -p src/.hexabot/helpers && find node_modules/ -name 'hexabot-helper-*' -exec cp -R {} src/.hexabot/helpers/ \\;",
|
"build:helpers": "mkdir -p src/.hexabot/extensions/helpers && find node_modules/ -name 'hexabot-helper-*' -exec cp -R {} src/.hexabot/extensions/helpers/ \\;",
|
||||||
"build:plugins": "mkdir -p src/.hexabot/plugins && find node_modules/ -name 'hexabot-plugin-*' -exec cp -R {} src/.hexabot/plugins/ \\;",
|
"build:plugins": "mkdir -p src/.hexabot/extensions/plugins && find node_modules/ -name 'hexabot-plugin-*' -exec cp -R {} src/.hexabot/extensions/plugins/ \\;",
|
||||||
"build:extensions": "npm run build:channels && npm run build:helpers && npm run build:plugins",
|
"build:extensions": "npm run build:channels && npm run build:helpers && npm run build:plugins",
|
||||||
"build:prepare": "npm run build:clean && npm run build:extensions",
|
"build:prepare": "npm run build:clean && npm run build:extensions",
|
||||||
"build": "npm run build:prepare && nest build",
|
"build": "npm run build:prepare && nest build",
|
||||||
|
@ -33,7 +33,7 @@ export interface ChannelModuleOptions {
|
|||||||
// Core & under dev channels
|
// Core & under dev channels
|
||||||
'dist/extensions/**/*.channel.js',
|
'dist/extensions/**/*.channel.js',
|
||||||
// Installed channels via npm
|
// Installed channels via npm
|
||||||
'dist/.hexabot/channels/**/*.channel.js',
|
'dist/.hexabot/extensions/channels/**/*.channel.js',
|
||||||
)
|
)
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [WebhookController, ChannelController],
|
controllers: [WebhookController, ChannelController],
|
||||||
|
@ -59,12 +59,21 @@ export default class OllamaLlmHelper
|
|||||||
*
|
*
|
||||||
* @param prompt - The input text from the user
|
* @param prompt - The input text from the user
|
||||||
* @param model - The model to be used
|
* @param model - The model to be used
|
||||||
|
* @param systemPrompt - The input text from the system
|
||||||
* @returns {Promise<string>} - The generated response from the LLM
|
* @returns {Promise<string>} - The generated response from the LLM
|
||||||
*/
|
*/
|
||||||
async generateResponse(prompt: string, model: string): Promise<string> {
|
async generateResponse(
|
||||||
|
prompt: string,
|
||||||
|
model: string,
|
||||||
|
system: string,
|
||||||
|
{ keepAlive = '5m', options = {} },
|
||||||
|
): Promise<string> {
|
||||||
const response = await this.client.generate({
|
const response = await this.client.generate({
|
||||||
model,
|
model,
|
||||||
prompt,
|
prompt,
|
||||||
|
system: system,
|
||||||
|
keep_alive: keepAlive,
|
||||||
|
options,
|
||||||
});
|
});
|
||||||
|
|
||||||
return response.response ? response.response : '';
|
return response.response ? response.response : '';
|
||||||
|
@ -75,7 +75,10 @@ export class OllamaPlugin extends BaseBlockPlugin<typeof SETTINGS> {
|
|||||||
|
|
||||||
const options = this.settings
|
const options = this.settings
|
||||||
.filter(
|
.filter(
|
||||||
(setting) => 'subgroup' in setting && setting.subgroup === 'options',
|
(setting) =>
|
||||||
|
'subgroup' in setting &&
|
||||||
|
setting.subgroup === 'options' &&
|
||||||
|
setting.value !== null,
|
||||||
)
|
)
|
||||||
.reduce((acc, { label }) => {
|
.reduce((acc, { label }) => {
|
||||||
acc[label] = args[label];
|
acc[label] = args[label];
|
||||||
|
@ -18,7 +18,7 @@ import { HelperService } from './helper.service';
|
|||||||
// Core & under dev helpers
|
// Core & under dev helpers
|
||||||
'dist/extensions/**/*.helper.js',
|
'dist/extensions/**/*.helper.js',
|
||||||
// Installed helpers via npm
|
// Installed helpers via npm
|
||||||
'dist/.hexabot/helpers/**/*.helper.js',
|
'dist/.hexabot/extensions/helpers/**/*.helper.js',
|
||||||
)
|
)
|
||||||
@Module({
|
@Module({
|
||||||
imports: [HttpModule],
|
imports: [HttpModule],
|
||||||
|
@ -34,9 +34,16 @@ export default abstract class BaseLlmHelper<
|
|||||||
*
|
*
|
||||||
* @param prompt - The input text from the user
|
* @param prompt - The input text from the user
|
||||||
* @param model - The model to be used
|
* @param model - The model to be used
|
||||||
|
* @param systemPrompt - The input text from the system
|
||||||
|
* @param extra - Extra options
|
||||||
* @returns {Promise<string>} - The generated response from the LLM
|
* @returns {Promise<string>} - The generated response from the LLM
|
||||||
*/
|
*/
|
||||||
abstract generateResponse(prompt: string, model: string): Promise<string>;
|
abstract generateResponse(
|
||||||
|
prompt: string,
|
||||||
|
model: string,
|
||||||
|
systemPrompt: string,
|
||||||
|
extra?: any,
|
||||||
|
): Promise<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a chat completion request with the conversation history.
|
* Send a chat completion request with the conversation history.
|
||||||
@ -46,6 +53,7 @@ export default abstract class BaseLlmHelper<
|
|||||||
* @param prompt - The input text from the user
|
* @param prompt - The input text from the user
|
||||||
* @param model - The model to be used
|
* @param model - The model to be used
|
||||||
* @param history - Array of messages
|
* @param history - Array of messages
|
||||||
|
* @param extra - Extra options
|
||||||
* @returns {Promise<string>} - The generated response from the LLM
|
* @returns {Promise<string>} - The generated response from the LLM
|
||||||
*/
|
*/
|
||||||
abstract generateChatCompletion(
|
abstract generateChatCompletion(
|
||||||
|
@ -24,7 +24,7 @@ import { PluginService } from './plugins.service';
|
|||||||
// Core & under dev plugins
|
// Core & under dev plugins
|
||||||
'dist/extensions/**/*.plugin.js',
|
'dist/extensions/**/*.plugin.js',
|
||||||
// Installed plugins via npm
|
// Installed plugins via npm
|
||||||
'dist/.hexabot/plugins/**/*.plugin.js',
|
'dist/.hexabot/extensions/plugins/**/*.plugin.js',
|
||||||
)
|
)
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
|
@ -18,6 +18,7 @@ import { I18nService } from '@/i18n/services/i18n.service';
|
|||||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||||
|
|
||||||
import { Setting } from '../schemas/setting.schema';
|
import { Setting } from '../schemas/setting.schema';
|
||||||
|
import { SettingType } from '../schemas/types';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SettingRepository extends BaseRepository<Setting> {
|
export class SettingRepository extends BaseRepository<Setting> {
|
||||||
@ -43,9 +44,14 @@ export class SettingRepository extends BaseRepository<Setting> {
|
|||||||
setting: Document<unknown, unknown, Setting> &
|
setting: Document<unknown, unknown, Setting> &
|
||||||
Setting & { _id: Types.ObjectId },
|
Setting & { _id: Types.ObjectId },
|
||||||
) {
|
) {
|
||||||
if (setting.type === 'text' && typeof setting.value !== 'string') {
|
if (
|
||||||
|
(setting.type === SettingType.text ||
|
||||||
|
setting.type === SettingType.textarea) &&
|
||||||
|
typeof setting.value !== 'string' &&
|
||||||
|
setting.value !== null
|
||||||
|
) {
|
||||||
throw new Error('Setting Model : Value must be a string!');
|
throw new Error('Setting Model : Value must be a string!');
|
||||||
} else if (setting.type === 'multiple_text') {
|
} else if (setting.type === SettingType.multiple_text) {
|
||||||
const isStringArray =
|
const isStringArray =
|
||||||
Array.isArray(setting.value) &&
|
Array.isArray(setting.value) &&
|
||||||
setting.value.every((v) => {
|
setting.value.every((v) => {
|
||||||
@ -55,10 +61,18 @@ export class SettingRepository extends BaseRepository<Setting> {
|
|||||||
throw new Error('Setting Model : Value must be a string array!');
|
throw new Error('Setting Model : Value must be a string array!');
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
setting.type === 'checkbox' &&
|
setting.type === SettingType.checkbox &&
|
||||||
typeof setting.value !== 'boolean'
|
typeof setting.value !== 'boolean' &&
|
||||||
|
setting.value !== null
|
||||||
) {
|
) {
|
||||||
throw new Error('Setting Model : Value must be a boolean!');
|
throw new Error('Setting Model : Value must be a boolean!');
|
||||||
|
} else if (
|
||||||
|
setting.type === SettingType.number &&
|
||||||
|
typeof setting.value !== 'number' &&
|
||||||
|
setting.value !== null
|
||||||
|
) {
|
||||||
|
console.log(setting);
|
||||||
|
throw new Error('Setting Model : Value must be a number!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*", "src/.hexabot/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
Loading…
Reference in New Issue
Block a user