-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create docker environment and Codespace for easy onborading (#35)
- Loading branch information
1 parent
eb7cbce
commit 40d66b8
Showing
12 changed files
with
175 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"dockerComposeFile": "../docker-compose.yaml", | ||
"service": "chromegpt", | ||
"workspaceFolder": "/app", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"ms-toolsai.jupyter" | ||
] | ||
} | ||
}, | ||
"forwardPorts": [3000,4444,7900,5900], | ||
"shutdownAction": "stopCompose" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
OPENAI_API_KEY=sk- | ||
REQUEST="Find me a bar that can host a 20 person event near Chelsea, Manhattan evening of Apr 30th. Fill out contact us form if they have one with info: Name Richard, email he@hrichard.com." | ||
TARGET=base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"." | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM python:3.8 as base | ||
|
||
WORKDIR /app | ||
|
||
# setup code | ||
COPY . . | ||
RUN pip install poetry==1.4.2 | ||
|
||
# Install dependencies using Poetry | ||
RUN poetry config virtualenvs.create false && \ | ||
poetry install --no-interaction --no-ansi | ||
|
||
CMD python -m chromegpt -v -t "${REQUEST}" | ||
|
||
# image to dev | ||
FROM base as dev | ||
CMD sh -c "while sleep 1000; do :; done" | ||
|
||
# image to run tests | ||
FROM base as test | ||
ARG MAKE="tests" | ||
CMD make $MAKE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import Any, Callable | ||
|
||
from chromegpt.tools.selenium import SeleniumWrapper | ||
|
||
|
||
def execute_with_driver(test_function: Callable[[SeleniumWrapper], None]) -> Callable: | ||
def wrapper(*args: Any, **kwargs: Any) -> None: | ||
try: | ||
client = SeleniumWrapper(headless=True) | ||
test_function(client, *args, **kwargs) | ||
finally: | ||
# release the driver | ||
del client | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: '3' | ||
services: | ||
chromegpt: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
target: ${TARGET:-dev} # Default value is "dev" | ||
args: | ||
- MAKE=${MAKE} | ||
environment: | ||
- OPENAI_API_KEY=${OPENAI_API_KEY} | ||
- REQUEST=${REQUEST} | ||
depends_on: | ||
# make sure the the image will be created only after Selenium is stable | ||
# otherwise, tests a run before Selenium is accessible | ||
selenium-chrome: | ||
condition: service_healthy | ||
|
||
|
||
selenium-chrome: | ||
image: selenium/standalone-chrome:latest | ||
ports: | ||
- "4444:4444" | ||
- "7900:7900" | ||
- "5900:5900" | ||
environment: | ||
- SE_NODE_MAX_SESSIONS=10 | ||
- SE_NODE_SESSION_TIMEOUT=30000 | ||
shm_size: "2g" | ||
# define Selenium stable 'Healthy' only after it's accessible. | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://selenium-chrome:4444/wd/hub/status"] | ||
interval: 10s # Check every 30 seconds | ||
timeout: 5s # Timeout after 10 seconds | ||
retries: 3 # Retry 3 times before considering the container unhealthy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,51 @@ | ||
"""Integration test for Selenium API Wrapper.""" | ||
|
||
import pytest | ||
|
||
from chromegpt.tools.selenium import SeleniumWrapper | ||
|
||
|
||
@pytest.fixture | ||
def client() -> SeleniumWrapper: | ||
return SeleniumWrapper(headless=True) | ||
from chromegpt.tools.driver import SeleniumWrapper, execute_with_driver | ||
|
||
|
||
@execute_with_driver | ||
def test_describe_website(client: SeleniumWrapper) -> None: | ||
"""Test that SeleniumWrapper returns correct website""" | ||
|
||
output = None | ||
output = client.describe_website("https://example.com") | ||
assert "this domain is for use in illu" in output | ||
assert output is not None and "this domain is for use in illu" in output | ||
|
||
|
||
@execute_with_driver | ||
def test_click(client: SeleniumWrapper) -> None: | ||
"""Test that SeleniumWrapper click works""" | ||
|
||
output = None | ||
client.describe_website("https://example.com") | ||
output = client.click_button_by_text('link with title "More information..."') | ||
assert "Clicked interactable element and the website changed" in output | ||
assert ( | ||
output is not None | ||
and "Clicked interactable element and the website changed" in output | ||
) | ||
|
||
|
||
@execute_with_driver | ||
def test_google_input(client: SeleniumWrapper) -> None: | ||
"""Test that SeleniumWrapper can find input form""" | ||
|
||
output = None | ||
output = client.find_form_inputs("https://google.com") | ||
assert "q" in output | ||
assert output is not None and "q" in output | ||
|
||
|
||
@execute_with_driver | ||
def test_google_fill(client: SeleniumWrapper) -> None: | ||
"""Test that SeleniumWrapper can fill input form""" | ||
|
||
output = None | ||
client.find_form_inputs("https://google.com") | ||
output = client.fill_out_form(q="hello world") | ||
assert "website changed after filling out form" in output | ||
|
||
assert output is not None and "website changed after filling out form" in output | ||
|
||
|
||
@execute_with_driver | ||
def test_google_search(client: SeleniumWrapper) -> None: | ||
"""Test google search functionality""" | ||
res = client.google_search("hello world") | ||
assert "hello" in res | ||
assert "Which url would you like to goto" in res | ||
output = None | ||
output = client.google_search("hello world") | ||
assert output is not None and "hello" in output | ||
assert output is not None and "Which url would you like to goto" in output |