( ctx context.Context, userID uuid.UUID, modelConfigID uuid.UUID, )
| 961 | } |
| 962 | |
| 963 | func (api *API) validateUserChatModelConfigAvailable( |
| 964 | ctx context.Context, |
| 965 | userID uuid.UUID, |
| 966 | modelConfigID uuid.UUID, |
| 967 | ) (int, *codersdk.Response) { |
| 968 | reason, err := api.userCanUseChatModelConfig(ctx, userID, modelConfigID) |
| 969 | if err != nil { |
| 970 | return http.StatusInternalServerError, &codersdk.Response{ |
| 971 | Message: "Internal error validating model config override.", |
| 972 | Detail: err.Error(), |
| 973 | } |
| 974 | } |
| 975 | switch reason { |
| 976 | case chatModelConfigAvailable: |
| 977 | return 0, nil |
| 978 | case chatModelConfigUnavailableModelNotFoundOrDisabled: |
| 979 | return http.StatusBadRequest, &codersdk.Response{ |
| 980 | Message: "Invalid model_config_id: model config not found or disabled.", |
| 981 | } |
| 982 | case chatModelConfigUnavailableCredentialsMissing: |
| 983 | return http.StatusBadRequest, &codersdk.Response{ |
| 984 | Message: "Invalid model_config_id: provider credentials unavailable for this model.", |
| 985 | } |
| 986 | case chatModelConfigUnavailableProviderDisabled: |
| 987 | return http.StatusBadRequest, &codersdk.Response{ |
| 988 | Message: "Invalid model_config_id: provider is not enabled for this model.", |
| 989 | } |
| 990 | default: |
| 991 | api.Logger.Warn(ctx, |
| 992 | "unknown chat model config availability reason", |
| 993 | slog.F("user_id", userID), |
| 994 | slog.F("model_config_id", modelConfigID), |
| 995 | slog.F("reason", reason), |
| 996 | ) |
| 997 | return http.StatusBadRequest, &codersdk.Response{ |
| 998 | Message: "Invalid model_config_id.", |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 1004 | // |
no test coverage detected