Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add natural pattern for delineating between streaming and sync LLM output #29

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions hn_analysis_report.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
When you sift through the latest chatter on Hacker News, it’s like walking into a buzzing café where software engineers and tech enthusiasts sip their coffee and debate the next big thing. Here’s a rundown of the trends that have them leaning forward in their seats or shaking their heads.
When you sift through the vibrant exchanges on Hacker News, you start to see patterns in the chaos. It's like peering into a crystal ball, albeit one that's a bit cracked and smudged with fingerprints. The topics buzzing around tell us a lot about where technology is heading and what’s gnawing at the minds of those in the trenches.

## Themes with a Thumbs Up
### Exciting Waves in Tech

1. **Gaming on the Web’s Frontier**: Remember when games on the web were like those old handheld consoles? Times have changed. Projects like [Eonfall](https://news.ycombinator.com/item?id=42480624) are proving that you can have rich, cooperative action experiences right in your browser. Using Unity and Nuxt 3, they’re pushing the envelope, despite some bugs. It’s like when the first iPhone came out—flawed but revolutionary.
1. **AI and Machine Learning:**
AI is the new electricity, lighting up the imagination of everyone from garage tinkerers to corporate juggernauts. Take, for instance, the buzz around [Semantic Search for ArXiv Papers](https://news.ycombinator.com/item?id=42507116). It's a project that uses AI to sift through the academic haystack to find those elusive needles. The real excitement lies in AI's potential to revolutionize fields like healthcare by making diagnostics smarter, or code smarter by augmenting software development.

2. **AI in Everyday Objects**: Integrating AI into microcontrollers, as seen with [openai-realtime-embedded-SDK](https://news.ycombinator.com/item?id=42451409), is like putting a brain into your toaster. Suddenly, the mundane becomes interesting. The potential here is vast, from smart homes to smarter appliances. It’s AI stepping off the cloud and into the real world.
2. **Cutting-Edge Development Tools:**
Developers are always on the hunt for ways to do more with less hassle. Enter tools like [Cudair](https://news.ycombinator.com/item?id=42484994), which offers live-reloading for CUDA applications. Such innovations are like giving a chef a sharper knife—they can still chop faster without losing a finger. In high-performance computing, where every millisecond counts, these tools are nothing short of revolutionary.

3. **Streamlined Web Development**: Developers are tired of the kitchen-sink frameworks that feel like driving a tank to the grocery store. Enter [Mizu.js](https://news.ycombinator.com/item?id=42464310), a lightweight templating solution that’s like carrying a Swiss Army knife: simple but surprisingly versatile.
3. **Decentralization and Privacy:**
Privacy is the new frontier, and decentralized systems are the pioneers staking their claim. Projects such as [TideCloak](https://news.ycombinator.com/item?id=42460131) are building the infrastructure for a world where control over personal data is not just a pipe dream. As our lives move increasingly online, the demand for privacy and user sovereignty is growing louder.

## Themes with a Raised Eyebrow
### Storm Clouds on the Horizon

1. **AI: All Hype and No Bite?**: AI is the rock star of the tech world, but like many rock stars, it’s got its skeptics. The discussions around [agentic LLM systems](https://news.ycombinator.com/item?id=42431361) are a reality check. People wonder if these systems are as autonomous as they claim, or if they’re more like a teenager with a learner’s permit.
1. **Tech Monopolies and Privacy Concerns:**
The tech giants are feeling more and more like Big Brother to the Hacker News crowd. Consider the uproar over [uBlock in Chrome](https://news.ycombinator.com/item?id=42506506). Users are frustrated by changes that seem to prioritize profits over privacy, making them feel like pawns rather than participants.

2. **Privacy and Security in the Spotlight**: New tools like [SignWith](https://news.ycombinator.com/item?id=42470254) are under scrutiny for how they handle sensitive data. It’s like inviting a new roommate and not knowing if they’re going to respect your privacy. The community demands transparency and reliability, especially when legal compliance is at stake.
2. **AI-Induced Job Anxiety:**
The specter of AI-induced job loss is haunting the discussions, especially concerning the [future of programming jobs](https://news.ycombinator.com/item?id=42500926). There's a palpable tension between the promise of AI augmenting human work and the fear of it replacing entry-level positions. Yet, the optimists argue that AI will create more jobs than it destroys, akin to how ATMs didn't eliminate bank tellers.

3. **Kubernetes and the Illusion of Simplicity**: Tools like [K8s Cleaner](https://news.ycombinator.com/item?id=42454723) face pushback for potentially glossing over deeper issues in Kubernetes resource management. It’s akin to putting a fresh coat of paint on a building with structural problems. The call is for fixes that address the root, not just the surface.
3. **Cloud Dependency Issues:**
The reliance on cloud services is a double-edged sword. While they offer convenience, they also introduce risks, as seen with issues like those surrounding [Google Authenticator](https://news.ycombinator.com/item?id=42510300). The fragility of these systems can be unnerving, especially when they hold the keys to your digital kingdom.

## The Unexpected
### Surprising Currents

1. **A Love Affair with Software History**: Who knew geeks had such a soft spot for history? The [OS/2 Warp localization project](https://news.ycombinator.com/item?id=42423742) is a testament to the community’s passion for preserving the digital past, akin to restoring an old car to its former glory.
1. **AI's Cross-Disciplinary Ventures:**
AI is proving to be a versatile tool, popping up in unexpected places like [crossword generation](https://news.ycombinator.com/item?id=42496953). It's like discovering your hammer can also make a decent screwdriver. This cross-pollination of ideas is pushing AI into creative domains, sparking new forms of problem-solving.

2. **Nostalgic Gaming**: Games like [SmartHome](https://news.ycombinator.com/item?id=42424508) are tapping into nostalgia by replicating the frustrations of modern tech. It’s like playing a game that mirrors your daily tech annoyances—a cathartic experience for many.
2. **DIY and Open-Source Renaissance:**
There's a resurgence of interest in DIY and open-source projects, as demonstrated by [Musoq](https://news.ycombinator.com/item?id=42453650). It enables querying across diverse data sources with SQL, empowering developers to break free from the shackles of proprietary software. It's a reminder that innovation often thrives outside corporate walls.

3. **Cross-Pollination of Careers**: Tech isn’t an island. The discussion on [interesting jobs](https://news.ycombinator.com/item?id=42421835) highlights a trend of blending tech with fields like patent law and public service. It’s like a mashup of your favorite songs, offering a richer, more fulfilling career path.
3. **Tech’s Cultural and Environmental Impact:**
Projects like [Movie Iris](https://news.ycombinator.com/item?id=42462348) show a unique blend of art, tech, and environmental consciousness. By using color extraction for film analysis, they encourage us to ponder the deeper implications of our cultural consumption and its environmental footprint.

## The Big Picture
### The Collective Pulse

The vibe in the tech community is one of cautious optimism. There’s excitement about new technologies, but also a wary eye on the practicalities and pitfalls. The discourse is balancing innovation with a critical view of hype, especially in AI and security. This blend of enthusiasm and skepticism is what keeps the industry grounded, ensuring that as we explore new horizons, we do so with an eye on what’s real and reliable.
The atmosphere among the tech-savvy is one of cautious optimism. There's a tangible excitement about the transformative power of technology, tempered by a keen awareness of the ethical and societal challenges it brings. As we forge ahead, the focus remains on balancing innovation with responsibility, ensuring that the future we build is one we can be proud of.
2 changes: 1 addition & 1 deletion hn_analysis_tweet.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AI in your toaster is more exciting than AI in the cloud; it's the real-world leap we didn't see coming. As tech blends with everyday life, the mundane suddenly gets a brain. What happens when your toaster is smarter than your fridge? 🤔 #TechTrends #AI #Innovation
AI is shaking up fields you wouldn't expect, like crossword puzzles—proof that the real magic lies in AI's unexpected versatility, not just its raw power. #AI #Innovation #TechTrends
31 changes: 12 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "gensx",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did the changes in here come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove tsup - more description on that in the PR description but in short I ran into an obtuse error that has several open bug reports. Looking through the repo, it appears to be abandoned.

"version": "0.1.1",
"description": "Make LLMs work good",
"main": "dist/index.cjs",
"module": "lib/index.js",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"author": "",
"license": "MIT",
Expand All @@ -20,19 +20,19 @@
"packageManager": "pnpm@9.14.2",
"type": "module",
"scripts": {
"build:watch": "pnpm build:clean && pnpm generate-dist --watch",
"build:watch": "pnpm build:clean && tsc -p tsconfig.prod.json --watch",
"dev": "nodemon",
"prepublishOnly": "pnpm i && pnpm build",
"build": "pnpm validate-typescript && pnpm build:clean && pnpm generate-dist",
"build": "pnpm validate-typescript && pnpm build:clean && pnpm build:dist",
"test": "rimraf coverage && pnpm test:unit",
"test:watch": "vitest",
"test:unit": "vitest run --coverage",
"lint": "eslint --ignore-path .gitignore . --ext .js,.ts",
"lint:fix": "eslint --ignore-path .gitignore . --ext .js,.ts --fix",
"lint:file": "eslint --ignore-path .gitignore",
"validate-typescript": "tsc -p tsconfig.prod.json --noEmit",
"generate-dist": "tsup src/index.ts --minify --tsconfig tsconfig.prod.json --dts --format cjs,esm --out-dir dist --entry.jsx-runtime=src/jsx-runtime.ts --entry.jsx-dev-runtime=src/jsx-dev-runtime.ts --entry.index=src/index.ts",
"build:clean": "rimraf dist; exit 0",
"build:clean": "rimraf dist",
"build:dist": "tsc -p tsconfig.prod.json --outDir dist --declaration",
"prepare": "[ -f .husky/install.mjs ] && node .husky/install.mjs || true"
},
"devDependencies": {
Expand All @@ -56,7 +56,6 @@
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"tsconfig-paths": "^4.2.0",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"unplugin-swc": "^1.5.1",
Expand All @@ -72,22 +71,16 @@
],
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./jsx-runtime": {
"import": "./dist/jsx-runtime.js",
"require": "./dist/jsx-runtime.cjs"
"types": "./dist/jsx-runtime.d.ts",
"default": "./dist/jsx-runtime.js"
},
"./jsx-dev-runtime": {
"import": "./dist/jsx-dev-runtime.js",
"require": "./dist/jsx-dev-runtime.cjs"
"types": "./dist/jsx-dev-runtime.d.ts",
"default": "./dist/jsx-dev-runtime.js"
}
},
"dependencies": {
Expand Down
23 changes: 23 additions & 0 deletions playground/chatCompletion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { gsx } from "@/index";
import { createLLMService } from "@/llm";

const llm = createLLMService({
model: "gpt-4",
temperature: 0.7,
});

interface ChatCompletionProps {
prompt: string;
}

export const ChatCompletion = gsx.StreamComponent<ChatCompletionProps, string>(
async ({ prompt }) => {
// Use the LLM service's streaming API
const result = await llm.completeStream(prompt);

return {
stream: () => result.stream(),
value: result.value,
};
},
);
97 changes: 85 additions & 12 deletions playground/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,106 @@
import * as gsx from "@/index";
import { BlogWritingWorkflow } from "./blogWriter";
import { gsx } from "@/index";
import {
HNAnalyzerWorkflow,
HNAnalyzerWorkflowOutput,
} from "./hackerNewsAnalyzer";
import * as fs from "fs/promises";

async function main() {
console.log("🚀 Starting blog writing workflow");
import { BlogWritingWorkflow } from "./blogWriter";
import { ChatCompletion } from "./chatCompletion";
import fs from "fs/promises";
import type { Streamable } from "@/types";

// Use the gensx function to execute the workflow and annotate with the output type.
// Example 1: Simple blog writing workflow
async function runBlogWritingExample() {
console.log("\n🚀 Starting blog writing workflow");
const result = await gsx.execute<string>(
<BlogWritingWorkflow prompt="Write a blog post about the future of AI" />,
);
console.log("✅ Final result:", { result });
console.log("🚀 Starting HN analysis workflow...");
console.log("✅ Blog writing complete:", { result });
}

// Request all 500 stories since we're filtering to text-only posts
// Example 2: HN analysis workflow with parallel execution
async function runHNAnalysisExample() {
console.log("\n🚀 Starting HN analysis workflow...");
const { report, tweet } = await gsx.execute<HNAnalyzerWorkflowOutput>(
<HNAnalyzerWorkflow postCount={500} />,
);

// Write outputs to files
await fs.writeFile("hn_analysis_report.md", report);
await fs.writeFile("hn_analysis_tweet.txt", tweet);

console.log(
"✅ Analysis complete! Check hn_analysis_report.md and hn_analysis_tweet.txt",
);
}

await main();
// Example 3: Streaming vs non-streaming chat completion
async function runStreamingWithChildrenExample() {
const prompt =
"Write a 250 word story about an AI that discovers the meaning of friendship through a series of small interactions with humans. Be concise but meaningful.";

console.log("\n🚀 Starting streaming example with prompt:", prompt);

console.log("\n📝 Non-streaming version (waiting for full response):");
await gsx.execute<string>(
<ChatCompletion prompt={prompt}>
{async (response: string) => {
console.log(response);
}}
</ChatCompletion>,
);

console.log("\n📝 Streaming version (processing tokens as they arrive):");
await gsx.execute(
<gsx.Stream>
<ChatCompletion prompt={prompt}>
{async (response: Streamable<string>) => {
// Print tokens as they arrive
for await (const token of {
[Symbol.asyncIterator]: () => response.stream(),
}) {
process.stdout.write(token);
}
process.stdout.write("\n");
console.log("✅ Streaming complete");
}}
</ChatCompletion>
</gsx.Stream>,
);
}

async function runStreamingExample() {
const prompt =
"Write a 250 word story about an AI that discovers the meaning of friendship through a series of small interactions with humans. Be concise but meaningful.";

console.log("\n🚀 Starting streaming example with prompt:", prompt);

console.log("\n📝 Non-streaming version (waiting for full response):");
const finalResult = await gsx.execute<Streamable<string>>(
<ChatCompletion prompt={prompt} />,
);
console.log("✅ Complete response:", await finalResult.value);

console.log("\n📝 Streaming version (processing tokens as they arrive):");
const response: Streamable<string> = await gsx.execute(
<gsx.Stream>
<ChatCompletion prompt={prompt} />
</gsx.Stream>,
);

for await (const token of {
[Symbol.asyncIterator]: () => response.stream(),
}) {
process.stdout.write(token);
}
process.stdout.write("\n");
console.log("✅ Streaming complete");
}

// Main function to run examples
async function main() {
await runBlogWritingExample();
await runHNAnalysisExample();
await runStreamingWithChildrenExample();
await runStreamingExample();
}

main().catch(console.error);
Loading
Loading