mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-02 00:30:32 +00:00
Merge pull request #6281 from wuji-labs/feat/http2-long-stream-keepalive
feat(upstream): add HTTP/2 PING keepalive for long LLM generation streams
This commit is contained in:
@@ -7,9 +7,10 @@ import "context"
|
||||
type HTTPUpstreamProfile string
|
||||
|
||||
const (
|
||||
HTTPUpstreamProfileDefault HTTPUpstreamProfile = ""
|
||||
HTTPUpstreamProfileOpenAI HTTPUpstreamProfile = "openai"
|
||||
HTTPUpstreamProfileGrok HTTPUpstreamProfile = "grok"
|
||||
HTTPUpstreamProfileDefault HTTPUpstreamProfile = ""
|
||||
HTTPUpstreamProfileOpenAI HTTPUpstreamProfile = "openai"
|
||||
HTTPUpstreamProfileGrok HTTPUpstreamProfile = "grok"
|
||||
HTTPUpstreamProfileLongStream HTTPUpstreamProfile = "long_stream"
|
||||
)
|
||||
|
||||
type httpUpstreamProfileContextKey struct{}
|
||||
@@ -37,7 +38,7 @@ func HTTPUpstreamProfileFromContext(ctx context.Context) HTTPUpstreamProfile {
|
||||
return HTTPUpstreamProfileDefault
|
||||
}
|
||||
switch profile {
|
||||
case HTTPUpstreamProfileOpenAI, HTTPUpstreamProfileGrok:
|
||||
case HTTPUpstreamProfileOpenAI, HTTPUpstreamProfileGrok, HTTPUpstreamProfileLongStream:
|
||||
return profile
|
||||
default:
|
||||
return HTTPUpstreamProfileDefault
|
||||
|
||||
@@ -20,6 +20,13 @@ func TestWithHTTPUpstreamProfile_OpenAI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithHTTPUpstreamProfile_LongStream(t *testing.T) {
|
||||
ctx := WithHTTPUpstreamProfile(context.TODO(), HTTPUpstreamProfileLongStream)
|
||||
if profile := HTTPUpstreamProfileFromContext(ctx); profile != HTTPUpstreamProfileLongStream {
|
||||
t.Fatalf("expected profile %q, got %q", HTTPUpstreamProfileLongStream, profile)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithHTTPUpstreamRedirectsDisabled(t *testing.T) {
|
||||
//nolint:staticcheck // Exercises the defensive nil-context fallback.
|
||||
ctx := WithHTTPUpstreamRedirectsDisabled(nil)
|
||||
|
||||
Reference in New Issue
Block a user