54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
//go:build ignore
|
|
|
|
// connectivity check for the real LLM endpoint. Run with:
|
|
// go run -tags=ignored scripts/llm_check.go
|
|
// (build tag ignored keeps it out of normal builds; we run it directly.)
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
body := strings.NewReader(`{
|
|
"model": "qwen3.7-plus",
|
|
"messages": [{"role":"user","content":"用一句话介绍你自己"}],
|
|
"stream": false
|
|
}`)
|
|
req, _ := http.NewRequestWithContext(context.Background(), "POST",
|
|
"https://api.littlelan.cn/v1/chat/completions", body)
|
|
req.Header.Set("Authorization", "Bearer sk-YOUR-API-KEY")
|
|
req.Header.Set("Content-Type", "application/json")
|
|
client := &http.Client{Timeout: 30 * time.Second}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
fmt.Println("ERR:", err)
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
rb, _ := io.ReadAll(resp.Body)
|
|
fmt.Println("status:", resp.StatusCode)
|
|
// pretty print a bit
|
|
var parsed map[string]any
|
|
if json.Unmarshal(rb, &parsed) == nil {
|
|
if choices, ok := parsed["choices"].([]any); ok && len(choices) > 0 {
|
|
if c0, ok := choices[0].(map[string]any); ok {
|
|
if msg, ok := c0["message"].(map[string]any); ok {
|
|
fmt.Println("content:", msg["content"])
|
|
}
|
|
}
|
|
}
|
|
if e, ok := parsed["error"]; ok {
|
|
fmt.Println("error obj:", e)
|
|
}
|
|
} else {
|
|
fmt.Println("raw:", string(rb))
|
|
}
|
|
}
|