asd
This commit is contained in:
parent
b3f02ea15e
commit
9de71239b1
2 changed files with 63 additions and 0 deletions
63
main.go
Normal file
63
main.go
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"prsi/internal/api"
|
||||||
|
"prsi/internal/llm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hub := api.NewHub()
|
||||||
|
|
||||||
|
// Static files
|
||||||
|
http.Handle("/", http.FileServer(http.Dir("./web/static")))
|
||||||
|
|
||||||
|
// WebSocket
|
||||||
|
http.HandleFunc("/ws", hub.HandleWS)
|
||||||
|
|
||||||
|
// Expose current script for a game room (used by the script viewer panel)
|
||||||
|
http.HandleFunc("/api/script", hub.HandleGetScript)
|
||||||
|
|
||||||
|
// LLM rule-generation endpoint
|
||||||
|
http.HandleFunc("/api/generate-rule", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req struct {
|
||||||
|
CurrentScript string `json:"current_script"`
|
||||||
|
RulePrompt string `json:"rule_prompt"`
|
||||||
|
WinnerName string `json:"winner_name"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
|
http.Error(w, "bad request", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.RulePrompt == "" {
|
||||||
|
http.Error(w, "rule_prompt is required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := llm.GenerateRule(llm.GenerateRuleRequest{
|
||||||
|
CurrentScript: req.CurrentScript,
|
||||||
|
RulePrompt: req.RulePrompt,
|
||||||
|
WinnerName: req.WinnerName,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Println("generate-rule error:", err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(result)
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Println("Server starting on :8080")
|
||||||
|
if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||||
|
log.Fatal("ListenAndServe:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
prsi
Executable file
BIN
prsi
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue