Skip to content

Initial version of "export as markdown" functionality #130

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pd95
Copy link
Contributor

@pd95 pd95 commented Feb 6, 2025

This is a preview of a possible "export" functionality.

  • a "share button" in the chat's toolbar triggers the save dialog (using fileExporter)
  • the chat with its messages and some statistics is "rendered manually" into a markdown string
  • the string is saved using the Transferable protocol

Happy to receive feedback...

For each message:

  • the prompt is rendered into a markdown "quote block", so indenting the users input.
  • the response is checked for a <think> block. If found, this part is put into a quote block as the users input.
  • the rest of the response is added "as is" (as we expect it to be proper markdown)

There are known issues:

  • if the prompt contains markdown formatting, this might look ugly/break
  • HTML entities are only escaped in the <think> block. But if the < & or > are already escaped in markdown (using backticks ` or ```) this is incorrect.

@pd95
Copy link
Contributor Author

pd95 commented Feb 8, 2025

Attached here is a sample export done using this code.

Below you see how Github is rendering it.

============================

Swift Function to Check Prime Numbers in Swift Code

Conversation

User

What is a prime number? Give me a Swift function implementing "isPrime".

AI

What is a Prime Number?

A prime number is a positive integer that is divisible only by itself and 1. In other words, it has exactly two distinct factors: 1 and the number itself.

For example, the first few prime numbers are:

2, 3, 5, 7, 11, 13, ...

Swift Function Implementing "isPrime"

Here's a simple Swift function that checks whether a given integer is a prime number or not:

/// Checks if a given integer is a prime number.
///
/// - Parameter n: The number to check for primality.
/// - Returns: `true` if the number is prime, `false` otherwise.
func isPrime(_ n: Int) -> Bool {
    guard n > 1 else { return false }
    
    for i in 2...Int(sqrt(Double(n))) {
        if n % i == 0 {
            return false
        }
    }
    return true
}

Explanation

This function works by checking divisibility of the input number n from 2 up to its square root. If n is divisible by any of these numbers, it's not prime.

Here's a step-by-step breakdown:

  1. We first check if n is less than or equal to 1, in which case it's not prime.
  2. We then iterate from 2 up to the square root of n. For each iteration, we check if n is divisible by the current number i.
  3. If n is divisible by i, we immediately return false, indicating that n is not prime.
  4. If we reach the end of the loop without finding a divisor, we return true, indicating that n is prime.

Example Use Cases

You can use this function to check whether a given integer is prime:

print(isPrime(25)) // prints: false
print(isPrime(23)) // prints: true

Note that this implementation has a time complexity of O(√n), making it relatively efficient for large inputs. However, for extremely large numbers, you may need to use more advanced primality tests or libraries.


Stats

Property Value
Model llama3.2:latest
Created at 8.2.2025, 13:27:01 CET
Modified at 8.2.2025, 13:28:02 CET
Messages 1
Host http://localhost:11434
System Prompt You're a helpful assistant.
Temperature 0.7
Top P 0.9
Top K 40

- a "share button" in toolbar of the chat view triggers the save dialog (`fileExporter`)
- the chat with its messages is "manually" rendered into a markdown string
- the string  is saved using the `Transferable` protocol
@pd95 pd95 force-pushed the feature/export-chat-as-markdown branch from 44912ec to 645466c Compare March 5, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant