Commit 2aaf29ac authored by Eva Ho's avatar Eva Ho
Browse files

app/ui: do not send to prevent errors with cloud provider

parent a42f826a
......@@ -782,6 +782,25 @@ func (s *Server) chat(w http.ResponseWriter, r *http.Request) error {
var thinkValue any
if req.Think != nil {
// Validate that the model supports thinking if requested
thinkRequested := false
switch v := req.Think.(type) {
case bool:
thinkRequested = v
case string:
thinkRequested = v != "" && v != "none"
}
if thinkRequested && !think {
errorEvent := responses.ErrorEvent{
EventName: "error",
Error: fmt.Sprintf("Model %q does not support thinking/reasoning", req.Model),
Code: "model_capability_error",
}
json.NewEncoder(w).Encode(errorEvent)
flusher.Flush()
return nil
}
thinkValue = req.Think
} else {
thinkValue = think
......@@ -866,6 +885,9 @@ func (s *Server) chat(w http.ResponseWriter, r *http.Request) error {
return err
}
// Debug: Log what we're sending
s.log().Debug("sending chat request", "model", chatReq.Model, "think", chatReq.Think, "num_messages", len(chatReq.Messages))
err = c.Chat(ctx, chatReq, func(res api.ChatResponse) error {
if loading {
// Remove the loading indicator on first token
......@@ -1794,13 +1816,14 @@ func (s *Server) buildChatRequest(chat *store.Chat, model string, think any, ava
var thinkValue *api.ThinkValue
if think != nil {
// Only set Think if it's actually requesting thinking
if boolValue, ok := think.(bool); ok {
thinkValue = &api.ThinkValue{
Value: boolValue,
if boolValue {
thinkValue = &api.ThinkValue{Value: boolValue}
}
} else if stringValue, ok := think.(string); ok {
thinkValue = &api.ThinkValue{
Value: stringValue,
if stringValue != "" && stringValue != "none" {
thinkValue = &api.ThinkValue{Value: stringValue}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment