@@ -15,16 +15,16 @@ import (
15
15
16
16
const (
17
17
aiDevopsChatPath = "chat/platform"
18
+ dbChangesetPath = "chat/db-changeset"
18
19
)
19
20
20
21
type GenaiService struct {
21
22
Client * Client
22
23
}
23
24
24
- // SendAIDevOpsChat sends a request to the AI DevOps service and returns the response.
25
- // If request.Stream is true and onProgress is provided, it will handle streaming responses.
26
- // For non-streaming requests or when onProgress is nil, it will use the standard request flow.
27
- func (g * GenaiService ) SendAIDevOpsChat (ctx context.Context , scope dto.Scope , request * dto.ServiceChatParameters , onProgress ... func (progressUpdate dto.ProgressUpdate ) error ) (* dto.ServiceChatResponse , error ) {
25
+ // sendGenAIRequest is a generic method to send requests to GenAI services
26
+ func (g * GenaiService ) sendGenAIRequest (ctx context.Context , path string , scope dto.Scope , request dto.GenAIRequest ,
27
+ onProgress ... func (progressUpdate dto.ProgressUpdate ) error ) (* dto.ServiceChatResponse , error ) {
28
28
if g == nil || g .Client == nil {
29
29
return nil , fmt .Errorf ("genai service or client is nil" )
30
30
}
@@ -56,11 +56,13 @@ func (g *GenaiService) SendAIDevOpsChat(ctx context.Context, scope dto.Scope, re
56
56
params ["projectIdentifier" ] = scope .ProjectID
57
57
}
58
58
59
+ // Determine if streaming is required
60
+ shouldStream := request .IsStreaming () && progressCB != nil
61
+
59
62
// Handle non-streaming case with early return
60
- isStreaming := request .Stream && progressCB != nil
61
- if ! isStreaming {
63
+ if ! shouldStream {
62
64
var response dto.ServiceChatResponse
63
- err := g .Client .Post (ctx , aiDevopsChatPath , params , request , & response )
65
+ err := g .Client .Post (ctx , path , params , request , & response )
64
66
if err != nil {
65
67
return nil , fmt .Errorf ("failed to send request to genai service: %w" , err )
66
68
}
@@ -69,7 +71,7 @@ func (g *GenaiService) SendAIDevOpsChat(ctx context.Context, scope dto.Scope, re
69
71
}
70
72
71
73
// Execute the streaming request
72
- resp , err := g .Client .PostStream (ctx , aiDevopsChatPath , params , request )
74
+ resp , err := g .Client .PostStream (ctx , path , params , request )
73
75
if err != nil {
74
76
slog .Warn ("Failed to execute streaming request" , "error" , err .Error ())
75
77
return nil , fmt .Errorf ("failed to execute streaming request: %w" , err )
@@ -84,7 +86,7 @@ func (g *GenaiService) SendAIDevOpsChat(ctx context.Context, scope dto.Scope, re
84
86
85
87
// Initialize the response with conversation ID from request
86
88
finalResponse := & dto.ServiceChatResponse {
87
- ConversationID : request .ConversationID ,
89
+ ConversationID : request .GetBaseParameters (). ConversationID ,
88
90
}
89
91
90
92
// Process the streaming response
@@ -97,6 +99,19 @@ func (g *GenaiService) SendAIDevOpsChat(ctx context.Context, scope dto.Scope, re
97
99
return finalResponse , nil
98
100
}
99
101
102
+ // SendAIDevOpsChat sends a request to the AI DevOps service and returns the response.
103
+ // If request.Stream is true and onProgress is provided, it will handle streaming responses.
104
+ // For non-streaming requests or when onProgress is nil, it will use the standard request flow.
105
+ func (g * GenaiService ) SendAIDevOpsChat (ctx context.Context , scope dto.Scope , request * dto.ServiceChatParameters , onProgress ... func (progressUpdate dto.ProgressUpdate ) error ) (* dto.ServiceChatResponse , error ) {
106
+ return g .sendGenAIRequest (ctx , aiDevopsChatPath , scope , request , onProgress ... )
107
+ }
108
+
109
+ // SendDBChangeset sends a request to generate database changesets and returns the response.
110
+ // If request.Stream is true and onProgress is provided, it will handle streaming responses.
111
+ func (g * GenaiService ) SendDBChangeset (ctx context.Context , scope dto.Scope , request * dto.DBChangesetParameters , onProgress ... func (progressUpdate dto.ProgressUpdate ) error ) (* dto.ServiceChatResponse , error ) {
112
+ return g .sendGenAIRequest (ctx , dbChangesetPath , scope , request , onProgress ... )
113
+ }
114
+
100
115
// processStreamingResponse handles Server-Sent Events (SSE) streaming responses
101
116
// and accumulates complete events before forwarding them with appropriate event types
102
117
func (g * GenaiService ) processStreamingResponse (body io.ReadCloser , finalResponse * dto.ServiceChatResponse , onProgress func (dto.ProgressUpdate ) error ) error {
0 commit comments