mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-16 18:41:03 +01:00
Fix 2d63263b79
by applying the override on the backend rather than in the client-side variable that isn't actually being referenced
This commit is contained in:
parent
b0f3107da2
commit
afe1a38a0e
@ -313,7 +313,7 @@ func (s *Server) aiSuggestionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var req ai.AiSuggestionRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to decode: %w", err))
|
||||
panic(fmt.Errorf("failed to decode AiSuggestionRequest: %w", err))
|
||||
}
|
||||
if req.NumberCompletions > 10 {
|
||||
panic(fmt.Errorf("request for %d completions is greater than max allowed", req.NumberCompletions))
|
||||
@ -338,6 +338,17 @@ func (s *Server) aiSuggestionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) testOnlyOverrideAiSuggestions(w http.ResponseWriter, r *http.Request) {
|
||||
var req ai.TestOnlyOverrideAiSuggestionRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to decode TestOnlyOverrideAiSuggestionRequest: %w", err))
|
||||
}
|
||||
ai.TestOnlyOverrideAiSuggestions[req.Query] = req.Suggestions
|
||||
w.Header().Set("Content-Length", "0")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Server) pingHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("OK"))
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ func (s *Server) Run(ctx context.Context, addr string) error {
|
||||
mux.Handle("/internal/api/v1/usage-stats", middlewares(http.HandlerFunc(s.usageStatsHandler)))
|
||||
mux.Handle("/internal/api/v1/stats", middlewares(http.HandlerFunc(s.statsHandler)))
|
||||
if s.isTestEnvironment {
|
||||
mux.Handle("/api/v1/ai-suggest-override", middlewares(http.HandlerFunc(s.testOnlyOverrideAiSuggestions)))
|
||||
mux.Handle("/api/v1/wipe-db-entries", middlewares(http.HandlerFunc(s.wipeDbEntriesHandler)))
|
||||
mux.Handle("/api/v1/get-num-connections", middlewares(http.HandlerFunc(s.getNumConnectionsHandler)))
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -1935,9 +1936,14 @@ func testTui_ai(t *testing.T) {
|
||||
// Setup
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester, _, _ := setupTestTui(t, Online)
|
||||
req, err := json.Marshal(
|
||||
ai.TestOnlyOverrideAiSuggestionRequest{Query: "myQuery", Suggestions: []string{"result 1", "result 2", "longer result 3"}},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
_, err = lib.ApiPost(hctx.MakeContext(), "/api/v1/ai-suggest-override", "application/json", req)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test running an AI query
|
||||
ai.TestOnlyOverrideAiSuggestions["myQuery"] = []string{"result 1", "result 2", "longer result 3"}
|
||||
out := captureTerminalOutput(t, tester, []string{
|
||||
"hishtory SPACE tquery ENTER",
|
||||
"?myQuery",
|
||||
|
@ -44,6 +44,11 @@ type OpenAiUsage struct {
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
}
|
||||
|
||||
type TestOnlyOverrideAiSuggestionRequest struct {
|
||||
Query string `json:"query"`
|
||||
Suggestions []string `json:"suggestions"`
|
||||
}
|
||||
|
||||
var TestOnlyOverrideAiSuggestions map[string][]string = make(map[string][]string)
|
||||
|
||||
func GetAiSuggestionsViaOpenAiApi(query string, numberCompletions int) ([]string, OpenAiUsage, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user