(t *testing.T)
| 10113 | } |
| 10114 | |
| 10115 | func seedChatCostFixture(t *testing.T) chatCostTestFixture { |
| 10116 | t.Helper() |
| 10117 | |
| 10118 | client, db := newChatClientWithDatabase(t) |
| 10119 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 10120 | modelConfig := createChatModelConfig(t, client) |
| 10121 | |
| 10122 | chat := dbgen.Chat(t, db, database.Chat{ |
| 10123 | OrganizationID: firstUser.OrganizationID, |
| 10124 | OwnerID: firstUser.UserID, |
| 10125 | LastModelConfigID: modelConfig.ID, |
| 10126 | Title: "test chat", |
| 10127 | }) |
| 10128 | |
| 10129 | msg1 := dbgen.ChatMessage(t, db, database.ChatMessage{ |
| 10130 | ChatID: chat.ID, |
| 10131 | ModelConfigID: uuid.NullUUID{UUID: modelConfig.ID, Valid: true}, |
| 10132 | Role: database.ChatMessageRoleAssistant, |
| 10133 | InputTokens: sql.NullInt64{Int64: 100, Valid: true}, |
| 10134 | OutputTokens: sql.NullInt64{Int64: 50, Valid: true}, |
| 10135 | TotalCostMicros: sql.NullInt64{Int64: 500, Valid: true}, |
| 10136 | RuntimeMs: sql.NullInt64{Int64: 1500, Valid: true}, |
| 10137 | }) |
| 10138 | msg2 := dbgen.ChatMessage(t, db, database.ChatMessage{ |
| 10139 | ChatID: chat.ID, |
| 10140 | ModelConfigID: uuid.NullUUID{UUID: modelConfig.ID, Valid: true}, |
| 10141 | Role: database.ChatMessageRoleAssistant, |
| 10142 | InputTokens: sql.NullInt64{Int64: 100, Valid: true}, |
| 10143 | OutputTokens: sql.NullInt64{Int64: 50, Valid: true}, |
| 10144 | TotalCostMicros: sql.NullInt64{Int64: 500, Valid: true}, |
| 10145 | RuntimeMs: sql.NullInt64{Int64: 2500, Valid: true}, |
| 10146 | }) |
| 10147 | results := []database.ChatMessage{msg1, msg2} |
| 10148 | require.Len(t, results, 2) |
| 10149 | |
| 10150 | earliestCreatedAt := results[0].CreatedAt |
| 10151 | latestCreatedAt := results[0].CreatedAt |
| 10152 | for _, msg := range results { |
| 10153 | if msg.CreatedAt.Before(earliestCreatedAt) { |
| 10154 | earliestCreatedAt = msg.CreatedAt |
| 10155 | } |
| 10156 | if msg.CreatedAt.After(latestCreatedAt) { |
| 10157 | latestCreatedAt = msg.CreatedAt |
| 10158 | } |
| 10159 | } |
| 10160 | |
| 10161 | return chatCostTestFixture{ |
| 10162 | Client: client, |
| 10163 | DB: db, |
| 10164 | ModelConfigID: modelConfig.ID, |
| 10165 | ChatID: chat.ID, |
| 10166 | EarliestCreatedAt: earliestCreatedAt, |
| 10167 | LatestCreatedAt: latestCreatedAt, |
| 10168 | } |
| 10169 | } |
| 10170 | |
| 10171 | func assertChatCostSummary(t *testing.T, summary codersdk.ChatCostSummary, modelConfigID, chatID uuid.UUID) { |
| 10172 | t.Helper() |
no test coverage detected