Skip to content

Instantly share code, notes, and snippets.

View paztek's full-sized avatar

Matthieu Balmes paztek

View GitHub Profile
@paztek
paztek / call.json
Created December 17, 2023 13:28
Basic chat completions call with tools
{
"model": "gpt-4",
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather at a specific location",
"parameters": {
"type": "object",
@paztek
paztek / business.controller.ts
Created May 16, 2021 20:24
nestjs-count-api-calls-example-1
import { Controller, Get, UseGuards } from '@nestjs/common';
import { AuthGuard } from '../auth/auth.guard';
@UseGuards(AuthGuard)
@Controller()
export class BusinessController {
/**
* This endpoint costs 1 credit per call
*/
@paztek
paztek / manual.strategy.ts
Created August 23, 2020 10:49
nestjs-authentication-example-4
import { HttpService, Injectable } from '@nestjs/common';
import { map } from 'rxjs/operators';
import * as jwt from 'jsonwebtoken';
import { AuthenticationStrategy, KeycloakUserInfoResponse } from '../authentication.strategy';
export class InvalidTokenPublicKeyId extends Error {
constructor(keyId: string) {
super(`Invalid public key ID ${keyId}`);
}
@paztek
paztek / authentication.module.ts
Created August 23, 2020 10:31
nestjs-authentication-example-3
import { HttpModule, Module } from '@nestjs/common';
import { AuthenticationGuard } from './authentication.guard';
import { AuthenticationService } from './authentication.service';
import { AUTHENTICATION_STRATEGY_TOKEN } from './authentication.strategy';
import { KeycloakAuthenticationStrategy } from './strategy/keycloak.strategy';
@Module({
imports: [
HttpModule,
@paztek
paztek / authentication.module.ts
Last active August 23, 2020 10:17
nestjs-authentication-example-2
import { HttpModule, Module } from '@nestjs/common';
import { AuthenticationGuard } from './authentication.guard';
import { AuthenticationService } from './authentication.service';
import { AUTHENTICATION_STRATEGY_TOKEN } from './authentication.strategy';
import { KeycloakAuthenticationStrategy } from './strategy/keycloak.strategy';
import { FakeAuthenticationStrategy } from './strategy/fake.strategy';
@Module({
imports: [
@paztek
paztek / app.module.ts
Last active August 23, 2020 09:06
nestjs-authentication-example-1
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthenticationModule } from './authentication/authentication.module';
@Module({
imports: [
AuthenticationModule,
],
@paztek
paztek / cache.module.ts
Created August 19, 2020 13:04
nestjs-redis-example-2
import {
CACHE_MANAGER,
CacheModule as BaseCacheModule,
Inject,
Logger,
Module,
OnModuleInit,
} from '@nestjs/common';
import * as redisStore from 'cache-manager-ioredis';
import { Cache} from 'cache-manager';
@paztek
paztek / app.controller.ts
Last active March 30, 2022 09:34
nestjs-redis-example-1
import { Body, Controller, Get, Put } from '@nestjs/common';
import { AppService } from './app.service';
@Controller('/hello')
export class AppController {
constructor(
private readonly appService: AppService,
) {}
@paztek
paztek / elasticsearch.module.ts
Last active July 21, 2020 07:06
nestjs-elasticsearch-example-4
import { Logger, Module, OnModuleInit } from '@nestjs/common';
import { ElasticsearchModule as BaseElasticsearchModule, ElasticsearchService } from '@nestjs/elasticsearch';
import { v4 as uuid }from 'uuid';
@Module({
imports: [
BaseElasticsearchModule.register({
node: 'http://localhost:9200',
generateRequestId: () => uuid(),
}),
@paztek
paztek / elasticsearch.module.ts
Created July 20, 2020 07:36
nestjs-elasticsearch-example-3
import { Module, OnModuleInit } from '@nestjs/common';
import { ElasticsearchModule as BaseElasticsearchModule, ElasticsearchService } from '@nestjs/elasticsearch';
import { v4 as uuid }from 'uuid';
@Module({
imports: [
BaseElasticsearchModule.register({
node: 'http://localhost:9200',
generateRequestId: () => uuid(),
}),