Skip to content

Commit

Permalink
Merge branch 'develop' into server-4710-spaceAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
techsmyth authored Dec 6, 2024
2 parents 06c2439 + faba13c commit 6f0516d
Show file tree
Hide file tree
Showing 78 changed files with 1,526 additions and 781 deletions.
24 changes: 24 additions & 0 deletions .build/ory/oathkeeper/access-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
- unauthorized
- forbidden

- id: 'alkemio:graphiql:protected'
upstream:
preserve_host: true
url: 'http://host.docker.internal:4000'
match:
url: 'http://localhost:3000/graphiql'
methods:
- POST
- GET
authenticators:
- handler: cookie_session
- handler: noop
authorizer:
handler: allow
mutators:
- handler: id_token
errors:
- handler: redirect
config:
to: http://localhost:3000/login
when:
- error:
- unauthorized
- forbidden

- id: 'alkemio:api:private:rest:storage'
upstream:
Expand Down
6 changes: 6 additions & 0 deletions .build/traefik/http.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ http:
entryPoints:
- 'web'

graphiql:
rule: 'PathPrefix(`/graphiql`)'
service: 'oathkeeper-proxy'
entryPoints:
- 'web'

api-public-graphql:
rule: 'PathPrefix(`/api/public/graphql`)'
service: 'alkemio-server'
Expand Down
10 changes: 9 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ RABBITMQ_INGEST_SPACE_QUEUE=virtual-contributor-ingest-space
RABBITMQ_INGEST_SPACE_RESULT_QUEUE=virtual-contributor-ingest-space-result
RABBITMQ_EVENT_BUS_EXCHANGE=event-bus

RABBITMQ_RESULT_QUEUE=virtual-contributor-invoke-engine-result
RABBITMQ_RESULT_ROUTING_KEY=invoke-engine-result

ALKEMIO_SERVER_ENDPOINT=http://host.docker.internal:4000/graphql
KRATOS_API_PUBLIC_ENDPOINT=http://kratos:4433/
[email protected]
Expand All @@ -46,16 +49,21 @@ AI_LOCAL_PATH=/home/alkemio/data
OPENAI_API_VERSION=2023-05-15
AZURE_OPENAI_ENDPOINT=https://alkemio-gpt.openai.azure.com
AZURE_OPENAI_API_KEY=your-openai-key
AZURE_MISTRAL_ENDPOINT=https://Mistral-small-alkemio-serverless.swedencentral.inference.ai.azure.com
AZURE_MISTRAL_API_KEY=mistral-api-key
LLM_DEPLOYMENT_NAME=deploy-gpt-35-turbo
EMBEDDINGS_DEPLOYMENT_NAME=embedding
AI_MODEL_TEMPERATURE=0.3
AI_SOURCE_WEBSITE=https://www.alkemio.org
AI_SOURCE_WEBSITE2=https://welcome.alkem.io

AI_WEBSITE_REPO=github.com/alkem-io/website.git
AI_WEBSITE_REPO2=github.com/alkem-io/welcome-site.git

AI_GITHUB_USER=your-github-user
AI_GITHUB_PAT=your-github-pat
LANGCHAIN_TRACING_V2=true

LANGCHAIN_TRACING_V2=false
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_API_KEY=your-langchain-key
LANGCHAIN_PROJECT=guidance-engine
Expand Down
36 changes: 36 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
"dataloader": "^2.2.2",
"graphql": "^16.9.0",
"graphql-amqp-subscriptions": "^2.0.0",
"graphql-helix": "^1.13.0",
"graphql-http": "^1.22.3",
"graphql-subscriptions": "^2.0.0",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^13.0.0",
Expand Down
14 changes: 12 additions & 2 deletions quickstart-services-ai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ services:
virtual_contributor_engine_guidance:
container_name: alkemio_dev_virtual_contributor_engine_guidance
hostname: virtual-contributor-engine-guidance
image: alkemio/virtual-contributor-engine-guidance:v0.7.1
image: alkemio/virtual-contributor-engine-guidance:v0.8.2
platform: linux/x86_64
restart: always
volumes:
Expand All @@ -339,6 +339,11 @@ services:
- RABBITMQ_USER
- RABBITMQ_PASSWORD
- RABBITMQ_QUEUE=virtual-contributor-engine-guidance
- RABBITMQ_EVENT_BUS_EXCHANGE
- RABBITMQ_RESULT_QUEUE
- RABBITMQ_RESULT_ROUTING_KEY
- AZURE_MISTRAL_ENDPOINT
- AZURE_MISTRAL_API_KEY
- ENVIRONMENT=dev
- EMBEDDINGS_DEPLOYMENT_NAME
- AZURE_OPENAI_API_KEY
Expand Down Expand Up @@ -396,7 +401,7 @@ services:
- 'host.docker.internal:host-gateway'
container_name: alkemio_dev_virtual_contributor_engine_expert
hostname: virtual-contributor-engine-expert
image: alkemio/virtual-contributor-engine-expert:v0.5.0
image: alkemio/virtual-contributor-engine-expert:v0.10.0
platform: linux/x86_64
restart: always
volumes:
Expand All @@ -412,6 +417,11 @@ services:
- RABBITMQ_PASSWORD
- RABBITMQ_PORT
- RABBITMQ_QUEUE=virtual-contributor-engine-expert
- RABBITMQ_EVENT_BUS_EXCHANGE
- RABBITMQ_RESULT_QUEUE
- RABBITMQ_RESULT_ROUTING_KEY
- AZURE_MISTRAL_ENDPOINT
- AZURE_MISTRAL_API_KEY
- API_ENDPOINT_PRIVATE_GRAPHQL=http://host.docker.internal:3000/api/private/non-interactive/graphql
- AUTH_ORY_KRATOS_PUBLIC_BASE_URL=http://host.docker.internal:3000/ory/kratos/public
- AUTH_ADMIN_EMAIL
Expand Down
4 changes: 4 additions & 0 deletions src/common/enums/ai.persona.invocation.operation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum InvocationOperation {
QUERY = 'query',
INGEST = 'ingest',
}
1 change: 1 addition & 0 deletions src/common/enums/room.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export enum RoomType {
DISCUSSION_FORUM = 'discussion_forum',
UPDATES = 'updates',
CALLOUT = 'callout',
GUIDANCE = 'guidance',
}
2 changes: 2 additions & 0 deletions src/core/bootstrap/bootstrap.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import { TemplateDefaultModule } from '@domain/template/template-default/templat
import { LicenseModule } from '@domain/common/license/license.module';
import { LicensePlanModule } from '@platform/license-plan/license.plan.module';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';
import { AiPersonaServiceModule } from '@services/ai-server/ai-persona-service/ai.persona.service.module';

@Module({
imports: [
AiServerModule,
AiPersonaServiceModule,
AgentModule,
AuthorizationPolicyModule,
LicenseModule,
Expand Down
46 changes: 46 additions & 0 deletions src/core/bootstrap/bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ import { LicenseService } from '@domain/common/license/license.service';
import { AccountLicenseService } from '@domain/space/account/account.service.license';
import { LicensePlanService } from '@platform/license-plan/license.plan.service';
import { LicensingFrameworkService } from '@platform/licensing-framework/licensing.framework.service';
import { AiPersonaServiceService } from '@services/ai-server/ai-persona-service/ai.persona.service.service';
import { AiPersonaEngine } from '@common/enums/ai.persona.engine';
import { AiPersonaBodyOfKnowledgeType } from '@common/enums/ai.persona.body.of.knowledge.type';
import { AiPersonaDataAccessMode } from '@common/enums/ai.persona.data.access.mode';

@Injectable()
export class BootstrapService {
Expand All @@ -82,6 +86,7 @@ export class BootstrapService {
@Inject(WINSTON_MODULE_NEST_PROVIDER)
private readonly logger: LoggerService,
private aiServer: AiServerService,
private aiPersonaServiceService: AiPersonaServiceService,
private aiServerAuthorizationService: AiServerAuthorizationService,
private templatesManagerService: TemplatesManagerService,
private templatesSetService: TemplatesSetService,
Expand Down Expand Up @@ -113,6 +118,7 @@ export class BootstrapService {
await this.ensurePlatformTemplatesArePresent();
await this.ensureOrganizationSingleton();
await this.ensureSpaceSingleton();
await this.ensureGuidanceChat();
await this.ensureSsiPopulated();
// reset auth as last in the actions
// await this.ensureSpaceNamesInElastic();
Expand Down Expand Up @@ -524,4 +530,44 @@ export class BootstrapService {
return this.spaceService.getSpaceOrFail(space.id);
}
}

private async ensureGuidanceChat() {
const platform = await this.platformService.getPlatformOrFail({
relations: { guidanceVirtualContributor: true },
});
if (!platform.guidanceVirtualContributor?.id) {
const aiPersonaService =
await this.aiPersonaServiceService.createAiPersonaService({
bodyOfKnowledgeID: '',
bodyOfKnowledgeType: AiPersonaBodyOfKnowledgeType.NONE,
engine: AiPersonaEngine.GUIDANCE,
dataAccessMode: AiPersonaDataAccessMode.NONE,
prompt: [],
externalConfig: undefined,
});

// Get admin account:
const hostOrganization =
await this.organizationService.getOrganizationOrFail(
DEFAULT_HOST_ORG_NAMEID
);
const account =
await this.organizationService.getAccount(hostOrganization);

// Create the VC
const vc = await this.accountService.createVirtualContributorOnAccount({
accountID: account.id,
aiPersona: {
aiPersonaServiceID: aiPersonaService.id,
},
profileData: {
displayName: 'Guidance',
description: 'Guidance Virtual Contributor',
},
});

platform.guidanceVirtualContributor = vc;
await this.platformService.savePlatform(platform);
}
}
}
6 changes: 0 additions & 6 deletions src/core/microservices/client.proxy.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ 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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/microservices/microservices.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const excalidrawPubSubFactoryProvider = subscriptionFactoryProvider(
provide: VIRTUAL_CONTRIBUTOR_ENGINE_GUIDANCE,
useFactory: clientProxyFactory(
MessagingQueue.VIRTUAL_CONTRIBUTOR_ENGINE_GUIDANCE,
false
true
),

inject: [WINSTON_MODULE_NEST_PROVIDER, ConfigService],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { IAnswerToQuestionSource } from './message.answer.to.question.source.interface';

@ObjectType('MessageAnswerQuestion', {
description: 'A detailed answer to a question, typically from an AI service.',
})
export class IMessageAnswerToQuestion {
export class IMessageGuidanceQuestionResult {
@Field(() => String, {
nullable: true,
description: 'The id of the answer; null if an error was returned',
Expand All @@ -17,17 +16,16 @@ export class IMessageAnswerToQuestion {
})
question!: string;

@Field(() => [IAnswerToQuestionSource], {
@Field(() => String, {
nullable: true,
description: 'The sources used to answer the question',
description: 'Error message if an error occurred',
})
sources?: IAnswerToQuestionSource[];
error?: string;

@Field(() => String, {
@Field(() => Boolean, {
nullable: false,
description: 'The answer to the question',
description:
'Message successfully sent. If false, error will have the reason.',
})
answer!: string;

threadId?: string;
success!: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ import { VirtualContributor } from '@domain/community/virtual-contributor/virtua
providers: [],
exports: [],
})
export class MessageAnswerToQuestionModule {}
export class MessageGuidanceQuestionResultModule {}
5 changes: 2 additions & 3 deletions src/domain/communication/message/message.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { MessageResolverFields } from './message.resolver.fields';
import { ContributorLookupModule } from '@services/infrastructure/contributor-lookup/contributor.lookup.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { VirtualContributor } from '@domain/community/virtual-contributor/virtual.contributor.entity';
import { MessageService } from './message.service';

@Module({
imports: [
ContributorLookupModule,
TypeOrmModule.forFeature([VirtualContributor]),
],
providers: [MessageResolverFields, MessageService],
exports: [MessageResolverFields, MessageService],
providers: [MessageResolverFields],
exports: [MessageResolverFields],
})
export class MessageModule {}
Loading

0 comments on commit 6f0516d

Please sign in to comment.