diff --git a/Dockerfile b/Dockerfile index 5634e57..bcc0f9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM python:3.11-slim - WORKDIR /opt/app COPY ./requirements.txt /opt/app/requirements.txt @@ -8,4 +7,5 @@ RUN pip install -r requirements.txt COPY . . -CMD ["exec gunicorn main:app"] \ No newline at end of file +EXPOSE 80 +CMD ["gunicorn", "-b", "0.0.0.0:80", "main:app"] diff --git a/main.py b/main.py index 25359e3..4ee0105 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ -from flask import Flask, abort, render_template -from langchain.llms import OpenAI +from flask import Flask, abort, render_template, jsonify +from langchain_openai import OpenAI from dotenv import load_dotenv load_dotenv() @@ -14,9 +14,13 @@ def main(): @app.route("/ask") def ask(): - llm = OpenAI(temperature=0.7) - text = "Tell me a joke about artificial intelligence." - return llm(text) + try: + llm = OpenAI(temperature=0.7) + text = "Tell me a joke about artificial intelligence." + response = llm(text) + return response + except Exception as e: + return jsonify(error=str(e)), 500 @app.route("/") diff --git a/requirements.txt b/requirements.txt index a48e5e4..e33c70c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -Flask -gunicorn -langchain -openai -python-dotenv \ No newline at end of file +Flask==3.0.3 +gunicorn==22.0.0 +langchain==0.2.6 +langchain-openai==0.1.10 +openai==1.35.3 +python-dotenv==1.0.1