@@ -62,10 +62,46 @@ def copilot_headers(
6262 return h
6363
6464
65- def fetch_models (copilot_token : str , account_type : str = "individual " ):
66- url = f"{ copilot_base_url ( account_type ) } /models"
65+ def fetch_models (copilot_token : str , base_url : str = "https://192.168.1.100:5000 " ):
66+ url = f"{ base_url } /v1 /models"
6767 # Security: Add timeout to prevent hanging connections
68- r = requests .get (url , headers = copilot_headers (copilot_token ), timeout = 30 )
68+
69+ # Determine if SSL verification should be enabled
70+ # For internal/private IPs, skip verification as they often use self-signed certificates
71+ import ipaddress
72+ from urllib .parse import urlparse
73+
74+ verify_ssl = True
75+ try :
76+ parsed = urlparse (base_url )
77+ if parsed .hostname :
78+ try :
79+ ip = ipaddress .ip_address (parsed .hostname )
80+ # Skip verification for private IPs (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8)
81+ if ip .is_private or ip .is_loopback :
82+ verify_ssl = False
83+ except ValueError :
84+ # Not an IP address, keep verification enabled
85+ pass
86+ except Exception :
87+ # If parsing fails, keep verification enabled
88+ pass
89+
90+ # Check if we're using a configured endpoint with API key authentication
91+ # (instead of direct GitHub Copilot API access)
92+ api_key = os .environ .get ("api_key" )
93+ if api_key :
94+ # Use OpenAI-compatible API key authentication for proxy endpoints
95+ headers = {
96+ "Authorization" : f"Bearer { api_key } " ,
97+ "Content-Type" : "application/json" ,
98+ }
99+ else :
100+ # Use GitHub Copilot token authentication for direct API access
101+ headers = copilot_headers (copilot_token )
102+
103+ # Make the request
104+ r = requests .get (url , headers = headers , timeout = 30 , verify = verify_ssl )
69105 r .raise_for_status ()
70106 return r .json ()
71107
@@ -111,8 +147,21 @@ def list_models():
111147 copilot_token = info ["token" ]
112148 state ["copilot_token" ] = copilot_token
113149
150+ # Get base URL from environment (set by EndpointManager) or from config
151+ base_url = os .environ .get ("endpoint" )
152+ if not base_url :
153+ # Try to get from config
154+ try :
155+ from .config import ConfigManager
156+ config = ConfigManager ()
157+ copilot_config = config .get_endpoint_config ("copilot-api" )
158+ base_url = copilot_config .get ("endpoint" , "https://192.168.1.100:5000" )
159+ except Exception as e :
160+ logger .debug (f"Could not load config, using default URL: { e } " )
161+ base_url = "https://192.168.1.100:5000"
162+
114163 logger .debug ("Fetching Copilot models" )
115- models = fetch_models (copilot_token )
164+ models = fetch_models (copilot_token , base_url )
116165 model_count = len (models .get ("data" , []))
117166 logger .debug (f"Found { model_count } models" )
118167
0 commit comments