cogentcore / cogent

A powerful, fast, elegant software ecosystem of apps for all platforms.
https://cogentcore.org/cogent
BSD 3-Clause "New" or "Revised" License
192 stars 10 forks source link

sever err: Client.Timeout #320

Closed ddkwork closed 8 months ago

ddkwork commented 8 months ago

Describe the bug

This is a problem that has been bothering me for a long time, and I can't reproduce it every time, judging by the scan result of the body, the model closes the connection before it has returned the entire content

How to reproduce

GOROOT=C:\Program Files\Go #gosetup
GOPATH=C:\Users\Admin\go #gosetup
"C:\Program Files\Go\bin\go.exe" build -o C:\Users\Admin\AppData\Local\JetBrains\GoLand2023.3\tmp\GoLand\___2go_build_cogentcore_org_cogent_ai.exe cogentcore.org/cogent/ai #gosetup
[2024-03-12 16:46:46]   Trace ->  --------- title --------- | ------------------ info ------------------ //runtime.doInit1+0xec C:/Program Files/Go/src/runtime/proc.go:7176
[2024-03-12 16:46:49]   Error ->                            | textField.Text() == "" //main.main.func11+0x94 C:/Users/Admin/Desktop/cogent/ai/ai.go:90
[2024-03-12 16:51:36] Warning ->              connect serve | Send "how to use goquery get \"instruct\"\r\n\r\n              <div class=\"flex px-4 py-3\">\r\n                <div class=\"flex-1\">\r\n                  <a class=\"group\" href=\"/library/gemma:instruct\">\r\n                    <div class=\"break-all font-medium text-gray-900 group-hover:underline\">instruct</div>\r\n                    <div class=\"flex items-baseline space-x-1 text-[13px] text-neutral-500\">\r\n                      <span>\r\n                        430ed3535049 • 5.2GB • \r\n                        Updated 2 weeks ago\r\n                      </span>\r\n                    </div>\r\n                  </a>\r\n                </div>\r\n                \r\n              </div> " to the serve,please wait a while //main.main.func11.1+0xc9 C:/Users/Admin/Desktop/cogent/ai/ai.go:94
Sure, here's how you can use `goquery` to get the text "instruct":

```go
import (
  "github.com/goquery/goquery"
)

// Get the HTML content from the URL
data, err := goquery.New("your_url").HTML()

// If there's an error, handle it
if err != nil {
  panic(err)
}

// Parse the HTML content
results, err := goquery.Parse(data)

// If there's an error, handle it
if err != nil {
  panic(err)
}

// Get the first match of the element with the class "instruct"
result := results.Find("a.group[href='/library/gemma:instruct']")

// If we found the element, extract the text
if result != nil {
  text := result.Text()
  fmt.Println(text) // Output: instruct
} else {
  // If we didn't find the element, handle it
  fmt[2024-03-12 16:53:36]   Error ->                            | read tcp 127.0.0.1:64342->127.0.0.1:11434: use of closed network connection (Client.Timeout or context cancellation while reading body) //main.main.func11.1+0x4b3 C:/Users/Admin/Desktop/cogent/ai/ai.go:131

Example code

No response

Relevant output

No response

Platform

Windows

ddkwork commented 8 months ago

One guess as to a possible solution is to set a timeout on the client, but I haven't found where to set it there yet