Skip to content
TheChatArchiveThe Chat Archive
Amazon Novaamazon-nova-experimental-chat-05-14· AmazonHugging Face LMArena Human Preference 140K

Can you edit this script so that if the inputted text in the query isnt a .m3u8 or .mp4,…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    Can you edit this script so that if the inputted text in the query isnt a .m3u8 or .mp4, or it doesnt start with "http://" or "https://", it returns invalid URL?

    package main
    
    import (
    	"html"
    	"log"
    
    	"github.com/gofiber/fiber/v2"
    )
    
    func main() {
    	app := fiber.New(fiber.Config{
    		Prefork: true,
    	})
    
    	app.Static("/", ".", fiber.Static{
    		Index: "index.html",
    	})
    
    	app.Get("/play", func(c *fiber.Ctx) error {
    		query := c.Query("query")
    		if query == "" {
    			return c.SendString("")
    		}
    		return c.SendString("You searched for: " + html.EscapeString(query))
    	})
    
    	if err := app.Listen(":80"); err != nil {
    		log.Fatalf("Error starting server: %v", err)
    	}
    }
    
  2. Amazon Nova Assistant

    Certainly! Below is the edited script that checks if the inputted text in the query is a .m3u8 or .mp4, and if it starts with "http://" or "https://". If these conditions are not met, it returns "invalid URL".

    package main
    
    import (
    	"html"
    	"log"
    	"strings"
    
    	"github.com/gofiber/fiber/v2"
    )
    
    func main() {
    	app := fiber.New(fiber.Config{
    		Prefork: true,
    	})
    
    	app.Static("/", ".", fiber.Static{
    		Index: "index.html",
    	})
    
    	app.Get("/play", func(c *fiber.Ctx) error {
    		query := c.Query("query")
    		if query == "" {
    			return c.SendString("No query provided")
    		}
    
    		// Check if the query is a valid URL and has the correct extension
    		if !isValidURL(query) {
    			return c.SendString("invalid URL")
    		}
    
    		return c.SendString("You searched for: " + html.EscapeString(query))
    	})
    
    	if err := app.Listen(":80"); err != nil {
    		log.Fatalf("Error starting server: %v", err)
    	}
    }
    
    func isValidURL(url string) bool {
    	// Check if the URL starts with "http://" or  "https://"
    	if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
    		return false
    	}
    
    	// Check if the URL ends with ".m3u8" or ".mp4"
    	if !strings.HasSuffix(url, ".m3u8") && !strings.HasSuffix(url, ".mp4") {
    		return false
    	}
    	return true
    }
    
    

    Explanation:

    1. Import "strings" Package:

      • Imported the strings package to use HasPrefix and HasSuffix functions.
    2. isValidURL Function:

      • strings.HasPrefix: Checks if the URL starts with "http://" or "https://".
      • strings.HasSuffix: Checks if the URL ends with ".m3u8" or ".mp4".
      • If either check fails the function returns false, otherwise it returns true
    3. /play Endpoint:

      • Added a call to isValidURL(query) to validate the query.
      • If isValidURL returns false, the server responds with "invalid URL".
      • If the query is empty it now responds with “No query provided” instead of an empty string.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.