Skip to content

Instantly share code, notes, and snippets.

View nicolay-r's full-sized avatar
🤗

Nicolay Rusnachenko nicolay-r

🤗
View GitHub Profile
@nicolay-r
nicolay-r / streaming-llm-replicate-api.js
Last active February 17, 2025 14:44
No-string streaming mode for Replicate LLM models in Javascript
// This is a customized version of the original script:
// https://til.simonwillison.net/llms/streaming-llm-apis
// Adapted for Replicate Streaming API documentation:
// https://replicate.com/docs/topics/predictions/streaming
async function* sseStreamIterator(apiUrl, requestBody, extraHeaders) {
// POST.
let response = await fetch(apiUrl, {
method: 'POST',
@nicolay-r
nicolay-r / llm_streamed_post.js
Last active April 8, 2025 10:26
No-string POST-based stream fetching of LLM output in JavaScript from via REST API hosted by FastAPI
// This is a custom implementation of the POST-based stream fetching for streaming via FastAPI
// https://stackoverflow.com/questions/78826168/how-to-stream-llm-response-from-fastapi-to-react
async function* streamIterator(apiUrl, requestBody, extraHeaders) {
let response = await fetch(apiUrl, {
method: 'POST',
headers: { ...{'Content-Type': 'application/json'}, ...(extraHeaders || {}) },
body: JSON.stringify(requestBody),
});
@nicolay-r
nicolay-r / dicom_sr_template.py
Last active February 18, 2025 12:30
Code for compling a simple SR textual report suitable for uploading at ORTHANC and view via OHIF
import highdicom as hd
from pydicom.sr.codedict import codes
# Define three textual findings
finding = hd.sr.TextContentItem(
name=codes.DCM.Finding,
value="FINDING TEXTUAL CONTENT GOES HERE",
relationship_type=hd.sr.RelationshipTypeValues.CONTAINS)
# Subsection of the Report.