Skip to content

Instantly share code, notes, and snippets.

@nsadeh
nsadeh / crackpot_system_prompt.txt
Created March 10, 2024 23:04
crackpot_system_prompt
You are a crackpot pseudoscientist. When someone asks you a question, you respond with an answer with a lot of jargon and sciency-sounding terms that makes no sense
@nsadeh
nsadeh / building_llm_applications.md
Created February 29, 2024 21:20
Building LLM Applications notes

Course link

Course Repo

Summary

This course focused on using existing LLMs to build, test, and monitor apps. It introduced various ways to interact with LLMs using the chat endpoint, various ways to think about RAGs and LLM usage patterns, and had a number of guest speakers from various companies talking about their produces and how to use them in conjunction with LLMs to build great applications.

Ways to Evaluate LLM Outputs

This was a key driver for taking this course in the first place. We covered the following ways to evaluate LLM outputs:

@nsadeh
nsadeh / Makefile
Last active February 18, 2024 17:43
Elm <> Tailwind Makefile with elm-watch
PATH := $(PWD)/node_modules/.bin:$(PATH)
SHELL := /bin/bash
# Assumes the following structure:
# source-dir
# - public
# - styles.css (main CSS file with Tailwind directives)
# - index.html (entry index.html with css and javascript links
# - index.js (main JS file that inits Elm app and implements ports
# - src/App.elm (elm entry file)
@nsadeh
nsadeh / EventSubscription.scala
Last active February 5, 2022 23:33
Subscribing to events from another aggregate
// defining the parent entity
object Parent {
sealed trait Command
sealed trait Event
final case class State(...)
val empty: State = ???
def apply(parentId: String) = EventSourcedBehavior(
persistenceId = PersistenceId(parentId),
emptyState = empty,
implicit val spawnSystem = ActorSystem(SpawnProtocol(), "spawn")
def messageRoute =
// pattern matching on the URL
pathPrefix("message" / Segment) { trainerId =>
// await on the webflow materialization pending session actor creation by the spawnSystem
Await.ready(ChatSessionMap.findOrCreate(trainerId).webflow(), Duration.Inf).value.get match {
case Success(value) => handleWebSocketMessages(value)
case Failure(exception) =>
println(exception.getMessage())
import scala.concurrent.{ Future, ExecutionContext }
import akka.actor.typed.{ ActorRef, ActorSystem, SpawnProtocol, Props, DispatcherSelector }
import akka.actor.typed.SpawnProtocol.Spawn
import akka.http.scaladsl.model.ws.{ TextMessage, Message }
import akka.stream.{ FlowShape, OverflowStrategy }
import akka.stream.scaladsl._
import akka.stream.typed.scaladsl.{ ActorSink, ActorSource }
import akka.util.Timeout
import akka.actor.typed.ActorRef
object CoreChatEvents {
import WebSocketsEvents._
sealed trait CoreChatEvent
final case class UserMessage(message: String, phoneNumber: String) extends CoreChatEvent
final case class SMSMessage(sender: String, message: String) extends CoreChatEvent
final case class Connected(websocket: ActorRef[WebSocketsEvent]) extends CoreChatEvent
final case object Disconnected extends CoreChatEvent
@nsadeh
nsadeh / ChatSessionActor.scala
Created August 8, 2020 23:24
Describes a chat session
import akka.actor.typed.{ Behavior, SpawnProtocol, ActorRef }
import akka.actor.typed.scaladsl.Behaviors
object SessionActor {
// protocol - see gist below
import CoreChatEvents._
import WebSocketsEvents._
def receive(websocket: Option[ActorRef[WebSocketsEvent]]): Behavior[CoreChatEvent] = Behaviors.receiveMessage {
@nsadeh
nsadeh / ChatSessionMap.scala
Last active August 8, 2020 23:12
Record of chat sessions
import akka.actor.typed.{ ActorSystem, SpawnProtocol }
object ChatSessionMap {
// mutable data structure holding all the chat sessions. Definition to follow
private var sessions: Map[String, ChatSession] = Map.empty[String, ChatSession]
// only function of this class is to keep track of chat sessions
def findOrCreate(userId: String)(implicit system: ActorSystem[SpawnProtocol.Command]): ChatSession = sessions.getOrElse(userId, create(userId))
@nsadeh
nsadeh / BasicWebSocketsServer.scala
Last active August 9, 2020 17:07
Basic Web Server with an Affirming WebSockets endpoint
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import scala.io.StdIn
import akka.stream.scaladsl.Flow
import akka.http.scaladsl.model.ws.{ Message, TextMessage }
object WebServer extends App {