OpenHands/tests/integration/start_http_server.py
tobitege bc31fb15fe
(fix) CodeActAgent: fix issues with vision support in prompts (#3665)
* CodeActAgent: fix message prep if prompt caching is not supported

* fix python version in regen tests workflow

* fix in conftest "mock_completion" method

* add disable_vision to LLMConfig; revert change in message parsing in llm.py

* format messages in several files for completion

* refactored message(s) formatting (llm.py); added vision_is_active()

* fix a unit test

* regenerate: added LOG_TO_FILE and FORCE_REGENERATE env flags

* try to fix path to logs folder in workflow

* llm: prevent index error

* try FORCE_USE_LLM in regenerate

* tweaks everywhere...

* fix 2 random unit test errors :(

* added FORCE_REGENERATE_TESTS=true to regenerate CLI

* fix test_lint_file_fail_typescript again

* double-quotes for env vars in workflow; llm logger set to debug

* fix typo in regenerate

* regenerate iterations now 20; applied iteration counter fix by Li

* regenerate: pass FORCE_REGENERATE flag into env

* fixes for int tests. several mock files updated.

* browsing_agent: fix response_parser.py adding ) to empty response

* test_browse_internet: fix skipif and revert obsolete mock files

* regenerate: fi bracketing for http server start/kill conditions

* disable test_browse_internet for CodeAct*Agents; mock files updated after merge

* missed to include more mock files earlier

* reverts after review feedback from Li

* forgot one

* browsing agent test, partial fixes and updated mock files

* test_browse_internet works in my WSL now!

* adapt unit test test_prompt_caching.py

* add DEBUG to regenerate workflow command

* convert regenerate workflow params to inputs

* more integration test mock files updated

* more files

* test_prompt_caching: restored test_prompt_caching_headers purpose

* file_ops: fix potential exception, like "cross device copy"; fixed mock files accordingly

* reverts/changes wrt feedback from xingyao

* updated docs and config template

* code cleanup wrt review feedback
2024-09-04 17:58:30 +02:00

39 lines
1.2 KiB
Python

import os
import socket
from http.server import HTTPServer, SimpleHTTPRequestHandler
root_dir = os.path.join(os.path.dirname((os.path.dirname(__file__))))
web_dir = os.path.join(os.path.dirname(__file__), 'static')
os.chdir(web_dir)
class MultiAddressServer(HTTPServer):
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
class LoggingHTTPRequestHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
try:
# try to prevent exception in internal getcwd()
os.chdir(root_dir)
os.chdir(web_dir)
super().__init__(*args, **kwargs)
except FileNotFoundError:
print(f"Error: Directory '{web_dir}' not found.")
raise
def log_message(self, format, *args):
print(
f'Request received: {self.address_string()} - {self.log_date_time_string()} - {format % args}'
)
handler = LoggingHTTPRequestHandler
# Start the server
server = MultiAddressServer(('', 8000), handler)
print('Server running on http://localhost:8000 and http://127.0.0.1:8000')
server.serve_forever()