├── .gitignore
├── License
├── README.md
├── main.py
├── requirements.txt
├── screenshot.png
├── temp.py
├── tempCodeRunnerFile.py
└── templates
└── index.html
/.gitignore:
--------------------------------------------------------------------------------
1 | env
2 | .env
--------------------------------------------------------------------------------
/License:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Param
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | ...
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Chat Bot with OpenAI API and Flask
2 |
3 | Introducing the Flask Chat Bot powered by the OpenAI API! This innovative chat bot combines the flexibility and ease of use of Flask with the power of the OpenAI API to deliver intelligent and interactive conversations. With natural language processing capabilities, the chat bot can understand user queries and provide relevant responses in real time. Whether it's customer support, information retrieval, or just casual conversation, our chat bot is ready to engage and assist users with its advanced AI capabilities. Get ready for an immersive and dynamic chat experience like never before!
4 |
5 |
6 |
7 |
8 | ## Prerequisites
9 |
10 | - Python 3.9 or higher
11 | - Flask
12 | - Langchain
13 | - OpenAI API
14 | - OpenAI Python library
15 |
16 | ## Getting Started
17 |
18 | 1. Clone the repository:
19 |
20 | ```bash
21 | git clone https://github.com/paramsgit/autochat-bot
22 |
23 | 2 Navigate to the project directory:
24 |
25 | cd autochat-bot
26 |
27 | 3 Install the required dependencies using pip:
28 |
29 | pip install -r requirements.txt
30 |
31 | 4 Set up OpenAI API:
32 |
33 | - Create an OpenAI account and obtain an API key.
34 | - Set the OPENAI_API_KEY environment variable with your API key
35 |
36 | On Windows:
37 | - Use the search bar in the Start menu to find “Edit the system environment variables”.
38 | - Click “Environment variables”
39 | - Use the upper “New…” button to add a User variable
40 | - Create a new variable called OPENAI_API_KEY and set the value to the secret key you got from your account settings on openai.com
41 |
42 | For Mac or Linux:
43 | - Find the .bashrc, .bash_profile, or .zshrc in your home directory
44 | - Open the file in a text editor
45 | - Add a new line to the file:
46 | ``export OPENAI_API_KEY= [your secret key]``
47 |
48 | 5 Run the application:
49 |
50 | python app.py
51 |
52 | 6 Open your web browser and visit http://127.0.0.1:{port}/ to access the chat bot.
53 |
54 |
55 |
56 | ## Usage
57 | Once the application is running, you can interact with the chat bot through the web interface. Type your messages in the input box, and the bot will respond accordingly.
58 |
59 | ## Deployment
60 | To deploy the chat bot to a production environment, follow the deployment instructions provided by the Flask documentation. It's recommended to use a production-ready WSGI server, such as Gunicorn or uWSGI.
61 |
62 | ## License
63 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
64 |
65 | ## Contributing
66 | Contributions are welcome! If you find any issues or have suggestions for improvements, please create a GitHub issue or submit a pull request.
67 |
68 | Feel free to modify and expand upon this template according to your specific project needs.
69 |
70 |
71 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template,jsonify,request
2 | from flask_cors import CORS
3 | import requests,openai,os
4 | from dotenv.main import load_dotenv
5 | from langchain.llms import OpenAI
6 | from langchain.memory import ConversationBufferMemory
7 | from langchain.chains import ConversationChain
8 | from langchain.memory import ConversationSummaryBufferMemory
9 | llm = OpenAI()
10 | memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=100)
11 | app = Flask(__name__)
12 | CORS(app)
13 |
14 | @app.route('/')
15 | def index():
16 | return render_template('index.html')
17 |
18 | @app.route('/data', methods=['POST'])
19 | def get_data():
20 | data = request.get_json()
21 | text=data.get('data')
22 | user_input = text
23 | try:
24 | conversation = ConversationChain(llm=llm,memory=memory)
25 | output = conversation.predict(input=user_input)
26 | memory.save_context({"input": user_input}, {"output": output})
27 | return jsonify({"response":True,"message":output})
28 | except Exception as e:
29 | print(e)
30 | error_message = f'Error: {str(e)}'
31 | return jsonify({"message":error_message,"response":False})
32 |
33 | if __name__ == '__main__':
34 | app.run()
35 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | aiohttp==3.8.4
2 | aiosignal==1.3.1
3 | annotated-types==0.5.0
4 | async-timeout==4.0.2
5 | attrs==23.1.0
6 | blinker==1.6.2
7 | certifi==2023.5.7
8 | charset-normalizer==3.1.0
9 | click==8.1.3
10 | colorama==0.4.6
11 | dataclasses-json==0.5.14
12 | Flask==2.3.2
13 | Flask-Cors==3.0.10
14 | frozenlist==1.3.3
15 | greenlet==2.0.2
16 | idna==3.4
17 | importlib-metadata==6.6.0
18 | itsdangerous==2.1.2
19 | Jinja2==3.1.2
20 | langchain==0.0.273
21 | langsmith==0.0.26
22 | MarkupSafe==2.1.2
23 | marshmallow==3.20.1
24 | multidict==6.0.4
25 | mypy-extensions==1.0.0
26 | numexpr==2.8.5
27 | numpy==1.25.2
28 | openai==0.27.6
29 | packaging==23.1
30 | pydantic==2.3.0
31 | pydantic_core==2.6.3
32 | python-dotenv==1.0.0
33 | PyYAML==6.0.1
34 | regex==2023.8.8
35 | requests==2.30.0
36 | six==1.16.0
37 | SQLAlchemy==2.0.20
38 | tenacity==8.2.3
39 | tiktoken==0.5.1
40 | tqdm==4.65.0
41 | typing-inspect==0.9.0
42 | typing_extensions==4.7.1
43 | urllib3==2.0.2
44 | Werkzeug==2.3.4
45 | yarl==1.9.2
46 | zipp==3.15.0
47 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paramsgit/autochat-bot/a31d5bef3fc913e391dbfb700dfa31957d593872/screenshot.png
--------------------------------------------------------------------------------
/temp.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template,jsonify,request
2 | from flask_cors import CORS
3 | import requests,openai,os
4 | from dotenv.main import load_dotenv
5 | from langchain.llms import OpenAI
6 | from langchain.memory import ConversationBufferMemory
7 | from langchain.chains import ConversationChain
8 | from langchain.memory import ConversationSummaryBufferMemory
9 | llm = OpenAI()
10 | memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=100)
11 | app = Flask(__name__)
12 | CORS(app)
13 |
14 | @app.route('/')
15 | def index():
16 | return render_template('index.html')
17 |
18 | @app.route('/data', methods=['POST'])
19 | def get_data():
20 | data = request.get_json()
21 | text=data.get('data')
22 | user_input = text
23 | print(user_input)
24 | try:
25 | print("Function started : ")
26 | conversation = ConversationChain(llm=llm,memory=memory,verbose=True)
27 | var1 = conversation.predict(input=user_input)
28 | memory.save_context({"input": user_input}, {"output": var1})
29 | return jsonify({"response":True,"message":var1})
30 | except Exception as e:
31 | print(e)
32 | error_message = f'Error: {str(e)}'
33 | return jsonify({"message":error_message,"response":False})
34 |
35 | if __name__ == '__main__':
36 | app.run()
37 |
--------------------------------------------------------------------------------
/tempCodeRunnerFile.py:
--------------------------------------------------------------------------------
1 | user_input
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |