mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-26 09:57:24 +03:00
Fix permissions for chromedriver
Fix NoVNC server access Remove java from build
This commit is contained in:
parent
c617b18d12
commit
e0aaad8f47
@ -1,18 +1,22 @@
|
||||
FROM selenium/node-chrome
|
||||
|
||||
ARG G4F_VERSION
|
||||
ARG G4F_USER=g4f
|
||||
ARG G4F_USER_ID=1000
|
||||
ARG G4F_NO_GUI
|
||||
ARG G4F_PASS=secret
|
||||
|
||||
ENV G4F_VERSION $G4F_VERSION
|
||||
ENV G4F_USER $G4F_USER
|
||||
ENV G4F_USER_ID $G4F_USER_ID
|
||||
ENV G4F_NO_GUI $G4F_NO_GUI
|
||||
|
||||
ENV SE_SCREEN_WIDTH 1850
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV G4F_DIR /app
|
||||
ENV G4F_LOGIN_URL http://localhost:7900/?autoconnect=1&resize=scale&password=secret
|
||||
ARG G4F_VERSION
|
||||
ENV G4F_VERSION ${G4F_VERSION}
|
||||
ARG G4F_USER
|
||||
ENV G4F_USER ${G4F_USER:-g4f}
|
||||
ARG G4F_USER_ID
|
||||
ENV G4F_USER_ID ${G4F_USER_ID:-1000}
|
||||
ARG G4F_NO_GUI
|
||||
ENV G4F_NO_GUI $G4F_NO_GUI
|
||||
ENV G4F_LOGIN_URL http://localhost:7900/?autoconnect=1&resize=scale&password=$G4F_PASS
|
||||
ENV HOME /home/$G4F_USER
|
||||
ENV PATH $PATH:$HOME/.local/bin
|
||||
ENV SE_DOWNLOAD_DIR $HOME/Downloads
|
||||
ENV SEL_USER $G4F_USER
|
||||
ENV SEL_UID $G4F_USER_ID
|
||||
@ -33,6 +37,9 @@ RUN apt-get -qqy update \
|
||||
python-is-python3 \
|
||||
pip
|
||||
|
||||
# Remove java
|
||||
RUN apt-get -qyy remove openjdk-11-jre-headless
|
||||
|
||||
# Cleanup
|
||||
RUN rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
|
||||
&& apt-get -qyy autoremove \
|
||||
@ -51,16 +58,22 @@ RUN if [ "$G4F_NO_GUI" ] ; then \
|
||||
COPY docker/background.png /usr/share/images/fluxbox/ubuntu-light.png
|
||||
|
||||
# Add user
|
||||
RUN groupadd -g $G4F_USER_ID $G4F_USER
|
||||
RUN useradd -rm -G sudo -u $G4F_USER_ID -g $G4F_USER_ID $G4F_USER
|
||||
RUN groupadd -g $G4F_USER_ID $G4F_USER \
|
||||
&& useradd -rm -G sudo -u $G4F_USER_ID -g $G4F_USER_ID $G4F_USER \
|
||||
&& echo "${G4F_USER}:${G4F_PASS}" | chpasswd
|
||||
|
||||
# Fix permissions
|
||||
RUN mkdir "${SE_DOWNLOAD_DIR}"
|
||||
RUN chown "${G4F_USER_ID}:${G4F_USER_ID}" $SE_DOWNLOAD_DIR /var/run/supervisor /var/log/supervisor
|
||||
RUN chown "${G4F_USER_ID}:${G4F_USER_ID}" -R /opt/bin/ /usr/bin/chromedriver /opt/selenium/
|
||||
|
||||
# Switch user
|
||||
USER $G4F_USER_ID
|
||||
|
||||
# Set VNC password
|
||||
RUN mkdir -p ${HOME}/.vnc \
|
||||
&& x11vnc -storepasswd ${G4F_PASS} ${HOME}/.vnc/passwd
|
||||
|
||||
# Set the working directory in the container.
|
||||
WORKDIR $G4F_DIR
|
||||
|
||||
|
@ -4,24 +4,22 @@ from colorama import Fore, Style
|
||||
|
||||
sys.path.append(str(Path(__file__).parent.parent))
|
||||
|
||||
from g4f import BaseProvider, models, Provider
|
||||
|
||||
logging = False
|
||||
from g4f import Provider, ProviderType, models
|
||||
from g4f.Provider import __providers__
|
||||
|
||||
|
||||
def main():
|
||||
providers = get_providers()
|
||||
failed_providers = []
|
||||
|
||||
for _provider in providers:
|
||||
if _provider.needs_auth:
|
||||
for provider in providers:
|
||||
if provider.needs_auth:
|
||||
continue
|
||||
print("Provider:", _provider.__name__)
|
||||
result = test(_provider)
|
||||
print("Provider:", provider.__name__)
|
||||
result = test(provider)
|
||||
print("Result:", result)
|
||||
if _provider.working and not result:
|
||||
failed_providers.append(_provider)
|
||||
|
||||
if provider.working and not result:
|
||||
failed_providers.append(provider)
|
||||
print()
|
||||
|
||||
if failed_providers:
|
||||
@ -32,38 +30,29 @@ def main():
|
||||
print(f"{Fore.GREEN + Style.BRIGHT}All providers are working")
|
||||
|
||||
|
||||
def get_providers() -> list[type[BaseProvider]]:
|
||||
providers = dir(Provider)
|
||||
providers = [getattr(Provider, provider) for provider in providers if provider != "RetryProvider"]
|
||||
providers = [provider for provider in providers if isinstance(provider, type) and hasattr(provider, "url")]
|
||||
def get_providers() -> list[ProviderType]:
|
||||
return [
|
||||
provider
|
||||
for provider in providers
|
||||
if issubclass(provider, BaseProvider)
|
||||
and provider.__name__ not in dir(Provider.deprecated)
|
||||
for provider in __providers__
|
||||
if provider.__name__ not in dir(Provider.deprecated)
|
||||
and provider.__name__ not in dir(Provider.unfinished)
|
||||
]
|
||||
|
||||
|
||||
def create_response(_provider: type[BaseProvider]) -> str:
|
||||
model = models.gpt_35_turbo.name if _provider.supports_gpt_35_turbo else models.default.name
|
||||
response = _provider.create_completion(
|
||||
model=model,
|
||||
def create_response(provider: ProviderType) -> str:
|
||||
response = provider.create_completion(
|
||||
model=models.default.name,
|
||||
messages=[{"role": "user", "content": "Hello, who are you? Answer in detail much as possible."}],
|
||||
stream=False,
|
||||
)
|
||||
return "".join(response)
|
||||
|
||||
|
||||
def test(_provider: type[BaseProvider]) -> bool:
|
||||
def test(provider: ProviderType) -> bool:
|
||||
try:
|
||||
response = create_response(_provider)
|
||||
response = create_response(provider)
|
||||
assert type(response) is str
|
||||
assert len(response) > 0
|
||||
return response
|
||||
except Exception as e:
|
||||
if logging:
|
||||
print(e)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
|
@ -128,7 +128,7 @@ class Completion:
|
||||
|
||||
return result if stream else ''.join(result)
|
||||
|
||||
def get_last_provider(as_dict: bool = False) -> ProviderType:
|
||||
def get_last_provider(as_dict: bool = False) -> Union[ProviderType, dict[str, str]]:
|
||||
last = debug.last_provider
|
||||
if isinstance(last, BaseRetryProvider):
|
||||
last = last.last_provider
|
||||
|
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import g4f
|
||||
from g4f.Provider import __providers__
|
||||
|
||||
@ -94,10 +95,10 @@ class Backend_Api:
|
||||
}) + "\n"
|
||||
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
yield json.dumps({
|
||||
'type' : 'error',
|
||||
'error': f'{e.__class__.__name__}: {e}'
|
||||
})
|
||||
raise e
|
||||
|
||||
return self.app.response_class(try_response(), mimetype='text/event-stream')
|
Loading…
Reference in New Issue
Block a user