Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow external LLM providers integration #4561

Merged
merged 15 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alkemio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ security:
# Cors allowed headers.
allowed_headers: ${CORS_ALLOWED_HEADERS}:Origin,X-Requested-With,Content-Type,Accept,Authorization

encryption_key: ${ENCRYPTION_KEY}
valentinyanakiev marked this conversation as resolved.
Show resolved Hide resolved

valeksiev marked this conversation as resolved.
Show resolved Hide resolved
valeksiev marked this conversation as resolved.
Show resolved Hide resolved
innovation_hub:
header: ${INNOVATION_HUB_HEADER}:origin

Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@apollo/server": "^4.10.4",
"@elastic/elasticsearch": "^8.12.2",
"@golevelup/nestjs-rabbitmq": "^5.3.0",
"@hedger/nestjs-encryption": "^0.1.5",
"@nestjs/apollo": "^12.2.0",
"@nestjs/axios": "^3.0.2",
"@nestjs/cache-manager": "^2.2.2",
Expand Down
49 changes: 49 additions & 0 deletions quickstart-services-ai.yml
valentinyanakiev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,52 @@ services:
- AUTH_ORY_KRATOS_PUBLIC_BASE_URL=http://localhost:3000/ory/kratos/public
- CHUNK_SIZE=1000
- CHUNK_OVERLAP=100

virtual_contributor_engine_generic:
container_name: alkemio_dev_virtual_contributor_engine_generic
hostname: virtual-contributor-engine-generic
image: alkemio/virtual-contributor-engine-generic:v0.1.1
platform: linux/x86_64
restart: always
volumes:
- /dev/shm:/dev/shm
networks:
- alkemio_dev_net
depends_on:
rabbitmq:
condition: "service_healthy"
environment:
- RABBITMQ_HOST
- RABBITMQ_USER
- RABBITMQ_PASSWORD
- RABBITMQ_PORT
- RABBITMQ_QUEUE=virtual-contributor-engine-generic
- LOCAL_PATH=./
- LOG_LEVEL=DEBUG
- LANGCHAIN_TRACING_V2
- LANGCHAIN_ENDPOINT
- LANGCHAIN_API_KEY
- LANGCHAIN_PROJECT=virtual-contributor-engine-generic
- HISTORY_LENGTH=20

virtual_contributor_engine_openai_assistant:
container_name: alkemio_dev_virtual_contributor_engine_openai_assistant
hostname: virtual-contributor-engine-openai-assistant
image: alkemio/virtual-contributor-engine-openai-assistant:v0.1.0
platform: linux/x86_64
restart: always
volumes:
- /dev/shm:/dev/shm
networks:
- alkemio_dev_net
depends_on:
rabbitmq:
condition: "service_healthy"
environment:
- RABBITMQ_HOST
- RABBITMQ_USER
- RABBITMQ_PASSWORD
- RABBITMQ_PORT
- RABBITMQ_QUEUE=virtual-contributor-engine-openai-assistant
- LOCAL_PATH=./
- LOG_LEVEL=DEBUG
15 changes: 15 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,24 @@ import { LookupByNameModule } from '@services/api/lookup-by-name';
import { PlatformHubModule } from '@platform/platfrom.hub/platform.hub.module';
import { AdminContributorsModule } from '@platform/admin/avatars/admin.avatar.module';
import { InputCreatorModule } from '@services/api/input-creator/input.creator.module';
import { Cipher, EncryptionModule } from '@hedger/nestjs-encryption';

@Module({
imports: [
EncryptionModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService<AlkemioConfig, true>) => {
const key = configService.get('security.encryption_key', {
infer: true,
});

return {
key,
cipher: Cipher.AES_256_CBC,
};
},
}),
ConfigModule.forRoot({
envFilePath: ['.env'],
isGlobal: true,
Expand Down
4 changes: 4 additions & 0 deletions src/common/constants/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const VIRTUAL_CONTRIBUTOR_ENGINE_COMMUNITY_MANAGER =
'virtual-contributor-engine-community-manager';
export const VIRTUAL_CONTRIBUTOR_ENGINE_EXPERT =
'virtual-contributor-engine-expert';
export const VIRTUAL_CONTRIBUTOR_ENGINE_GENERIC =
'virtual-contributor-engine-generic';
export const VIRTUAL_CONTRIBUTOR_ENGINE_OPENAI_ASSISTANT =
'virtual-contributor-engine-openai-assistant';
export const NOTIFICATIONS_SERVICE = 'alkemio-notifications';
export const WALLET_MANAGEMENT_SERVICE = 'alkemio-wallet-manager';
export const REDIS_LOCK_SERVICE = 'redis-lock-service';
Expand Down
2 changes: 2 additions & 0 deletions src/common/enums/ai.persona.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { registerEnumType } from '@nestjs/graphql';
export enum AiPersonaEngine {
GUIDANCE = 'guidance',
EXPERT = 'expert',
GENERIC_OPENAI = 'generic-openai',
OPENAI_ASSISTANT = 'openai-assistant',
COMMUNITY_MANAGER = 'community-manager',
}

Expand Down
4 changes: 4 additions & 0 deletions src/common/enums/logging.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export enum LogContext {
INNOVATION_FLOW = 'innovation-flow',
FILE_INTEGRATION = 'file-integration',
VIRTUAL_CONTRIBUTOR = 'virtual-contributor',
VIRTUAL_CONTRIBUTOR_ENGINE_GENERIC = 'virtual-contributor-engine-generic',
VIRTUAL_CONTRIBUTOR_ENGINE_OPENAI_ASSISTANT = 'virtual-contributor-openai-assistant',
VIRTUAL_CONTRIBUTOR_ENGINE_EXPERT = 'virtual-contributor-engine-expert',
VIRTUAL_CONTRIBUTOR_ENGINE_COMMUNITY_MANAGER = 'virtual-contributor-engine-community-manager',
AI_SERVER = 'ai-server',
AI_SERVER_ADAPTER = 'ai-server-adapter',
AI_PERSONA_SERVICE = 'ai-persona-service',
Expand Down
2 changes: 2 additions & 0 deletions src/common/enums/messaging.queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export enum MessagingQueue {
VIRTUAL_CONTRIBUTOR_ENGINE_GUIDANCE = 'virtual-contributor-engine-guidance',
VIRTUAL_CONTRIBUTOR_ENGINE_COMMUNITY_MANAGER = 'virtual-contributor-engine-community-manager',
VIRTUAL_CONTRIBUTOR_ENGINE_EXPERT = 'virtual-contributor-engine-expert',
VIRTUAL_CONTRIBUTOR_ENGINE_GENERIC = 'virtual-contributor-engine-generic',
VIRTUAL_CONTRIBUTOR_ENGINE_OPENAI_ASSISTANT = 'virtual-contributor-engine-openai-assistant',
valeksiev marked this conversation as resolved.
Show resolved Hide resolved
valentinyanakiev marked this conversation as resolved.
Show resolved Hide resolved
//
WALLET_MANAGER = 'alkemio-wallet-manager',
NOTIFICATIONS = 'alkemio-notifications',
Expand Down
2 changes: 1 addition & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default () => {
const envConfig = process.env;

YAML.visit(doc, {
Scalar(key, node) {
Scalar(_key, node) {
if (node.type === 'PLAIN') {
node.value = buildYamlNodeValue(node.value, envConfig);
}
Expand Down
35 changes: 0 additions & 35 deletions src/core/microservices/auth.reset.service.factory.ts

This file was deleted.

45 changes: 45 additions & 0 deletions src/core/microservices/client.proxy.factory.ts
valentinyanakiev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { LogContext, MessagingQueue } from '@common/enums';
import { LoggerService } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ClientProxyFactory, Transport } from '@nestjs/microservices';
import { AlkemioConfig } from '@src/types';

const QUEUE_CONTEXT_MAP: { [key in MessagingQueue]?: LogContext } = {
[MessagingQueue.AUTH_RESET]: LogContext.AUTH,
[MessagingQueue.VIRTUAL_CONTRIBUTOR_ENGINE_OPENAI_ASSISTANT]:
LogContext.VIRTUAL_CONTRIBUTOR_ENGINE_OPENAI_ASSISTANT,
[MessagingQueue.VIRTUAL_CONTRIBUTOR_ENGINE_GENERIC]:
LogContext.VIRTUAL_CONTRIBUTOR_ENGINE_GENERIC,
[MessagingQueue.VIRTUAL_CONTRIBUTOR_ENGINE_EXPERT]:
LogContext.VIRTUAL_CONTRIBUTOR_ENGINE_EXPERT,
};

export const clientProxyFactory = (queue: MessagingQueue, durable = true) => {
const context = QUEUE_CONTEXT_MAP[queue];
return async (
logger: LoggerService,
configService: ConfigService<AlkemioConfig, true>
) => {
try {
const rabbitMqOptions = configService.get('microservices.rabbitmq', {
infer: true,
});
const { user, password, host, port } = rabbitMqOptions.connection;
const connectionString = `amqp://${user}:${password}@${host}:${port}?heartbeat=30`;

const options = {
urls: [connectionString],
queue,
queueOptions: {
// the queue will survive a broker restart
durable,
},
noAck: true,
};
valentinyanakiev marked this conversation as resolved.
Show resolved Hide resolved
return ClientProxyFactory.create({ transport: Transport.RMQ, options });
} catch (err) {
logger.error(`Could not connect to RabbitMQ: ${err}`, context);
return undefined;
}
};
};
35 changes: 0 additions & 35 deletions src/core/microservices/matrix.adapter.service.factory.ts

This file was deleted.

Loading