parent
b08cd06a76
commit
41344a625e
@ -1,158 +1,158 @@
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
import pkg_resources
|
||||
import psutil
|
||||
import toml
|
||||
|
||||
|
||||
def get_python_version():
|
||||
return platform.python_version()
|
||||
|
||||
|
||||
def get_pip_version():
|
||||
try:
|
||||
pip_version = (
|
||||
subprocess.check_output(["pip", "--version"])
|
||||
.decode()
|
||||
.split()[1]
|
||||
)
|
||||
except Exception as e:
|
||||
pip_version = str(e)
|
||||
return pip_version
|
||||
|
||||
|
||||
def get_oi_version():
|
||||
try:
|
||||
oi_version_cmd = (
|
||||
subprocess.check_output(["interpreter", "--version"])
|
||||
.decode()
|
||||
.split()[1]
|
||||
)
|
||||
except Exception as e:
|
||||
oi_version_cmd = str(e)
|
||||
oi_version_pkg = pkg_resources.get_distribution(
|
||||
"open-interpreter"
|
||||
).version
|
||||
oi_version = oi_version_cmd, oi_version_pkg
|
||||
return oi_version
|
||||
|
||||
|
||||
def get_os_version():
|
||||
return platform.platform()
|
||||
|
||||
|
||||
def get_cpu_info():
|
||||
return platform.processor()
|
||||
|
||||
|
||||
def get_ram_info():
|
||||
vm = psutil.virtual_memory()
|
||||
used_ram_gb = vm.used / (1024**3)
|
||||
free_ram_gb = vm.free / (1024**3)
|
||||
total_ram_gb = vm.total / (1024**3)
|
||||
return (
|
||||
f"{total_ram_gb:.2f} GB, used: {used_ram_gb:.2f}, free:"
|
||||
f" {free_ram_gb:.2f}"
|
||||
)
|
||||
|
||||
|
||||
def get_package_mismatches(file_path="pyproject.toml"):
|
||||
with open(file_path, "r") as file:
|
||||
pyproject = toml.load(file)
|
||||
dependencies = pyproject["tool"]["poetry"]["dependencies"]
|
||||
dev_dependencies = pyproject["tool"]["poetry"]["group"]["dev"][
|
||||
"dependencies"
|
||||
]
|
||||
dependencies.update(dev_dependencies)
|
||||
|
||||
installed_packages = {
|
||||
pkg.key: pkg.version for pkg in pkg_resources.working_set
|
||||
}
|
||||
|
||||
mismatches = []
|
||||
for package, version_info in dependencies.items():
|
||||
if isinstance(version_info, dict):
|
||||
version_info = version_info["version"]
|
||||
installed_version = installed_packages.get(package)
|
||||
if installed_version and version_info.startswith("^"):
|
||||
expected_version = version_info[1:]
|
||||
if not installed_version.startswith(expected_version):
|
||||
mismatches.append(
|
||||
f"\t {package}: Mismatch,"
|
||||
f" pyproject.toml={expected_version},"
|
||||
f" pip={installed_version}"
|
||||
)
|
||||
else:
|
||||
mismatches.append(f"\t {package}: Not found in pip list")
|
||||
|
||||
return "\n" + "\n".join(mismatches)
|
||||
|
||||
|
||||
def interpreter_info(interpreter):
|
||||
try:
|
||||
if interpreter.offline and interpreter.llm.api_base:
|
||||
try:
|
||||
curl = subprocess.check_output(
|
||||
f"curl {interpreter.llm.api_base}"
|
||||
)
|
||||
except Exception as e:
|
||||
curl = str(e)
|
||||
else:
|
||||
curl = "Not local"
|
||||
|
||||
messages_to_display = []
|
||||
for message in interpreter.messages:
|
||||
message = message.copy()
|
||||
try:
|
||||
if len(message["content"]) > 600:
|
||||
message["content"] = (
|
||||
message["content"][:300]
|
||||
+ "..."
|
||||
+ message["content"][-300:]
|
||||
)
|
||||
except KeyError as e:
|
||||
print(f"KeyError {str(e)} for message: {message}")
|
||||
messages_to_display.append(message)
|
||||
|
||||
return f"""
|
||||
|
||||
# Interpreter Info
|
||||
# import platform
|
||||
# import subprocess
|
||||
|
||||
# import pkg_resources
|
||||
# import psutil
|
||||
# import toml
|
||||
|
||||
|
||||
# def get_python_version():
|
||||
# return platform.python_version()
|
||||
|
||||
|
||||
# def get_pip_version():
|
||||
# try:
|
||||
# pip_version = (
|
||||
# subprocess.check_output(["pip", "--version"])
|
||||
# .decode()
|
||||
# .split()[1]
|
||||
# )
|
||||
# except Exception as e:
|
||||
# pip_version = str(e)
|
||||
# return pip_version
|
||||
|
||||
|
||||
# def get_oi_version():
|
||||
# try:
|
||||
# oi_version_cmd = (
|
||||
# subprocess.check_output(["interpreter", "--version"])
|
||||
# .decode()
|
||||
# .split()[1]
|
||||
# )
|
||||
# except Exception as e:
|
||||
# oi_version_cmd = str(e)
|
||||
# oi_version_pkg = pkg_resources.get_distribution(
|
||||
# "open-interpreter"
|
||||
# ).version
|
||||
# oi_version = oi_version_cmd, oi_version_pkg
|
||||
# return oi_version
|
||||
|
||||
|
||||
# def get_os_version():
|
||||
# return platform.platform()
|
||||
|
||||
|
||||
# def get_cpu_info():
|
||||
# return platform.processor()
|
||||
|
||||
|
||||
# def get_ram_info():
|
||||
# vm = psutil.virtual_memory()
|
||||
# used_ram_gb = vm.used / (1024**3)
|
||||
# free_ram_gb = vm.free / (1024**3)
|
||||
# total_ram_gb = vm.total / (1024**3)
|
||||
# return (
|
||||
# f"{total_ram_gb:.2f} GB, used: {used_ram_gb:.2f}, free:"
|
||||
# f" {free_ram_gb:.2f}"
|
||||
# )
|
||||
|
||||
|
||||
# def get_package_mismatches(file_path="pyproject.toml"):
|
||||
# with open(file_path, "r") as file:
|
||||
# pyproject = toml.load(file)
|
||||
# dependencies = pyproject["tool"]["poetry"]["dependencies"]
|
||||
# dev_dependencies = pyproject["tool"]["poetry"]["group"]["dev"][
|
||||
# "dependencies"
|
||||
# ]
|
||||
# dependencies.update(dev_dependencies)
|
||||
|
||||
# installed_packages = {
|
||||
# pkg.key: pkg.version for pkg in pkg_resources.working_set
|
||||
# }
|
||||
|
||||
# mismatches = []
|
||||
# for package, version_info in dependencies.items():
|
||||
# if isinstance(version_info, dict):
|
||||
# version_info = version_info["version"]
|
||||
# installed_version = installed_packages.get(package)
|
||||
# if installed_version and version_info.startswith("^"):
|
||||
# expected_version = version_info[1:]
|
||||
# if not installed_version.startswith(expected_version):
|
||||
# mismatches.append(
|
||||
# f"\t {package}: Mismatch,"
|
||||
# f" pyproject.toml={expected_version},"
|
||||
# f" pip={installed_version}"
|
||||
# )
|
||||
# else:
|
||||
# mismatches.append(f"\t {package}: Not found in pip list")
|
||||
|
||||
# return "\n" + "\n".join(mismatches)
|
||||
|
||||
|
||||
# def interpreter_info(interpreter):
|
||||
# try:
|
||||
# if interpreter.offline and interpreter.llm.api_base:
|
||||
# try:
|
||||
# curl = subprocess.check_output(
|
||||
# f"curl {interpreter.llm.api_base}"
|
||||
# )
|
||||
# except Exception as e:
|
||||
# curl = str(e)
|
||||
# else:
|
||||
# curl = "Not local"
|
||||
|
||||
# messages_to_display = []
|
||||
# for message in interpreter.messages:
|
||||
# message = message.copy()
|
||||
# try:
|
||||
# if len(message["content"]) > 600:
|
||||
# message["content"] = (
|
||||
# message["content"][:300]
|
||||
# + "..."
|
||||
# + message["content"][-300:]
|
||||
# )
|
||||
# except KeyError as e:
|
||||
# print(f"KeyError {str(e)} for message: {message}")
|
||||
# messages_to_display.append(message)
|
||||
|
||||
# return f"""
|
||||
|
||||
# # Interpreter Info
|
||||
|
||||
Vision: {interpreter.llm.supports_vision}
|
||||
Model: {interpreter.llm.model}
|
||||
Function calling: {interpreter.llm.supports_functions}
|
||||
Context window: {interpreter.llm.context_window}
|
||||
Max tokens: {interpreter.llm.max_tokens}
|
||||
|
||||
Auto run: {interpreter.auto_run}
|
||||
API base: {interpreter.llm.api_base}
|
||||
Offline: {interpreter.offline}
|
||||
|
||||
Curl output: {curl}
|
||||
|
||||
# Messages
|
||||
|
||||
System Message: {interpreter.system_message}
|
||||
|
||||
""" + "\n\n".join([str(m) for m in messages_to_display])
|
||||
except AttributeError as e:
|
||||
return f"Error, couldn't get interpreter info: {str(e)}"
|
||||
|
||||
|
||||
def system_info(interpreter):
|
||||
oi_version = get_oi_version()
|
||||
print(f"""
|
||||
Python Version: {get_python_version()}
|
||||
Pip Version: {get_pip_version()}
|
||||
Open-interpreter Version: cmd:{oi_version[0]}, pkg: {oi_version[1]}
|
||||
OS Version and Architecture: {get_os_version()}
|
||||
CPU Info: {get_cpu_info()}
|
||||
RAM Info: {get_ram_info()}
|
||||
{interpreter_info(interpreter)}
|
||||
""")
|
||||
|
||||
# Removed the following, as it causes `FileNotFoundError: [Errno 2] No such file or directory: 'pyproject.toml'`` on prod
|
||||
# (i think it works on dev, but on prod the pyproject.toml will not be in the cwd. might not be accessible at all)
|
||||
# Package Version Mismatches:
|
||||
# {get_package_mismatches()}
|
||||
# Vision: {interpreter.llm.supports_vision}
|
||||
# Model: {interpreter.llm.model}
|
||||
# Function calling: {interpreter.llm.supports_functions}
|
||||
# Context window: {interpreter.llm.context_window}
|
||||
# Max tokens: {interpreter.llm.max_tokens}
|
||||
|
||||
# Auto run: {interpreter.auto_run}
|
||||
# API base: {interpreter.llm.api_base}
|
||||
# Offline: {interpreter.offline}
|
||||
|
||||
# Curl output: {curl}
|
||||
|
||||
# # Messages
|
||||
|
||||
# System Message: {interpreter.system_message}
|
||||
|
||||
# """ + "\n\n".join([str(m) for m in messages_to_display])
|
||||
# except AttributeError as e:
|
||||
# return f"Error, couldn't get interpreter info: {str(e)}"
|
||||
|
||||
|
||||
# def system_info(interpreter):
|
||||
# oi_version = get_oi_version()
|
||||
# print(f"""
|
||||
# Python Version: {get_python_version()}
|
||||
# Pip Version: {get_pip_version()}
|
||||
# Open-interpreter Version: cmd:{oi_version[0]}, pkg: {oi_version[1]}
|
||||
# OS Version and Architecture: {get_os_version()}
|
||||
# CPU Info: {get_cpu_info()}
|
||||
# RAM Info: {get_ram_info()}
|
||||
# {interpreter_info(interpreter)}
|
||||
# """)
|
||||
|
||||
# # Removed the following, as it causes `FileNotFoundError: [Errno 2] No such file or directory: 'pyproject.toml'`` on prod
|
||||
# # (i think it works on dev, but on prod the pyproject.toml will not be in the cwd. might not be accessible at all)
|
||||
# # Package Version Mismatches:
|
||||
# # {get_package_mismatches()}
|
||||
|
@ -1,37 +1,37 @@
|
||||
"""Tests for the sys_info module."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import Mock
|
||||
from sys_info import interpreter_info, system_info
|
||||
# import pytest
|
||||
# from unittest.mock import Mock
|
||||
# from sys_info import interpreter_info, system_info
|
||||
|
||||
def test_interpreter_info(mocker):
|
||||
"""Test interpreter_info."""
|
||||
mocker.patch('subprocess.check_output', return_value='curl output')
|
||||
interpreter = Mock()
|
||||
interpreter.offline = True
|
||||
interpreter.llm.api_base = 'http://api_base'
|
||||
interpreter.llm.supports_vision = True
|
||||
interpreter.llm.model = 'model'
|
||||
interpreter.llm.supports_functions = True
|
||||
interpreter.llm.context_window = 'context_window'
|
||||
interpreter.llm.max_tokens = 100
|
||||
interpreter.auto_run = True
|
||||
interpreter.llm.api_base = 'http://api_base'
|
||||
interpreter.offline = True
|
||||
interpreter.system_message = 'system_message'
|
||||
interpreter.messages = [{'content': 'message_content'}]
|
||||
result = interpreter_info(interpreter)
|
||||
assert 'curl output' in result
|
||||
# def test_interpreter_info(mocker):
|
||||
# """Test interpreter_info."""
|
||||
# mocker.patch('subprocess.check_output', return_value='curl output')
|
||||
# interpreter = Mock()
|
||||
# interpreter.offline = True
|
||||
# interpreter.llm.api_base = 'http://api_base'
|
||||
# interpreter.llm.supports_vision = True
|
||||
# interpreter.llm.model = 'model'
|
||||
# interpreter.llm.supports_functions = True
|
||||
# interpreter.llm.context_window = 'context_window'
|
||||
# interpreter.llm.max_tokens = 100
|
||||
# interpreter.auto_run = True
|
||||
# interpreter.llm.api_base = 'http://api_base'
|
||||
# interpreter.offline = True
|
||||
# interpreter.system_message = 'system_message'
|
||||
# interpreter.messages = [{'content': 'message_content'}]
|
||||
# result = interpreter_info(interpreter)
|
||||
# assert 'curl output' in result
|
||||
|
||||
def test_system_info(mocker):
|
||||
"""Test system_info."""
|
||||
mocker.patch('your_module.get_oi_version', return_value=('cmd_version', 'pkg_version')) # replace with your actual module name
|
||||
mocker.patch('your_module.get_python_version', return_value='python_version') # replace with your actual module name
|
||||
mocker.patch('your_module.get_pip_version', return_value='pip_version') # replace with your actual module name
|
||||
mocker.patch('your_module.get_os_version', return_value='os_version') # replace with your actual module name
|
||||
mocker.patch('your_module.get_cpu_info', return_value='cpu_info') # replace with your actual module name
|
||||
mocker.patch('your_module.get_ram_info', return_value='ram_info') # replace with your actual module name
|
||||
mocker.patch('your_module.interpreter_info', return_value='interpreter_info') # replace with your actual module name
|
||||
interpreter = Mock()
|
||||
result = system_info(interpreter)
|
||||
assert 'interpreter_info' in result
|
||||
# def test_system_info(mocker):
|
||||
# """Test system_info."""
|
||||
# mocker.patch('your_module.get_oi_version', return_value=('cmd_version', 'pkg_version')) # replace with your actual module name
|
||||
# mocker.patch('your_module.get_python_version', return_value='python_version') # replace with your actual module name
|
||||
# mocker.patch('your_module.get_pip_version', return_value='pip_version') # replace with your actual module name
|
||||
# mocker.patch('your_module.get_os_version', return_value='os_version') # replace with your actual module name
|
||||
# mocker.patch('your_module.get_cpu_info', return_value='cpu_info') # replace with your actual module name
|
||||
# mocker.patch('your_module.get_ram_info', return_value='ram_info') # replace with your actual module name
|
||||
# mocker.patch('your_module.interpreter_info', return_value='interpreter_info') # replace with your actual module name
|
||||
# interpreter = Mock()
|
||||
# result = system_info(interpreter)
|
||||
# assert 'interpreter_info' in result
|
Loading…
Reference in new issue