cogentcore / core

A free and open source framework for building powerful, fast, elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the web with a single Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.71k stars 80 forks source link

markdown sync #929

Closed ddkwork closed 6 months ago

ddkwork commented 7 months ago

Describe the feature

After some testing, Label doesn't seem to be suitable for AI chat scenarios, while Markdown does, almost all AI models return MD format, CoreDOM doesn't seem to have a way to insert text in threads, can you add this feature?

Relevant code

package main

import (
    "cogentcore.org/core/gi"
    "fmt"
    "math/rand"
    "time"
    "unsafe"
)

func main() {
    b := gi.NewBody("ollama gui")
    label := gi.NewLabel(b)
    go func() {
        orig := "orig "
        for i := 0; i < 30000; i++ {
            start := label.UpdateStart()
            s := orig + randStr(i) + fmt.Sprint(i)
            if len(s)%10 == 0 {
                s += "\n"
            }
            label.SetTextUpdate(s)
            label.UpdateEndLayout(start)
            time.Sleep(200 * time.Millisecond)
        }
    }()
    b.RunMainWindow()
}

// ////////
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

var src = rand.NewSource(time.Now().UnixNano())

const (
    // 6 bits to represent a letter index
    letterIdBits = 6
    // All 1-bits as many as letterIdBits
    letterIdMask = 1<<letterIdBits - 1
    letterIdMax  = 63 / letterIdBits
)

func randStr(n int) string {
    b := make([]byte, n)
    // A rand.Int63() generates 63 random bits, enough for letterIdMax letters!
    for i, cache, remain := n-1, src.Int63(), letterIdMax; i >= 0; {
        if remain == 0 {
            cache, remain = src.Int63(), letterIdMax
        }
        if idx := int(cache & letterIdMask); idx < len(letters) {
            b[i] = letters[idx]
            i--
        }
        cache >>= letterIdBits
        remain--
    }
    return *(*string)(unsafe.Pointer(&b))
}
kkoreilly commented 6 months ago

I do not have time to implement the tree table widget now, but I will soon. Also, I do not really think that a tree table is the best widget for model selection; rather, two slice views, one with the model and one with the versions of the model, may be easier for users to interact with.

kkoreilly commented 6 months ago

I am not opposed to using a tree table, and I am perfectly happy with us using it once I implement it. Again, I will implement it as soon as I have the time, which should not be in too long.

kkoreilly commented 6 months ago

Regarding the error handling, this is the standard Go error handling paradigm that everyone follows, so we do not have much choice but to follow it. Furthermore, returning the errors allows us to display them to the user appropriately, which is important for GUI apps. I am open to suggestions on how to improve the error handling, and I would like for it to be as concise as possible, but we do need to be somewhat consistent with the standard Go paradigm.

kkoreilly commented 6 months ago

I still disagree with you, but I am fine with you just logging the errors and not returning them, as long as you use grr.Log instead of mylog.Error.

kkoreilly commented 6 months ago

Again, I still disagree with you, as I prefer to follow the standard conventions that everyone in the Go ecosystem follows, but if you insist, you are free to handle the errors as you choose. If you are going to log the errors, I would prefer that you use grr.Log instead of mylog.Error if possible.

kkoreilly commented 6 months ago

Again, we clearly disagree on this issue, and it is pointless to continue debating it. You can follow the error handling paradigm you want for Cogent AI.

kkoreilly commented 6 months ago

Again, we have much better things to do with our time than to keep debating this. Let's focus on making Cogent AI and Cogent Core better.

kkoreilly commented 6 months ago

Again, you are free to work on Cogent AI using your preferred method of error handling. Regardless, this specific issue of markdown syncing is completed, so I will close this issue as such.