### SwiftUI Usage of LLMStreamView Source: https://github.com/synth-inc/llmstream/blob/main/README.md Demonstrates how to integrate the LLMStreamView into a SwiftUI view. This example shows initializing the view with sample Markdown and LaTeX content. ```swift import LLMStream struct ContentView: View { @State var height: CGFloat = 0 var body: some View { LLMStreamView( text: "# Hello **Markdown** & $\\LaTeX$" ) } } ``` -------------------------------- ### Markdown: Inline and Display Math with LaTeX Source: https://github.com/synth-inc/llmstream/blob/main/README.md This Markdown example shows how to integrate LaTeX for mathematical expressions. It includes an inline equation using '$' delimiters and a display math equation using '\[\]' delimiters, demonstrating rendering capabilities for scientific content. ```markdown # Integration Example This is a **bold** text with an inline equation: $E = mc^2$ ## Display Math \[ \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} \] ``` -------------------------------- ### Swift Package Manager Installation for LLMStream Source: https://github.com/synth-inc/llmstream/blob/main/README.md Instructions for adding the LLMStream Swift package to your project using Swift Package Manager. This includes updating your Package.swift file and adding necessary security entitlements. ```swift dependencies: [ .package(url: "https://github.com/synth-inc/LLMStream", branch: "main") ] ``` ```xml com.apple.security.network.client com.apple.security.web ``` -------------------------------- ### Install LLMStream using Swift Package Manager in Swift Source: https://context7.com/synth-inc/llmstream/llms.txt Instructions for adding the LLMStream library to a Swift project using Swift Package Manager. This involves specifying the repository URL and branch in the Package.swift file. ```swift // Package.swift // swift-tools-version: 5.7 import PackageDescription let package = Package( name: "MyApp", platforms: [ .macOS(.v13), .iOS(.v16) ], dependencies: [ .package(url: "https://github.com/synth-inc/LLMStream", branch: "main") ], targets: [ .target( name: "MyApp", dependencies: ["LLMStream"]) ] ) ``` -------------------------------- ### Swift: Apply Custom Configurations to LLMStreamView Source: https://github.com/synth-inc/llmstream/blob/main/README.md This Swift code demonstrates how to create a comprehensive `LLMStreamConfiguration` by combining various sub-configurations (font, colors, layout, thought, animation, code block, table) and applying it to an LLMStreamView. This allows for a highly customized user experience. ```swift let config = LLMStreamConfiguration( font: fontConfig, colors: colorConfig, layout: layoutConfig, thought: thoughtConfig, animation: animationConfig, codeBlock: codeConfig, table: tableConfig ) LLMStreamView( text: "Your content here", configuration: config ) ``` -------------------------------- ### Display Streamed LLM Responses with LLMStreamView (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt The main SwiftUI view component for rendering streamed LLM responses. It supports Markdown, LaTeX, and code highlighting. It takes the streamed text, a configuration object, and callbacks for URL clicks and code actions as input. ```swift import SwiftUI import LLMStream struct ContentView: View { @State private var streamedText = """\n # Mathematical Formula\n The quadratic formula is: $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$\n ## Code Example\n ```swift func fibonacci(_ n: Int) -> Int { guard n > 1 else { return n } return fibonacci(n-1) + fibonacci(n-2) } ``` Let me analyze this problem step by step... The solution involves **recursive** calls with `O(2^n)` complexity. """ var body: some View { ScrollView { LLMStreamView( text: streamedText, configuration: .default, onUrlClicked: { url in print("URL clicked: \(url)") }, onCodeAction: { code in print("Execute code: \(code)") } ) .padding() } } } ``` -------------------------------- ### Configure Table Rendering with TableConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Configures how tables are rendered in LLMStream, including options for showing captions, styling headers, enabling hover effects, and zebra striping. It allows for custom caption styles and header styles. This configuration is passed to LLMStreamConfiguration. ```swift import SwiftUI import LLMStream let tableConfig = TableConfiguration( showCaption: true, captionStyle: TableConfiguration.CaptionStyle( fontSize: 0.9, textColor: Color(white: 0.8) ), headerStyle: TableConfiguration.HeaderStyle( fontWeight: .bold, textAlignment: .center, borderWidth: 2.0 ), enableHover: true, enableZebraStripes: true ) let config = LLMStreamConfiguration(table: tableConfig) let markdownTable = """| Feature | Supported | |---------|-----------| | Markdown | ✓ | | LaTeX | ✓ | | Code Highlighting | ✓ | """ LLMStreamView(text: markdownTable, configuration: config, onUrlClicked: { _ in }) ``` -------------------------------- ### Customize Code Blocks with CodeBlockConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Customizes the appearance and behavior of code blocks, including options to show language labels, copy buttons, and action buttons for code execution. It also allows customization of text sizes, button sizes, opacity, and icons. This configuration is passed to LLMStreamConfiguration. ```swift import SwiftUI import LLMStream let codeConfig = CodeBlockConfiguration( showLanguage: true, showCopyButton: true, showActionButton: true, languageTextSize: 13.0, copyButtonSize: 16, actionButtonSize: 16, copyButtonOpacity: 0.5, copyButtonHoverOpacity: 1.0, copyButtonIcon: Image(systemName: "doc.on.doc"), actionButtonOpacity: 0.5, actionButtonHoverOpacity: 1.0, actionButtonIcon: Image(systemName: "play.circle"), actionButtonTooltip: "Execute Code" ) LLMStreamView( text: """ ```python def hello(): print("Hello, World!") ``` """, configuration: LLMStreamConfiguration(codeBlock: codeConfig), onUrlClicked: { _ in }, onCodeAction: { code in print("Executing: \(code)") // Add your code execution logic here } ) ``` -------------------------------- ### LLMStream Color Configuration in Swift Source: https://github.com/synth-inc/llmstream/blob/main/README.md Provides a detailed configuration for colors used within LLMStream, covering text, backgrounds, links, and specific elements like code blocks, tables, and thought states. ```swift let colorConfig = ColorConfiguration( textColor: .white, backgroundColor: .clear, codeBackgroundColor: Color(red: 0.15, green: 0.15, blue: 0.15), codeBorderColor: Color(white: 0.24), linkColor: Color(red: 0.29, green: 0.60, blue: 1.0), thoughtBackgroundColor: Color.gray.opacity(0.1), tableHeaderBackgroundColor: Color(white: 0.24), tableBorderColor: Color(white: 0.4), tableRowEvenColor: Color(white: 0.2).opacity(0.2), tableRowHoverColor: Color(white: 0.27).opacity(0.3), theoremBorderColor: Color(red: 0.29, green: 0.60, blue: 1.0), proofBorderColor: Color(white: 0.47) ) ``` -------------------------------- ### SwiftUI LLMStream View with Streaming Response Source: https://context7.com/synth-inc/llmstream/llms.txt This snippet demonstrates how to use the `LLMStreamView` in SwiftUI to display streaming LLM responses. It configures the appearance, handles URL clicks, and executes code actions. The `simulateStreaming` function mimics a real-time response by appending characters over time. ```swift import SwiftUI import LLMStream struct AIAssistantView: View { @State private var streamedResponse = "" @State private var isStreaming = false let configuration = LLMStreamConfiguration( font: FontConfiguration(size: 15.0, lineHeight: 1.5), colors: ColorConfiguration( textColor: .white, backgroundColor: Color(red: 0.1, green: 0.1, blue: 0.12), codeBackgroundColor: Color(red: 0.15, green: 0.15, blue: 0.16) ), thought: ThoughtConfiguration( icon: Image(systemName: "brain"), thinkingTitle: "Analyzing...", thoughtTitle: "Reasoning" ), codeBlock: CodeBlockConfiguration( showActionButton: true, actionButtonTooltip: "Run this code" ) ) var body: some View { VStack(spacing: 0) { ScrollView { LLMStreamView( text: streamedResponse, configuration: configuration, onUrlClicked: { url in if let urlObj = URL(string: url) { NSWorkspace.shared.open(urlObj) } }, onCodeAction: { code in executeCode(code) } ) .padding() } HStack { Button("Stream Response") { simulateStreaming() } .disabled(isStreaming) } .padding() } } func simulateStreaming() { isStreaming = true streamedResponse = "" let fullResponse = """\ # Algorithm Analysis Need to evaluate time complexity... Considering space-time tradeoffs... The optimal approach uses **dynamic programming**: ```python def solve(n, memo={}): if n in memo: return memo[n] if n <= 1: return n memo[n] = solve(n-1) + solve(n-2) return memo[n] ``` Time complexity: $O(n)$ Space complexity: $O(n)$ """ var index = 0 Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { timer in if index < fullResponse.count { let currentIndex = fullResponse.index(fullResponse.startIndex, offsetBy: index) streamedResponse.append(fullResponse[currentIndex]) index += 1 } else { timer.invalidate() isStreaming = false } } } func executeCode(_ code: String) { print("Executing code:") print(code) // Implement your code execution logic } } ``` -------------------------------- ### Customize Thought Bubbles with ThoughtConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Customizes the appearance and behavior of LLM thinking states, typically used with `` tags. It allows setting icons, titles, and controls for expanding content. This configuration is passed to LLMStreamConfiguration. ```swift import SwiftUI import LLMStream let thoughtConfig = ThoughtConfiguration( icon: Image(systemName: "brain"), iconSize: 16, thinkingTitle: "Thinking...", thoughtTitle: "Thought-process", showExpandButton: true ) let config = LLMStreamConfiguration(thought: thoughtConfig) let textWithThinking = """# Problem Analysis First, I need to understand the problem constraints... Then calculate the time complexity... Finally, optimize the algorithm... The optimal solution uses dynamic programming with O(n) complexity. """ LLMStreamView(text: textWithThinking, configuration: config, onUrlClicked: { _ in }) ``` -------------------------------- ### Configure UI Layout with LayoutConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Controls spacing, padding, and corner radius for content areas, code blocks, tables, and thought bubbles in LLMStream. It accepts EdgeInsets for padding and CGFloat for spacing and corner radii. This configuration is passed to LLMStreamConfiguration. ```swift import SwiftUI import LLMStream let layoutConfig = LayoutConfiguration( contentPadding: EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0), codePadding: EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16), thoughtPadding: EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8), tablePadding: EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8), citationMargin: EdgeInsets(top: 0, leading: 4, bottom: 0, trailing: 4), citationPadding: EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4), spacing: 8, cornerRadius: 8, tableCornerRadius: 5, theoremCornerRadius: 4, citationBorderRadius: 6 ) let config = LLMStreamConfiguration(layout: layoutConfig) ``` -------------------------------- ### Configure UI Colors with ColorConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Defines the color scheme for all UI elements within LLMStream, including text, backgrounds, code blocks, tables, and interactive elements. It takes various Color objects as parameters to customize different UI parts. This configuration is passed to LLMStreamConfiguration. ```swift import SwiftUI import LLMStream let colorConfig = ColorConfiguration( textColor: Color.white, backgroundColor: Color.clear, codeBackgroundColor: Color(red: 0.15, green: 0.15, blue: 0.15), codeBorderColor: Color(white: 0.24), linkColor: Color(red: 0.29, green: 0.60, blue: 1.0), thoughtBackgroundColor: Color.gray.opacity(0.1), tableHeaderBackgroundColor: Color(white: 0.24), tableBorderColor: Color(white: 0.4), tableRowEvenColor: Color(white: 0.2).opacity(0.2), tableRowHoverColor: Color(white: 0.27).opacity(0.3), theoremBorderColor: Color(red: 0.29, green: 0.60, blue: 1.0), proofBorderColor: Color(white: 0.47), citationBackgroundColor: Color(red: 0.15, green: 0.15, blue: 0.15), citationHoverBackgroundColor: Color(red: 0.2, green: 0.2, blue: 0.2), citationTextColor: Color.white, citationHoverTextColor: Color.white, citationFontSizeRatio: 0.8 ) let config = LLMStreamConfiguration(colors: colorConfig) ``` -------------------------------- ### LLMStream Layout Configuration in Swift Source: https://github.com/synth-inc/llmstream/blob/main/README.md Configures the layout parameters for LLMStream, including padding for content, code blocks, thoughts, and tables, as well as spacing and corner radius values for various UI elements. ```swift let layoutConfig = LayoutConfiguration( contentPadding: EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0), codePadding: EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16), thoughtPadding: EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8), tablePadding: EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8), spacing: 8, cornerRadius: 8, tableCornerRadius: 5, theoremCornerRadius: 4 ) ``` -------------------------------- ### Configure LLMStream Animations in Swift Source: https://context7.com/synth-inc/llmstream/llms.txt Defines animation configurations for thought expansion and shimmer effects used in LLMStream. It specifies animation types, durations, and gradient colors for visual feedback during streaming. ```swift import SwiftUI import LLMStream let animationConfig = AnimationConfiguration( thoughtExpandAnimation: .spring(response: 0.35, dampingFraction: 0.85), shimmerAnimation: .linear(duration: 1.5) .delay(0.25) .repeatForever(autoreverses: false), shimmerGradient: Gradient(colors: [ .black.opacity(0.3), .black, .black.opacity(0.3) ]) ) let config = LLMStreamConfiguration(animation: animationConfig) ``` -------------------------------- ### Customize LLMStreamView Appearance with LLMStreamConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Configuration object for customizing the appearance and behavior of LLMStreamView. It includes preset themes (dark, light) and allows for detailed custom options for fonts, colors, layout, thought display, and code blocks. ```swift import SwiftUI import LLMStream // Using preset dark theme let darkConfig = LLMStreamConfiguration.dark // Using preset light theme let lightConfig = LLMStreamConfiguration.light // Custom configuration let customConfig = LLMStreamConfiguration( font: FontConfiguration( size: 16.0, lineHeight: 1.6, family: "SF Pro, sans-serif", codeFontFamily: "SF Mono, monospace" ), colors: ColorConfiguration( textColor: .white, backgroundColor: Color(red: 0.1, green: 0.1, blue: 0.12), codeBackgroundColor: Color(red: 0.15, green: 0.15, blue: 0.16), linkColor: Color(red: 0.4, green: 0.65, blue: 1.0) ), layout: LayoutConfiguration( contentPadding: EdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16), cornerRadius: 12, spacing: 12 ), thought: ThoughtConfiguration( icon: Image(systemName: "brain"), thinkingTitle: "Processing...", thoughtTitle: "Analysis" ), codeBlock: CodeBlockConfiguration( showLanguage: true, showCopyButton: true, showActionButton: true, actionButtonTooltip: "Run Code" ) ) LLMStreamView( text: "Your content here", configuration: customConfig, onUrlClicked: { _ in }, onCodeAction: { code in // Handle code execution } ) ``` -------------------------------- ### Required Entitlements for LLMStream Network Access Source: https://context7.com/synth-inc/llmstream/llms.txt Specifies the necessary entitlements required in an Xcode project's .entitlements file for LLMStream to access network resources. These include network client and web permissions. ```xml com.apple.security.network.client com.apple.security.web ``` -------------------------------- ### Process Markdown LaTeX Documents in Swift Source: https://context7.com/synth-inc/llmstream/llms.txt An internal Swift processor designed to clean and prepare LaTeX documents embedded within Markdown for rendering. It extracts content between \begin{document} and \end{document} and removes unnecessary LaTeX commands. ```swift // Internal usage - automatically handles LaTeX document extraction // Example input text with LaTeX document: let inputText = """ \documentclass{article} \usepackage{amsmath} \begin{document} \section{Introduction} This is a theorem. \end{document} """ // The processor extracts content between \begin{document} and \end{document} // and removes unnecessary LaTeX commands let processed = MarkdownLatexTextProcessor.cleanLatexDocuments(in: inputText) // Result: "# Introduction\nThis is a theorem." ``` -------------------------------- ### Swift: Configure Table Appearance and Behavior Source: https://github.com/synth-inc/llmstream/blob/main/README.md This Swift code snippet shows how to configure the appearance and behavior of tables within LLMStream. Options include enabling/disabling captions, styling captions and headers, and enabling hover effects and zebra striping for improved readability. ```swift let tableConfig = TableConfiguration( showCaption: true, captionStyle: TableConfiguration.CaptionStyle( fontSize: 0.9, textColor: Color(white: 0.8) ), headerStyle: TableConfiguration.HeaderStyle( fontWeight: .bold, textAlignment: .center, borderWidth: 2.0 ), enableHover: true, enableZebraStripes: true ) ``` -------------------------------- ### LLMStream Code Block Configuration in Swift Source: https://github.com/synth-inc/llmstream/blob/main/README.md Customizes the appearance and behavior of code blocks within LLMStream. Options include showing language labels, copy buttons, action buttons, and adjusting their sizes and opacities. ```swift let codeConfig = CodeBlockConfiguration( showLanguage: true, // Show language label showCopyButton: true, // Show copy button showActionButton: true, // Show action button languageTextSize: 13.0, // Language label size copyButtonSize: 16, // Copy button size actionButtonSize: 16, // Action button size copyButtonOpacity: 0.5, // Copy button normal opacity copyButtonHoverOpacity: 1.0, // Copy button hover opacity actionButtonOpacity: 0.5, // Action button normal opacity actionButtonHoverOpacity: 1.0,// Action button hover opacity actionButtonIcon: "play.circle", // SF Symbol name for action button actionButtonTooltip: "Execute" // Action button tooltip ) ``` -------------------------------- ### Configure Typography Settings with FontConfiguration (Swift) Source: https://context7.com/synth-inc/llmstream/llms.txt Configures typography settings for text, code, tables, and mathematical expressions within the LLMStreamView. Allows customization of font size, line height, and specific font families for different content types. ```swift import LLMStream let fontConfig = FontConfiguration( size: 15.0, lineHeight: 1.5, family: "-apple-system, BlinkMacSystemFont, sans-serif", codeFontFamily: "SF Mono, Monaco, Menlo, monospace", tableFontFamily: "system-ui, serif", mathFontFamily: "STIX Two Math, Latin Modern Math, serif" ) let config = LLMStreamConfiguration(font: fontConfig) ``` -------------------------------- ### Swift: Customize Thought Process Display Source: https://github.com/synth-inc/llmstream/blob/main/README.md This Swift code defines a `ThoughtConfiguration` for customizing the display of thought processes in LLMStream. It allows setting an optional icon, icon size, loading state title, normal state title, and whether to show an expand button. ```swift let thoughtConfig = ThoughtConfiguration( icon: Image(systemName: "brain"), // Optional icon iconSize: 16, thinkingTitle: "Thinking…", // Loading state title thoughtTitle: "Thought-process", // Normal state title showExpandButton: true ) ``` -------------------------------- ### Swift: Add Custom Action Button to Code Blocks Source: https://github.com/synth-inc/llmstream/blob/main/README.md This Swift code demonstrates how to add a custom action button to code blocks within an LLMStreamView. It allows triggering a callback function when the button is pressed, passing the code content to the handler. Configuration options include the button's icon and tooltip. ```swift LLMStreamView( text: "Your content here", configuration: LLMStreamConfiguration( codeBlock: CodeBlockConfiguration( showActionButton: true, actionButtonIcon: "play.circle", actionButtonTooltip: "Run this code" ) ), onCodeAction: { code in // Handle the code execution here print("Code to execute:", code) } ) ``` -------------------------------- ### Swift: Configure Animations for LLMStream Source: https://github.com/synth-inc/llmstream/blob/main/README.md This Swift code snippet illustrates how to configure animations within LLMStream, including animations for expanding thoughts and shimmering effects. It allows specifying animation types, durations, delays, and gradients for visual feedback. ```swift let animationConfig = AnimationConfiguration( thoughtExpandAnimation: .spring(response: 0.35, dampingFraction: 0.85), shimmerAnimation: .linear(duration: 1.5).delay(0.25).repeatForever(autoreverses: false), shimmerGradient: Gradient(colors: [ .black.opacity(0.3), .black, .black.opacity(0.3) ]) ) ``` -------------------------------- ### LLMStream Font Configuration in Swift Source: https://github.com/synth-inc/llmstream/blob/main/README.md Defines custom font settings for LLMStream, allowing adjustments to base font size, line height, and specific font families for regular text, code blocks, tables, and mathematical expressions. ```swift let fontConfig = FontConfiguration( size: 14.0, // Base font size lineHeight: 1.4, // Line height multiplier family: "-apple-system...", // Main font family codeFontFamily: "SF Mono...", // Code blocks font tableFontFamily: "system-ui...",// Table font mathFontFamily: "STIX Two Math..." // Math expressions font ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.