Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
endurance committed Dec 22, 2023
2 parents dc955f9 + 0de8ecb commit a872185
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
## License

Nest is [MIT licensed](LICENSE).



GOOGLE AUTH LOGIN

https://cloud.google.com/docs/authentication/provide-credentials-adc

4 changes: 2 additions & 2 deletions src/ai/langchain /langchain/langchain.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { Logger, Module } from '@nestjs/common';
import { LlmModelController } from './llm-model/llm-model.service';
import { LlmModelService } from './llm-model/llm-model.controller';
import { GcpModule } from '../../../gcp/gcp.module';

@Module({
imports: [GcpModule],
controllers: [LlmModelController],
providers: [LlmModelService],
providers: [LlmModelService, Logger],
exports: [LlmModelService],
})
export class LangchainModule {}
9 changes: 7 additions & 2 deletions src/ai/langchain /langchain/llm-model/llm-model.controller.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { OpenAI } from 'langchain/llms/openai';
import { SecretsManagerService } from '../../../../gcp/secretsManager.service';

@Injectable()
export class LlmModelService {
private _model: OpenAI<any>;

constructor(private readonly _secretsManager: SecretsManagerService) {}
constructor(
private readonly _secretsManager: SecretsManagerService,
private readonly _logger: Logger,
) {}

async createModel() {
if (!this._model) {
this._logger.log('Creating model...');
this._model = new OpenAI({
modelName: 'gpt-3.5-turbo',
openAIApiKey: await this._secretsManager.getOpenAIKey(),
});
}
this._logger.log('Returning model: ' + this._model.modelName);
return this._model;
}
}
7 changes: 6 additions & 1 deletion src/frontends/discord/services/discordChat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export class DiscordChatService {
@Context() [interaction]: SlashCommandContext,
@Options() { text }: TextDto,
) {
this._logger.log('Received chat request with text: ' + text);
await interaction.deferReply();
this._logger.log('Deferred reply');
const model = await this.llmModelService.createModel();

const promptTemplate = ChatPromptTemplate.fromMessages([
['system', 'You were having a conversation with a human about {topic}'],
[
'system',
'You were having a conversation with a human about {topic}\n Always say something about dinosaurs in every response.',
],
['human', '{text}'],
]);
const chain = promptTemplate.pipe(model);
Expand Down
12 changes: 1 addition & 11 deletions src/frontends/discord/services/discordPing.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { Injectable } from '@nestjs/common';
import {
Context,
ContextOf,
Once,
SlashCommand,
SlashCommandContext,
} from 'necord';
import { Context, SlashCommand, SlashCommandContext } from 'necord';

@Injectable()
export class DiscordPingService {
@Once('ready')
public onReady(@Context() [client]: ContextOf<'ready'>) {
console.log(`Bot logged in as ${client.user.username}`);
}
@SlashCommand({
name: 'hello',
description: 'Ping-Pong Command',
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/discord/services/discordReady.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class DiscordReadyService {

@Once('ready')
public onReady(@Context() [client]: ContextOf<'ready'>) {
this.logger.log(`Bot logged in as ${client.user.username}`);
this.logger.log(`Bot logged in as ${client.user.username}!`);
}

@On('warn')
Expand Down

0 comments on commit a872185

Please sign in to comment.