Configurable OpenAI (#2529)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2023-01-24 20:42:47 +07:00
committed by GitHub
parent 3daa9a3136
commit ba8ab45dc2
111 changed files with 2784 additions and 883 deletions
+26
View File
@@ -48,7 +48,9 @@ import { diffWorkspace, dumpWorkspace, restoreWorkspace } from './workspace'
import { Data, getWorkspaceId, Tx, Version } from '@hcengineering/core'
import { MinioService } from '@hcengineering/minio'
import { MigrateOperation } from '@hcengineering/model'
import { openAIConfigDefaults } from '@hcengineering/openai'
import { rebuildElastic } from './elastic'
import { openAIConfig } from './openai'
/**
* @public
@@ -136,6 +138,30 @@ export function devTool (
})
})
program
.command('openai <workspace>')
.description('assign workspace')
.requiredOption('-t, --token <token>', 'OpenAI token')
.option('-h, --host <host>', 'OpenAI API Host', openAIConfigDefaults.endpoint)
.option('--enable <value>', 'Enable or disable', true)
.option('--embeddings <embeddings>', 'Enable or disable embeddings generation', true)
.option('--tokenLimit <tokenLimit>', 'Acceptable token limit', `${openAIConfigDefaults.tokenLimit}`)
.action(
async (
workspace: string,
cmd: { token: string, host: string, enable: string, tokenLimit: string, embeddings: string }
) => {
console.log(`enabling OpenAI for workspace ${workspace}...`)
await openAIConfig(transactorUrl, workspace, productId, {
token: cmd.token,
endpoint: cmd.host,
enabled: cmd.enable === 'true',
tokenLimit: parseInt(cmd.tokenLimit),
embeddings: cmd.embeddings === 'true'
})
}
)
program
.command('show-user <email>')
.description('show user')
+34
View File
@@ -0,0 +1,34 @@
import core, { getWorkspaceId, TxOperations } from '@hcengineering/core'
import openai, { openAIConfigDefaults } from '@hcengineering/openai'
import { connect } from '@hcengineering/server-tool'
export async function openAIConfig (
transactorUrl: string,
workspace: string,
productId: string,
opt: { endpoint: string, token: string, enabled: boolean, tokenLimit: number, embeddings: boolean }
): Promise<void> {
const connection = await connect(transactorUrl, getWorkspaceId(workspace, productId), '#configurator@hc.engineering')
try {
const ops = new TxOperations(connection, core.account.System)
// Check if EmployeeAccoun is not exists
const config = await ops.findOne(openai.class.OpenAIConfiguration, {})
if (config === undefined) {
await ops.createDoc(openai.class.OpenAIConfiguration, core.space.Configuration, {
...openAIConfigDefaults,
...opt
})
} else {
await ops.update(config, {
...openAIConfigDefaults,
...opt
})
}
} catch (err: any) {
console.trace(err)
} finally {
await connection.close()
}
}