1// Code generated by sqlc. DO NOT EDIT.
2// versions:
3// sqlc v1.30.0
4// source: llm_requests.sql
5
6package generated
7
8import (
9 "context"
10 "time"
11)
12
13const getLLMRequestBody = `-- name: GetLLMRequestBody :one
14SELECT request_body FROM llm_requests WHERE id = ?
15`
16
17func (q *Queries) GetLLMRequestBody(ctx context.Context, id int64) (*string, error) {
18 row := q.db.QueryRowContext(ctx, getLLMRequestBody, id)
19 var request_body *string
20 err := row.Scan(&request_body)
21 return request_body, err
22}
23
24const getLLMRequestByID = `-- name: GetLLMRequestByID :one
25SELECT id, conversation_id, model, provider, url, request_body, response_body, status_code, error, duration_ms, created_at, prefix_request_id, prefix_length FROM llm_requests WHERE id = ?
26`
27
28func (q *Queries) GetLLMRequestByID(ctx context.Context, id int64) (LlmRequest, error) {
29 row := q.db.QueryRowContext(ctx, getLLMRequestByID, id)
30 var i LlmRequest
31 err := row.Scan(
32 &i.ID,
33 &i.ConversationID,
34 &i.Model,
35 &i.Provider,
36 &i.Url,
37 &i.RequestBody,
38 &i.ResponseBody,
39 &i.StatusCode,
40 &i.Error,
41 &i.DurationMs,
42 &i.CreatedAt,
43 &i.PrefixRequestID,
44 &i.PrefixLength,
45 )
46 return i, err
47}
48
49const getLLMResponseBody = `-- name: GetLLMResponseBody :one
50SELECT response_body FROM llm_requests WHERE id = ?
51`
52
53func (q *Queries) GetLLMResponseBody(ctx context.Context, id int64) (*string, error) {
54 row := q.db.QueryRowContext(ctx, getLLMResponseBody, id)
55 var response_body *string
56 err := row.Scan(&response_body)
57 return response_body, err
58}
59
60const getLastRequestForConversation = `-- name: GetLastRequestForConversation :one
61SELECT id, conversation_id, model, provider, url, request_body, response_body, status_code, error, duration_ms, created_at, prefix_request_id, prefix_length FROM llm_requests
62WHERE conversation_id = ?
63ORDER BY id DESC
64LIMIT 1
65`
66
67func (q *Queries) GetLastRequestForConversation(ctx context.Context, conversationID *string) (LlmRequest, error) {
68 row := q.db.QueryRowContext(ctx, getLastRequestForConversation, conversationID)
69 var i LlmRequest
70 err := row.Scan(
71 &i.ID,
72 &i.ConversationID,
73 &i.Model,
74 &i.Provider,
75 &i.Url,
76 &i.RequestBody,
77 &i.ResponseBody,
78 &i.StatusCode,
79 &i.Error,
80 &i.DurationMs,
81 &i.CreatedAt,
82 &i.PrefixRequestID,
83 &i.PrefixLength,
84 )
85 return i, err
86}
87
88const insertLLMRequest = `-- name: InsertLLMRequest :one
89INSERT INTO llm_requests (
90 conversation_id,
91 model,
92 provider,
93 url,
94 request_body,
95 response_body,
96 status_code,
97 error,
98 duration_ms,
99 prefix_request_id,
100 prefix_length
101) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
102RETURNING id, conversation_id, model, provider, url, request_body, response_body, status_code, error, duration_ms, created_at, prefix_request_id, prefix_length
103`
104
105type InsertLLMRequestParams struct {
106 ConversationID *string `json:"conversation_id"`
107 Model string `json:"model"`
108 Provider string `json:"provider"`
109 Url string `json:"url"`
110 RequestBody *string `json:"request_body"`
111 ResponseBody *string `json:"response_body"`
112 StatusCode *int64 `json:"status_code"`
113 Error *string `json:"error"`
114 DurationMs *int64 `json:"duration_ms"`
115 PrefixRequestID *int64 `json:"prefix_request_id"`
116 PrefixLength *int64 `json:"prefix_length"`
117}
118
119func (q *Queries) InsertLLMRequest(ctx context.Context, arg InsertLLMRequestParams) (LlmRequest, error) {
120 row := q.db.QueryRowContext(ctx, insertLLMRequest,
121 arg.ConversationID,
122 arg.Model,
123 arg.Provider,
124 arg.Url,
125 arg.RequestBody,
126 arg.ResponseBody,
127 arg.StatusCode,
128 arg.Error,
129 arg.DurationMs,
130 arg.PrefixRequestID,
131 arg.PrefixLength,
132 )
133 var i LlmRequest
134 err := row.Scan(
135 &i.ID,
136 &i.ConversationID,
137 &i.Model,
138 &i.Provider,
139 &i.Url,
140 &i.RequestBody,
141 &i.ResponseBody,
142 &i.StatusCode,
143 &i.Error,
144 &i.DurationMs,
145 &i.CreatedAt,
146 &i.PrefixRequestID,
147 &i.PrefixLength,
148 )
149 return i, err
150}
151
152const listRecentLLMRequests = `-- name: ListRecentLLMRequests :many
153SELECT
154 r.id,
155 r.conversation_id,
156 r.model,
157 m.display_name as model_display_name,
158 r.provider,
159 r.url,
160 LENGTH(r.request_body) as request_body_length,
161 LENGTH(r.response_body) as response_body_length,
162 r.status_code,
163 r.error,
164 r.duration_ms,
165 r.created_at,
166 r.prefix_request_id,
167 r.prefix_length
168FROM llm_requests r
169LEFT JOIN models m ON r.model = m.model_id
170ORDER BY r.id DESC
171LIMIT ?
172`
173
174type ListRecentLLMRequestsRow struct {
175 ID int64 `json:"id"`
176 ConversationID *string `json:"conversation_id"`
177 Model string `json:"model"`
178 ModelDisplayName *string `json:"model_display_name"`
179 Provider string `json:"provider"`
180 Url string `json:"url"`
181 RequestBodyLength *int64 `json:"request_body_length"`
182 ResponseBodyLength *int64 `json:"response_body_length"`
183 StatusCode *int64 `json:"status_code"`
184 Error *string `json:"error"`
185 DurationMs *int64 `json:"duration_ms"`
186 CreatedAt time.Time `json:"created_at"`
187 PrefixRequestID *int64 `json:"prefix_request_id"`
188 PrefixLength *int64 `json:"prefix_length"`
189}
190
191func (q *Queries) ListRecentLLMRequests(ctx context.Context, limit int64) ([]ListRecentLLMRequestsRow, error) {
192 rows, err := q.db.QueryContext(ctx, listRecentLLMRequests, limit)
193 if err != nil {
194 return nil, err
195 }
196 defer rows.Close()
197 items := []ListRecentLLMRequestsRow{}
198 for rows.Next() {
199 var i ListRecentLLMRequestsRow
200 if err := rows.Scan(
201 &i.ID,
202 &i.ConversationID,
203 &i.Model,
204 &i.ModelDisplayName,
205 &i.Provider,
206 &i.Url,
207 &i.RequestBodyLength,
208 &i.ResponseBodyLength,
209 &i.StatusCode,
210 &i.Error,
211 &i.DurationMs,
212 &i.CreatedAt,
213 &i.PrefixRequestID,
214 &i.PrefixLength,
215 ); err != nil {
216 return nil, err
217 }
218 items = append(items, i)
219 }
220 if err := rows.Close(); err != nil {
221 return nil, err
222 }
223 if err := rows.Err(); err != nil {
224 return nil, err
225 }
226 return items, nil
227}