@@ -29,6 +29,12 @@ import (
2929
3030// -----------------------------------------------------------------------------
3131
32+ func newGenImageResponse (c * geno.Client , body map [string ]any ) (xai.OperationResponse , error ) {
33+ return geno .NewOperationResponse [adapter ](c , xai .GenImage , body ), nil
34+ }
35+
36+ // -----------------------------------------------------------------------------
37+
3238type adapter struct {}
3339
3440func (adapter ) Actions (model xai.Model ) []xai.Action {
@@ -49,50 +55,52 @@ func (adapter) ActionInfo(action xai.Action) geno.ActionInfo {
4955 }
5056}
5157
52- func (adapter ) QueryOpInfo (action xai.Action , body map [string ]any ) geno.QueryOpInfo {
58+ func (adapter ) QueryOpInfo (action xai.Action , body map [string ]any ) ( ret geno.QueryOpInfo , err error ) {
5359 switch action {
5460 case xai .GenImage :
5561 data , _ := body ["data" ].(map [string ]any )
56- id , _ := data ["task_id" ].(string )
57- return geno.QueryOpInfo {
58- Path : "/v1/images/generations/" + id ,
59- NewResponse : newGenImageResponse ,
62+ if id , ok := data ["task_id" ].(string ); ok {
63+ ret .Path = "/v1/images/generations/" + id
64+ ret .NewResponse = newGenImageResponse
65+ } else {
66+ err = geno .ErrMissingOperationID
6067 }
6168 default :
6269 panic ("unexpected action: " + action )
6370 }
71+ return
6472}
6573
6674func (adapter ) Results (action xai.Action , body map [string ]any ) xai.Results {
67- data , _ := body ["task_result" ].(map [string ]any )
75+ result , _ := body ["task_result" ].(map [string ]any )
6876 switch action {
6977 case xai .GenImage :
70- return geno .NewImageResults [adapter ](data , "images" )
78+ return geno .NewImageResults [adapter ](result , "images" )
7179 default :
7280 panic ("unexpected action: " + action )
7381 }
7482}
7583
84+ func (adapter ) Sleep (action xai.Action , body map [string ]any ) {
85+ switch action {
86+ case xai .GenVideo :
87+ // sleep 10s for video operations
88+ time .Sleep (10 * time .Second )
89+ default :
90+ // sleep 0.5s for image operations
91+ time .Sleep (time .Second / 2 )
92+ }
93+ }
94+
7695func (adapter ) Done (action xai.Action , body map [string ]any ) bool {
7796 data , _ := body ["data" ].(map [string ]any )
7897 return data ["task_status" ] == "succeed" // submitted, processing, succeed, failed
7998}
8099
81- func (adapter ) Sleep (action xai.Action , body map [string ]any ) {
82- if action == xai .GenVideo {
83- time .Sleep (10 * time .Second ) // sleep 10s for video operations
84- }
85- time .Sleep (time .Second / 2 ) // sleep 0.5s for image operations
86- }
87-
88100func (adapter ) OutputImage (item any ) * xai.OutputImage {
89101 panic ("todo" )
90102}
91103
92- func newGenImageResponse (c * geno.Client , body map [string ]any ) (xai.OperationResponse , error ) {
93- return geno .NewOperationResponse [adapter ](c , xai .GenImage , body ), nil
94- }
95-
96104// -----------------------------------------------------------------------------
97105
98106const (
0 commit comments