Skip to content

Commit

Permalink
Remove dependency on requests library
Browse files Browse the repository at this point in the history
  • Loading branch information
luo-anthony committed Nov 30, 2023
1 parent 226a6b5 commit 505f3d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
6 changes: 0 additions & 6 deletions developergpt/huggingface_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
from typing import Optional

import requests
from rich.console import Console
from rich.live import Live
from rich.markdown import Markdown
Expand Down Expand Up @@ -112,11 +111,6 @@ def model_command(
f"[bold red]Hugging Face Inference API returned a bad request. {e}[/bold red]"
)
sys.exit(-1)
except requests.exceptions.ReadTimeout:
console.print(
"[bold red]Hugging Face Inference API request timed out. Try again later.[/bold red]"
)
sys.exit(-1)

# clean up
output_text = output_text.strip()
Expand Down
11 changes: 7 additions & 4 deletions developergpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import json
import os
import socket
import sys
from typing import Optional

import pyperclip
import requests
import tiktoken
from prompt_toolkit import PromptSession
from prompt_toolkit.completion import Completer, Completion
Expand Down Expand Up @@ -250,9 +250,12 @@ def get_completions(self, document, complete_event):
)


def check_connectivity(url: str = "http://www.google.com", timeout: int = 8) -> bool:
def check_connectivity(host: str = "8.8.8.8", port: int = 53, timeout: int = 8) -> bool:
"""
Check internet connection by trying to connect to Google's DNS server.
"""
try:
_ = requests.get(url, timeout=timeout)
socket.create_connection((host, port), timeout=timeout)
return True
except requests.ConnectionError:
except OSError:
return False
3 changes: 1 addition & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ pytest-cov
mypy
gitchangelog
mkdocs
autopep8
types-requests
autopep8
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ tiktoken
rich
inquirer
prompt_toolkit
pyperclip
requests
pyperclip

0 comments on commit 505f3d7

Please sign in to comment.