mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
feat: Add various HTTP Client settings
Options to load a TLS Client certificate. An option to set an authentication cookie. These are necessary for talking to certain configurations of backends.
This commit is contained in:
parent
c7e8d297a4
commit
4e100960d8
2 changed files with 44 additions and 5 deletions
|
@ -138,6 +138,21 @@ def get_parser(default_config_files, git_root):
|
||||||
default=True,
|
default=True,
|
||||||
help="Verify the SSL cert when connecting to models (default: True)",
|
help="Verify the SSL cert when connecting to models (default: True)",
|
||||||
)
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--client-cert",
|
||||||
|
type=str,
|
||||||
|
help="Specify the client certificate file for TLS connections",
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--client-cert-key",
|
||||||
|
type=str,
|
||||||
|
help="Specify the client certificate key file for TLS connections",
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--auth-cookie",
|
||||||
|
type=str,
|
||||||
|
help="A cookie that will be sent with all HTTP requests (e.g. for authentication)",
|
||||||
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--timeout",
|
"--timeout",
|
||||||
type=float,
|
type=float,
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from dataclasses import fields
|
from dataclasses import fields
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import httpx
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import git
|
import git
|
||||||
|
@ -498,16 +500,38 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
analytics = Analytics(permanently_disable=True)
|
analytics = Analytics(permanently_disable=True)
|
||||||
print("Analytics have been permanently disabled.")
|
print("Analytics have been permanently disabled.")
|
||||||
|
|
||||||
|
litellm._load_litellm()
|
||||||
|
http_client = httpx.Client()
|
||||||
|
async_client = httpx.AsyncClient()
|
||||||
|
|
||||||
if not args.verify_ssl:
|
if not args.verify_ssl:
|
||||||
import httpx
|
|
||||||
|
|
||||||
os.environ["SSL_VERIFY"] = ""
|
os.environ["SSL_VERIFY"] = ""
|
||||||
litellm._load_litellm()
|
http_client = httpx.Client(verify=False)
|
||||||
litellm._lazy_module.client_session = httpx.Client(verify=False)
|
async_client = httpx.AsyncClient(verify=False)
|
||||||
litellm._lazy_module.aclient_session = httpx.AsyncClient(verify=False)
|
|
||||||
# Set verify_ssl on the model_info_manager
|
# Set verify_ssl on the model_info_manager
|
||||||
models.model_info_manager.set_verify_ssl(False)
|
models.model_info_manager.set_verify_ssl(False)
|
||||||
|
|
||||||
|
if args.client_cert:
|
||||||
|
if not args.client_cert_key:
|
||||||
|
print("Expected both --client-cert and --client-cert-key.")
|
||||||
|
return False
|
||||||
|
context = ssl.create_default_context()
|
||||||
|
context.load_cert_chain(certfile=args.client_cert, keyfile=args.client_cert_key)
|
||||||
|
|
||||||
|
http_client = httpx.Client(verify=context)
|
||||||
|
async_client = httpx.AsyncClient(verify=context)
|
||||||
|
|
||||||
|
if args.auth_cookie:
|
||||||
|
try:
|
||||||
|
cookie_name, cookie_value = args.auth_cookie.split("=", 1)
|
||||||
|
http_client.cookies = httpx.Cookies({cookie_name: cookie_value})
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid format for --auth-cookie. Expected format: name=value")
|
||||||
|
return False
|
||||||
|
|
||||||
|
litellm._lazy_module.client_session = http_client
|
||||||
|
litellm._lazy_module.aclient_session = async_client
|
||||||
|
|
||||||
if args.timeout:
|
if args.timeout:
|
||||||
models.request_timeout = args.timeout
|
models.request_timeout = args.timeout
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue