From f1cf658de68aac59795fa0dbc61d179ffc9d20cc Mon Sep 17 00:00:00 2001 From: aboutphilippe Date: Wed, 26 Jun 2024 11:53:27 +0200 Subject: [PATCH 1/3] Update requirements.txt --- requirements.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 From 87994ac94667d797f80c2dc10bfec9f5e1a12eae Mon Sep 17 00:00:00 2001 From: aboutphilippe Date: Wed, 26 Jun 2024 11:54:01 +0200 Subject: [PATCH 2/3] dotn fail when no openai key --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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("/") From 05139021df62dfde2aea00b05770bacb9e54f96c Mon Sep 17 00:00:00 2001 From: aboutphilippe Date: Wed, 26 Jun 2024 11:54:25 +0200 Subject: [PATCH 3/3] expose app --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"]