Skip to content

Instantly share code, notes, and snippets.

View waptik's full-sized avatar
💻
Learning JavaScript and ReactJS...

Stephane Mensah waptik

💻
Learning JavaScript and ReactJS...
View GitHub Profile
@waptik
waptik / openai.ts
Last active April 29, 2023 10:42
a custom class that makes use of Langchain + openai model
import config from "$config/mod.ts";
import {
initializeAgentExecutorWithOptions,
} from "langchain/agents";
import { BaseLanguageModel } from "langchain/base_language";
import { CallbackManager, ConsoleCallbackHandler } from "langchain/callbacks";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { Calculator } from "langchain/tools/calculator";
import { BaseChatMessage } from "langchain/schema";
import { assert } from "asserts";
@waptik
waptik / upstash_redis_adapter_v0-1.ts
Last active April 2, 2023 08:08
This is an implementation of an adapter powered by upstash redis, for grammy.dev
import { Redis } from "https://deno.land/x/upstash_redis@v1.20.2/mod.ts";
import { StorageAdapter } from "~grammy/deps.ts";
/**
* A storage adapter that uses upstash redis.
* @template T The type of the data to store.
*
* Implementation of StorageAdapter v2 were inspired by @grammyjs/storage-cloudflare
* @see {@link "https://github.com/grammyjs/storages/blob/main/packages/cloudflare/src/kv.ts"}
*/
@waptik
waptik / errors.ts
Created March 24, 2023 20:51
type error when using grammy@1.15.3 with current version of gramm_chat_members plugin
When i hover `chatMembers`, i get:
```
Argument of type 'Composer<ChatMembersContext>' is not assignable to parameter of type 'Middleware<GrammyContext>'.
Type 'Composer<ChatMembersContext>' is not assignable to type 'MiddlewareObj<GrammyContext>'.
The types returned by 'middleware()' are incompatible between these types.
Type 'MiddlewareFn<ChatMembersContext>' is not assignable to type 'MiddlewareFn<GrammyContext>'.
Types of parameters 'ctx' and 'ctx' are incompatible.
Type 'GrammyContext' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'Context'.
@waptik
waptik / errors.ts
Created March 24, 2023 20:51
type error when using grammy@1.15.3 with current version of gramm_chat_members plugin
When i hover `chatMembers`, i get:
```
Argument of type 'Composer<ChatMembersContext>' is not assignable to parameter of type 'Middleware<GrammyContext>'.
Type 'Composer<ChatMembersContext>' is not assignable to type 'MiddlewareObj<GrammyContext>'.
The types returned by 'middleware()' are incompatible between these types.
Type 'MiddlewareFn<ChatMembersContext>' is not assignable to type 'MiddlewareFn<GrammyContext>'.
Types of parameters 'ctx' and 'ctx' are incompatible.
Type 'GrammyContext' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'Context'.
@waptik
waptik / getParticipants.ts
Created January 21, 2023 09:50
[GramJS] - Getting participant object in group and channel chats
// The code below works for both gramjs in node and grm in deno
.... // other imports above
import ChannelParticipants = Api.channels.ChannelParticipants;
import ChatParticipant = Api.ChatParticipant;
import ChannelParticipant = Api.ChannelParticipant;
@waptik
waptik / Upload.tsx
Last active October 13, 2022 20:27
A POC for uploading files to a cloudflare r2 public bucket using presigned url in nextjs
// pages/Upload.tsx
import { getPresignedUrl } from "~/utils/files";
export default function Upload() {
const uploadPhoto = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
const name = encodeURIComponent(file?.name as string);
const type = encodeURIComponent(file?.type as string);
const res = await getPresignedUrl({ name, type, size: "" + file!.size });
@waptik
waptik / Upload.tsx
Created October 13, 2022 20:15
A POC of uploading files to a cloudflare r2 public bucket using presigned url
// pages/Upload.tsx
import { getPresignedUrl } from "~/utils/files";
export default function Upload() {
const uploadPhoto = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
const name = encodeURIComponent(file?.name as string);
const type = encodeURIComponent(file?.type as string);
const res = await getPresignedUrl({ name, type, size: "" + file!.size });
@waptik
waptik / aliceData.ts
Created August 30, 2022 11:12
An example of using the deno's x/epubgen
import {
Chapter,
Options,
} from "epubgen/util/mod.ts";
const date = new Date();
date.setFullYear(2000);
export const optionsAlice: Options = {
import { Column, DataTable } from '@saas-ui/react';
interface ExampleData {
id: string
name: string
email: string
}
const columns: Column<ExampleData>[] = [
@waptik
waptik / bot.ts
Created September 3, 2021 07:39
Custom session adapter for grammyjs using supabase. Please give it a try and comment for feedback
import { Bot, Context, session, SessionFlavor } from 'grammy'
import { CustomSessionAdapter } from './session'
// This bot will collect some basic statistics about each chat. They can be
// retrieved with the `/stats` command.
// This is the data that will be saved per chat.
interface SessionData {
messages: number
edits: number