@@ -49,6 +49,42 @@ var _ = Describe("Gallery API tests", func() {
4949 ).ToNot (HaveOccurred ())
5050 })
5151 })
52+
53+ Context ("HuggingFace mirror" , func () {
54+ var originalEndpoint string
55+
56+ BeforeEach (func () {
57+ originalEndpoint = HF_ENDPOINT
58+ })
59+
60+ AfterEach (func () {
61+ HF_ENDPOINT = originalEndpoint
62+ })
63+
64+ It ("rewrites direct https://huggingface.co URLs when mirror is set" , func () {
65+ HF_ENDPOINT = "https://hf-mirror.com"
66+ uri := URI ("https://huggingface.co/TheBloke/model-GGUF/resolve/main/model.Q4_K_M.gguf" )
67+ Expect (uri .ResolveURL ()).To (Equal ("https://hf-mirror.com/TheBloke/model-GGUF/resolve/main/model.Q4_K_M.gguf" ))
68+ })
69+
70+ It ("does not rewrite direct https://huggingface.co URLs when no mirror is set" , func () {
71+ HF_ENDPOINT = "https://huggingface.co"
72+ uri := URI ("https://huggingface.co/TheBloke/model-GGUF/resolve/main/model.Q4_K_M.gguf" )
73+ Expect (uri .ResolveURL ()).To (Equal ("https://huggingface.co/TheBloke/model-GGUF/resolve/main/model.Q4_K_M.gguf" ))
74+ })
75+
76+ It ("rewrites hf:// URIs when mirror is set" , func () {
77+ HF_ENDPOINT = "https://hf-mirror.com"
78+ uri := URI ("hf://TheBloke/model-GGUF/model.Q4_K_M.gguf" )
79+ Expect (uri .ResolveURL ()).To (Equal ("https://hf-mirror.com/TheBloke/model-GGUF/resolve/main/model.Q4_K_M.gguf" ))
80+ })
81+
82+ It ("does not rewrite non-huggingface URLs" , func () {
83+ HF_ENDPOINT = "https://hf-mirror.com"
84+ uri := URI ("https://example.com/some/file.gguf" )
85+ Expect (uri .ResolveURL ()).To (Equal ("https://example.com/some/file.gguf" ))
86+ })
87+ })
5288})
5389
5490var _ = Describe ("ContentLength" , func () {
0 commit comments