Adopt Promptkit at application boundaries
This commit is contained in:
@@ -8,12 +8,12 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/scriptorium"
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||
)
|
||||
|
||||
type Runner interface {
|
||||
Run(ctx context.Context, req scriptorium.RunRequest) (*scriptorium.RunResult, error)
|
||||
Run(ctx context.Context, req promptkit.RunRequest) (*promptkit.RunResult, error)
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
@@ -81,21 +81,21 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
mappedInputs := make(map[string]scriptorium.ArtifactRef, len(req.Inputs))
|
||||
mappedInputs := make(map[string]promptkit.ArtifactRef, len(req.Inputs))
|
||||
for name, in := range req.Inputs {
|
||||
mappedInputs[name] = scriptorium.ArtifactRef{
|
||||
Type: scriptorium.ArtifactRefType(in.Type),
|
||||
mappedInputs[name] = promptkit.ArtifactRef{
|
||||
Type: promptkit.ArtifactRefType(in.Type),
|
||||
URI: in.URI,
|
||||
Body: in.Body,
|
||||
}
|
||||
}
|
||||
|
||||
var model *scriptorium.ExecutionTargetOverride
|
||||
var model *promptkit.ExecutionTargetOverride
|
||||
if req.Model != nil {
|
||||
model = executionTargetOverrideFromModelOverrideDTO(req.Model)
|
||||
}
|
||||
|
||||
res, err := h.runner.Run(r.Context(), scriptorium.RunRequest{
|
||||
res, err := h.runner.Run(r.Context(), promptkit.RunRequest{
|
||||
PromptID: req.PromptID,
|
||||
PromptVersion: req.PromptVersion,
|
||||
ProfileID: req.ProfileID,
|
||||
@@ -152,11 +152,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
writeLimitedJSON(w, http.StatusOK, resp, h.options.MaxResponseBytes)
|
||||
}
|
||||
|
||||
func executionTargetOverrideFromModelOverrideDTO(dto *modelOverrideRequestDTO) *scriptorium.ExecutionTargetOverride {
|
||||
func executionTargetOverrideFromModelOverrideDTO(dto *modelOverrideRequestDTO) *promptkit.ExecutionTargetOverride {
|
||||
if dto == nil {
|
||||
return nil
|
||||
}
|
||||
return &scriptorium.ExecutionTargetOverride{
|
||||
return &promptkit.ExecutionTargetOverride{
|
||||
Endpoint: dto.Endpoint,
|
||||
Model: dto.Model,
|
||||
Temperature: dto.Temperature,
|
||||
@@ -170,7 +170,7 @@ func executionTargetOverrideFromModelOverrideDTO(dto *modelOverrideRequestDTO) *
|
||||
}
|
||||
}
|
||||
|
||||
func modelParamsDTOFromExecutionTarget(target scriptorium.ExecutionTarget) modelParamsDTO {
|
||||
func modelParamsDTOFromExecutionTarget(target promptkit.ExecutionTarget) modelParamsDTO {
|
||||
return modelParamsDTO{
|
||||
Endpoint: target.Endpoint,
|
||||
Model: target.Model,
|
||||
@@ -185,7 +185,7 @@ func modelParamsDTOFromExecutionTarget(target scriptorium.ExecutionTarget) model
|
||||
}
|
||||
}
|
||||
|
||||
func mapValidation(v scriptorium.ValidationResult) validationDTO {
|
||||
func mapValidation(v promptkit.ValidationResult) validationDTO {
|
||||
return validationDTO{
|
||||
Status: string(v.Status),
|
||||
Mode: string(v.Mode),
|
||||
@@ -198,31 +198,31 @@ func mapValidation(v scriptorium.ValidationResult) validationDTO {
|
||||
|
||||
func mapRunError(err error) (int, string, string) {
|
||||
switch {
|
||||
case errors.Is(err, scriptorium.ErrPromptNotFound):
|
||||
case errors.Is(err, promptkit.ErrPromptNotFound):
|
||||
return http.StatusNotFound, "prompt_not_found", "prompt definition not found"
|
||||
case errors.Is(err, scriptorium.ErrProfileNotFound):
|
||||
case errors.Is(err, promptkit.ErrProfileNotFound):
|
||||
return http.StatusNotFound, "profile_not_found", "execution profile not found"
|
||||
case errors.Is(err, scriptorium.ErrProfileRequired):
|
||||
case errors.Is(err, promptkit.ErrProfileRequired):
|
||||
return http.StatusBadRequest, "profile_required", "profile_id is required when prompt default_profile is not set"
|
||||
case errors.Is(err, scriptorium.ErrAPIKeyEnvMissing):
|
||||
case errors.Is(err, promptkit.ErrAPIKeyEnvMissing):
|
||||
return http.StatusBadRequest, "api_key_env_missing", "api_key_env is set but the environment variable is missing"
|
||||
case errors.Is(err, scriptorium.ErrPromptLoad):
|
||||
case errors.Is(err, promptkit.ErrPromptLoad):
|
||||
return http.StatusBadRequest, "prompt_load_failed", "failed to load prompt definition"
|
||||
case errors.Is(err, scriptorium.ErrProfileLoad):
|
||||
case errors.Is(err, promptkit.ErrProfileLoad):
|
||||
return http.StatusBadRequest, "profile_load_failed", "failed to load execution profile"
|
||||
case errors.Is(err, scriptorium.ErrInvalidRequest):
|
||||
case errors.Is(err, promptkit.ErrInvalidRequest):
|
||||
return http.StatusBadRequest, "invalid_request", "invalid run request"
|
||||
case errors.Is(err, ErrFileNotAllowed), errors.Is(err, ErrFileOutsideRoot):
|
||||
return http.StatusBadRequest, "artifact_not_allowed", "file input artifact is not allowed"
|
||||
case errors.Is(err, ErrFileTooLarge):
|
||||
return http.StatusRequestEntityTooLarge, "artifact_too_large", "file input artifact is too large"
|
||||
case errors.Is(err, scriptorium.ErrArtifactLoad):
|
||||
case errors.Is(err, promptkit.ErrArtifactLoad):
|
||||
return http.StatusBadRequest, "artifact_read_failed", "failed to read input artifact"
|
||||
case errors.Is(err, scriptorium.ErrPromptRender):
|
||||
case errors.Is(err, promptkit.ErrPromptRender):
|
||||
return http.StatusBadRequest, "prompt_render_failed", "failed to render prompt"
|
||||
case errors.Is(err, scriptorium.ErrLLMGenerate):
|
||||
case errors.Is(err, promptkit.ErrLLMGenerate):
|
||||
return http.StatusBadGateway, "llm_failed", "model generation request failed"
|
||||
case errors.Is(err, scriptorium.ErrValidation):
|
||||
case errors.Is(err, promptkit.ErrValidation):
|
||||
return http.StatusInternalServerError, "validation_runtime_failed", "validation runtime failed"
|
||||
default:
|
||||
return http.StatusInternalServerError, "internal_error", "internal server error"
|
||||
|
||||
Reference in New Issue
Block a user