@@ -54,17 +54,16 @@ public static void FindCompatibleUrl(LlmConfig config)
5454 var schemesToTry = new List < string > ( ) ;
5555 if ( baseUrl . StartsWith ( "http://" , StringComparison . OrdinalIgnoreCase ) )
5656 {
57+ schemesToTry . Add ( "https://" + baseUrl . Substring ( 7 ) ) ;
5758 schemesToTry . Add ( baseUrl ) ;
58- schemesToTry . Add ( "https://" + baseUrl . Substring ( 7 ) ) ; // then HTTPS
5959 }
6060 else if ( baseUrl . StartsWith ( "https://" , StringComparison . OrdinalIgnoreCase ) )
6161 {
62- schemesToTry . Add ( baseUrl ) ; // HTTPS first
63- schemesToTry . Add ( "http://" + baseUrl . Substring ( 8 ) ) ; // then HTTP
62+ schemesToTry . Add ( baseUrl ) ;
63+ schemesToTry . Add ( "http://" + baseUrl . Substring ( 8 ) ) ;
6464 }
6565 else
6666 {
67- // no scheme, try both
6867 schemesToTry . Add ( "https://" + baseUrl ) ;
6968 schemesToTry . Add ( "http://" + baseUrl ) ;
7069 }
@@ -81,10 +80,9 @@ public static void FindCompatibleUrl(LlmConfig config)
8180
8281 var variants = new List < string >
8382 {
84- Combine ( "responses" ) ,
85- Combine ( "v1/responses" ) ,
8683 Combine ( "v1/chat/completions" ) ,
87- Combine ( "chat/completions" ) ,
84+ Combine ( "api/v1/chat/completions" ) ,
85+ Combine ( "api/paas/v4/chat/completions" )
8886 } ;
8987
9088
@@ -100,24 +98,24 @@ public static void FindCompatibleUrl(LlmConfig config)
10098 var req = ( HttpWebRequest ) WebRequest . Create ( url ) ;
10199 req . Method = "POST" ;
102100 req . ContentType = "application/json" ;
103- req . Timeout = 2500 ;
104-
105- if ( ! string . IsNullOrWhiteSpace ( config . ApiKey ) )
101+ req . Timeout = 2000 ;
102+ // Only send api key on https
103+ if ( ! string . IsNullOrWhiteSpace ( config . ApiKey ) && url . StartsWith ( "https://" , StringComparison . OrdinalIgnoreCase ) )
106104 req . Headers [ "Authorization" ] = $ "Bearer { config . ApiKey } ";
107105
108106 using ( var writer = new StreamWriter ( req . GetRequestStream ( ) ) )
109107 {
110108 writer . Write ( $@ "
111- {{
112- ""model"": ""{ config . Model } "",
113- ""max_tokens"": 1,
114- ""messages"": [
115109 {{
116- ""role"": ""user"",
117- ""content"": ""Hello there.""
118- }}
119- ]
120- }}" ) ;
110+ ""model"": ""{ config . Model } "",
111+ ""max_tokens"": 1,
112+ ""messages"": [
113+ {{
114+ ""role"": ""user"",
115+ ""content"": ""Hello there.""
116+ }}
117+ ]
118+ }}" ) ;
121119 }
122120
123121 using var resp = ( HttpWebResponse ) req . GetResponse ( ) ;
@@ -136,14 +134,18 @@ public static void FindCompatibleUrl(LlmConfig config)
136134 }
137135 }
138136 }
139- catch ( WebException )
137+ catch ( WebException ) // ex)
140138 {
141- // if (ex.Response is HttpWebResponse response)
142- // Console.WriteLine($"Failed {url} - Status Code: {(int)response.StatusCode} ({response.StatusCode})");
139+ /*
140+ if (ex.Response is HttpWebResponse r)
141+ Console.WriteLine($"Failed {url}: {(int)r.StatusCode} {r.StatusCode}");
142+ */
143143 }
144144 } ) ;
145145 }
146146 if ( ! found )
147- throw new Exception ( "Endpoint is not working or API key or specified model is not provided" ) ;
147+ throw new InvalidOperationException (
148+ $ "Failed to connect { baseUrl } . Endpoint may not exist, or require a valid API key."
149+ ) ;
148150 }
149151}
0 commit comments