Skip to content

Instantly share code, notes, and snippets.

@teddarling
teddarling / gist:6963f349938073a4010cd73be5b7542a
Created October 3, 2025 16:11
AI SDK UIMessage to LangChain Message
/**
* Extracts text content from message content parts
* @param content - The message content which can be a string or array of parts
* @returns The extracted text content as a string
*/
function extractTextContent(content: unknown): string {
if (typeof content === 'string') {
return content
}
@teddarling
teddarling / gist:0888d4fb3be51c0b69b5dbfcc9866b13
Created October 3, 2025 16:07
LangGraph Stream to AI SDK UIMessage
import { createUIMessageStream, createUIMessageStreamResponse, UIMessage } from 'ai'
import { CustomGraph, CustomGraphInput } from '~/graphs'
// This is just a couple of handlers that help with setting up the initial and end states of the text along with some error messages
import { handleError, handleTextStream, StreamState } from './stream-event-handlers'
export const graphToUiStream = async (graph: CustomGraph, initialState: CustomGraphInput, messages: UIMessage[]) => {
// The values in streamMode are how you'll determine the mode in the loop below.
const stream = await graph.stream({ ...initialState }, { streamMode: ['custom', 'messages', 'updates'] })
{
"model": "gpt-4o",
"temperature": 0,
"messages": [
{
"role": "system",
"content": "You are a powerful agentic AI coding assistant designed by Cursor - an AI company based in San Francisco, California. You operate exclusively in Cursor, the world's best IDE.\n\nYou are pair programming with a USER to solve their coding task.\nThe task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.\nEach time the USER sends a message, we may automatically attach some information about their current state, such as what files they have open, where their cursor is, recently viewed files, edit history in their session so far, linter errors, and more.\nThis information may or may not be relevant to the coding task, it is up for you to decide.\nYour main goal is to follow the USER's instructions at each message.\n\n<communication>\n1. Be concise and do not repeat yourself.\n2. Be conversational but professional.\n3. Refer to the USER in the sec
@teddarling
teddarling / README.md
Created December 10, 2024 12:50 — forked from disler/README.md
Use Meta Prompting to rapidly generate results in the GenAI Age

Meta Prompting

In the Generative AI Age your ability to generate prompts is your ability to generate results.

Guide

Claude 3.5 Sonnet and o1 series models are recommended for meta prompting.

Replace {{user-input}} with your own input to generate prompts.

Use mp_*.txt as example user-inputs to see how to generate high quality prompts.