Skip to content

Instantly share code, notes, and snippets.

View liuweiathust's full-sized avatar

liuweiathust liuweiathust

View GitHub Profile
@jvelezmagic
jvelezmagic / main.py
Created May 17, 2023 12:05
Langchain FastAPI stream with simple memory
# The goal of this file is to provide a FastAPI application for handling
# chat requests amd generation AI-powered responses using conversation chains.
# The application uses the LangChaing library, which includes a chatOpenAI model
# for natural language processing.
# The `StreamingConversationChain` class is responsible for creating and storing
# conversation memories and generating responses. It utilizes the `ChatOpenAI` model
# and a callback handler to stream responses as they're generated.
# The application defines a `ChatRequest` model for handling chat requests,
@ninely
ninely / main.py
Last active September 15, 2025 10:10
Langchain with fastapi stream example
"""This is an example of how to use async langchain with fastapi and return a streaming response.
The latest version of Langchain has improved its compatibility with asynchronous FastAPI,
making it easier to implement streaming functionality in your applications.
"""
import asyncio
import os
from typing import AsyncIterable, Awaitable
import uvicorn
from dotenv import load_dotenv
@wesleybliss
wesleybliss / docker-compose-node-mongo.yml
Created September 9, 2016 21:37
Docker Compose with example App & Mongo
version: '2'
services:
myapp:
build: .
container_name: "myapp"
image: debian/latest
environment:
- NODE_ENV=development
- FOO=bar
volumes:
@jlewi
jlewi / AvroSpecific
Last active August 29, 2015 14:01
Reading a FastQ file in hadoop
import contrail.AvroHelper
import contrail.spark.SerializableGraphNodeData
val contigFile = contrail.AvroHelper.readAvro(sc,"hdfs://hadoop-nn//tmp/contrail.stages.CompressAndCorrect/part-*.avro")
val datums = contigFile.map(r => new SerializableGraphNodeData(r._1.datum))
val keyedById = datums.map(r => (r.node_id.toString, r))
keyedById.cache()
keyedById.lookup(“4fw3YAOX8-lvVjIWgNPGYR3gc5CvsxI”)
@viktorklang
viktorklang / swingfutures.scala
Created April 19, 2012 17:58
Akka Futures in the Swing Event Dispatch Thread
// © 2012 Viktor Klang
import akka.dispatch.ExecutionContext
import javax.swing.SwingUtilities
import java.util.concurrent.Executor
//
object SwingExecutionContext {
implicit val swingExecutionContext: ExecutionContext = ExecutionContext.fromExecutor(new Executor {
def execute(command: Runnable): Unit = SwingUtilities invokeLater command