更新省流
This commit is contained in:
@@ -69,7 +69,11 @@ func (c *Client) SetProxy(proxy string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GenerateImage(ctx context.Context, accessToken, prompt, model, aspectRatio, resolution string, refs [][]byte) ([]byte, map[string]any, error) {
|
func (c *Client) GenerateImage(ctx context.Context, accessToken, prompt, model, aspectRatio, resolution string, refs [][]byte) ([]byte, map[string]any, error) {
|
||||||
session, err := c.newSession(accessToken)
|
// Everything except the generation submit egresses on the local IP. Only
|
||||||
|
// startImageGeneration (the /backend-api/f/conversation POST) goes through
|
||||||
|
// the proxy; the bootstrap / chat-requirements / reference upload / prepare
|
||||||
|
// handshake and the poll / resolve / download run direct.
|
||||||
|
session, err := c.newDirectSession(accessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -100,7 +104,12 @@ func (c *Client) GenerateImage(ctx context.Context, accessToken, prompt, model,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
conversationID, fileIDs, sedimentIDs, err := c.startImageGeneration(ctx, session, accessToken, effectivePrompt, reqs, conduitToken, model, uploadedRefs)
|
// The generation submit is the only request that egresses via the proxy.
|
||||||
|
submitSession, err := c.newSession(accessToken)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
conversationID, fileIDs, sedimentIDs, err := c.startImageGeneration(ctx, submitSession, accessToken, effectivePrompt, reqs, conduitToken, model, uploadedRefs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -110,12 +119,6 @@ func (c *Client) GenerateImage(ctx context.Context, accessToken, prompt, model,
|
|||||||
refIDs := uploadedRefIDSet(uploadedRefs)
|
refIDs := uploadedRefIDSet(uploadedRefs)
|
||||||
fileIDs = dropIDs(fileIDs, refIDs)
|
fileIDs = dropIDs(fileIDs, refIDs)
|
||||||
sedimentIDs = dropIDs(sedimentIDs, refIDs)
|
sedimentIDs = dropIDs(sedimentIDs, refIDs)
|
||||||
// Poll / resolve / download run on the local IP (fresh direct session);
|
|
||||||
// only the submit phase above egressed via the proxy.
|
|
||||||
session, err = c.newDirectSession(accessToken)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
fileIDs, sedimentIDs, err = c.pollForImage(ctx, session, accessToken, conversationID, fileIDs, sedimentIDs, refIDs, pollBudget(ctx))
|
fileIDs, sedimentIDs, err = c.pollForImage(ctx, session, accessToken, conversationID, fileIDs, sedimentIDs, refIDs, pollBudget(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@@ -224,9 +227,9 @@ func (c *Client) newSession(accessToken string) (tlsclient.HttpClient, error) {
|
|||||||
return c.newSessionP(accessToken, true)
|
return c.newSessionP(accessToken, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newDirectSession egresses on the local IP (never the proxy). Used for the
|
// newDirectSession egresses on the local IP (never the proxy). Used for
|
||||||
// poll / resolve / download phase; only the anti-bot-guarded submit phase
|
// everything except the generation submit (the /backend-api/f/conversation
|
||||||
// (bootstrap, chat-requirements, upload, conversation create) uses the proxy.
|
// POST), which is the only request that uses the proxy.
|
||||||
func (c *Client) newDirectSession(accessToken string) (tlsclient.HttpClient, error) {
|
func (c *Client) newDirectSession(accessToken string) (tlsclient.HttpClient, error) {
|
||||||
return c.newSessionP(accessToken, false)
|
return c.newSessionP(accessToken, false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ func (c *Client) GenerateVideo(ctx context.Context, token, prompt, aspectRatio,
|
|||||||
// Self-heal the x-statsig-id anti-bot challenge for THIS session before the
|
// Self-heal the x-statsig-id anti-bot challenge for THIS session before the
|
||||||
// gated submit. Without it the header falls back to the static defaults,
|
// gated submit. Without it the header falls back to the static defaults,
|
||||||
// which go stale on a new grok web build and make conversations/new answer
|
// which go stale on a new grok web build and make conversations/new answer
|
||||||
// 403 (anti-bot). Fetch via the proxy client so the derived seed matches the
|
// 403 (anti-bot). Fetch on the local IP (the proxy is rotating, so pinning
|
||||||
// submit's egress IP. Failure is non-fatal (statsigID then uses defaults).
|
// the seed to a proxy egress IP is pointless). Failure is non-fatal
|
||||||
c.ensureChallenge(ctx, submitClient, token)
|
// (statsigID then uses defaults).
|
||||||
|
c.ensureChallenge(ctx, directClient, token)
|
||||||
|
|
||||||
// Image-to-video: upload each reference frame and collect its asset URL.
|
// Image-to-video: upload each reference frame and collect its asset URL.
|
||||||
var imageRefs []string
|
var imageRefs []string
|
||||||
|
|||||||
Reference in New Issue
Block a user