diff --git a/cmd/wisdom/main.go b/cmd/wisdom/main.go index 0af7813..ae96499 100644 --- a/cmd/wisdom/main.go +++ b/cmd/wisdom/main.go @@ -133,6 +133,7 @@ func newStartServerCommand() *cobra.Command { } r.HandleFunc("/infer", h.InferHandler).Methods("POST") + r.HandleFunc("/infer", h.CORSHandler).Methods("OPTIONS") //r.HandleFunc("/feedback", h.FeedbackHandler).Methods("POST") r.HandleFunc("/login", h.HandleLogin) r.HandleFunc("/githubcallback", h.HandleGithubCallback) diff --git a/pkg/filters/markdown/markdown.go b/pkg/filters/markdown/markdown.go index dc41e95..e8010a4 100644 --- a/pkg/filters/markdown/markdown.go +++ b/pkg/filters/markdown/markdown.go @@ -23,6 +23,9 @@ func MarkdownStripper(response *api.ModelResponse) (*api.ModelResponse, error) { //response.Output = markdownRegex.ReplaceAllString(response.Output, "") matches := markdownRegex.FindStringSubmatch(response.Output) + if len(matches) < 2 { + return response, fmt.Errorf("no markdown found in response") + } response.Output = matches[1] /* node := gomarkdown.Parse([]byte(response.Output), nil) diff --git a/pkg/model/invoker.go b/pkg/model/invoker.go index 9a258dd..2343151 100644 --- a/pkg/model/invoker.go +++ b/pkg/model/invoker.go @@ -1,6 +1,8 @@ package model import ( + log "github.com/sirupsen/logrus" + "github.com/openshift/wisdom/pkg/api" "github.com/openshift/wisdom/pkg/filters" ) @@ -11,6 +13,7 @@ func InvokeModel(input api.ModelInput, model api.Model, filter filters.Filter) ( if response == nil { response = &api.ModelResponse{} } + log.Debugf("model response: %#v", response) if err != nil { response.ErrorMessage = err.Error() return response, err diff --git a/pkg/server/inference_handler.go b/pkg/server/inference_handler.go index 2b7efd7..a14b683 100644 --- a/pkg/server/inference_handler.go +++ b/pkg/server/inference_handler.go @@ -10,6 +10,13 @@ import ( "github.com/openshift/wisdom/pkg/model" ) +func (h *Handler) CORSHandler(w http.ResponseWriter, r *http.Request) { + http.Header.Add(w.Header(), "Access-Control-Allow-Origin", "*") + http.Header.Add(w.Header(), "Access-Control-Allow-Methods", "GET, POST, OPTIONS") + http.Header.Add(w.Header(), "Access-Control-Allow-Headers", "Content-Type, Authorization") + +} + func (h *Handler) InferHandler(w http.ResponseWriter, r *http.Request) { if !h.hasValidBearerToken(r) { http.Error(w, "No valid bearer token found", http.StatusUnauthorized)