Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Langchain #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM python:3.11-slim

WORKDIR /opt/app

COPY ./requirements.txt /opt/app/requirements.txt
Expand All @@ -8,4 +7,5 @@ RUN pip install -r requirements.txt

COPY . .

CMD ["exec gunicorn main:app"]
EXPOSE 80
CMD ["gunicorn", "-b", "0.0.0.0:80", "main:app"]
14 changes: 9 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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("/<path:any_path>")
Expand Down
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Flask
gunicorn
langchain
openai
python-dotenv
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