Simatwa / python-tgpt

AI Chat in Terminal + Package + REST-API
https://python-tgpt.onrender.com
MIT License
102 stars 15 forks source link

ERROR : 'choices' #50

Closed hitesh22rana closed 3 months ago

hitesh22rana commented 3 months ago

I am working on a project which requires to run pytgpt inside a docker container, but I am getting this strange error:- ERROR : 'choices'

On doing exec inside the container, I am able to run pytgpt (indicates that is successfully installed), but on asking some question, I am getting the same error:- ERROR : 'choices'

Screenshot 2024-05-15 at 9 12 54 PM

It's running on my local environment, but won't work inside a docker container.

I am using Phind as LLM provider, example is given below:-

import pytgpt.phind as phind
llm = phind.PHIND()

try:
    data = llm.ask("Hello, how are you?") #getting the error here
    print(data)
    print(llm.get_message(data))

except Exception as e:
    print(e)

For reference, this is my Dockerfile

ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim as base

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1

# Install system-level dependencies
RUN apt-get update -y \
    && apt-get upgrade -y \
    && apt-get install -y --no-install-recommends gcc build-essential libpython3-dev libleptonica-dev tesseract-ocr libtesseract-dev python3-pil tesseract-ocr-eng tesseract-ocr-script-latn \
    && rm -rf /var/lib/apt/lists/*

# Create a non-privileged user that the app will run under.
ARG UID=10001
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/home/bot" \
    --shell "/sbin/nologin" \
    --uid "${UID}" \
    bot

# Create the home directory and set permissions
RUN chown bot:bot /home/bot

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements.txt to avoid having to copy them into
# into this layer.
RUN --mount=type=cache,target=/root/.cache/pip \
    --mount=type=bind,source=requirements.txt,target=requirements.txt \
    pip install --upgrade -r requirements.txt

# Switch to the non-privileged user and set the working directory
USER bot
WORKDIR /home/bot

# Copy the source code into the container.
COPY . .

# Run the application.
CMD ["python", "src/main.py"]

My requirements.txt

python-tgpt[all]
requests
Simatwa commented 3 months ago

Please be informed that some providers implement geo-restrictions. If your IP's location is from the affected region, you will definitely encounter such restrictions. As a workaround, apart from using proxies, you can also disable streaming when using the default provider, Auto. Unlike the others, this dynamic provider attempts to generate a response using every available provider.

$ pytgpt interactive -w 
hitesh22rana commented 3 months ago

The code is working perfectly fine if run directly(in local environment), the problem I am facing is after I run the application via docker(in local environment). So, I don't think it's due to some geo-restrictions.

hitesh22rana commented 3 months ago

Still the same, it's some other issue. I think there's some dependency that is by default available but, not available in the docker environment.

Screenshot 2024-05-22 at 1 13 18 PM