flowchart TD
%% μμ
A[μ¬μ©μ] -->|HTTP POST μμ²| B[/chat μλν¬μΈνΈ/]
%% μμ² μ²λ¦¬
B --> C[μμ² λ³Έλ¬Έ νμ±]
C --> D{μ ν¨μ± κ²μ¬}
D -->|μ ν¨| E[λ©μμ§ μΆμΆ]
D -->|μ ν¨νμ§ μμ| F[400 μ€λ₯ λ°ν]
%% μμ€ν
λ©μμ§ μΆκ°
E --> G{μμ€ν
λ©μμ§ ν¬ν¨ μ¬λΆ νμΈ}
G -->|ν¬ν¨λ¨| H[μ¬μ©μ μ
λ ₯ μΆμΆ]
G -->|ν¬ν¨λμ§ μμ| I[μμ€ν
λ©μμ§ μΆκ°]
I --> H
%% μ¬μ©μ μ
λ ₯ μ²λ¦¬
H --> J{μ
λ ₯ λ΄μ© νμΈ}
J -->|λΉμ΄ μμ| K[400 μ€λ₯ λ°ν]
J -->|μ ν¨| L[μ¬μ©μ μ
λ ₯ λ‘κ·Έ κΈ°λ‘]
%% OpenAI API νΈμΆ
L --> M[OpenAI API νΈμΆ]
M --> N{API μλ΅ νμΈ}
N -->|μ±κ³΅| O[μλ΅ λ΄μ© μΆμΆ λ° λ‘κ·Έ κΈ°λ‘]
N -->|μ€ν¨| P[500 μ€λ₯ λ°ν]
%% μλ΅ λ°ν
O --> Q[μλ΅ λ°ν]
Q --> A
%% λ‘κ·Έ μλν¬μΈνΈ
A -->|GET /logs μμ²| R[/logs μλν¬μΈνΈ/]
R --> S[λ‘κ·Έ νμΌ μ½κΈ°]
S --> T[μ΅κ·Ό 1000μ λ°ν]
T --> A
%% μλ¬ μ²λ¦¬
F --> U[400 Bad Request]
K --> U
P --> V[500 Internal Server Error]
PLKIT-AI.chat is a chatbot application that emulates a Smart Farm Expert. Built on FastAPI, this application leverages OpenAI's GPT-4 API to facilitate natural and engaging conversations with users. By setting up user personas, the chatbot provides professional responses tailored to specific fields. Additionally, it manages conversation logs for future analysis and monitoring. Designed for seamless deployment, PLKIT-AI.chat can be easily hosted on cloud services such as AWS EC2.
PLKIT-AI.chat/
βββ app.py # FastAPI application main file
βββ set_persona.py # User persona setup and chatbot logic
βββ set_connection.py # OpenAI API key configuration
βββ requirements.txt # Project dependencies list
βββ chatbot.log # Application log file
βββ README.md # Project documentation
βββ config.conf # configuration file
βββ .gitignore # Git ignore file
- User Persona Setup: Define user personas with specific roles and backgrounds to ensure consistent and relevant conversation experiences.
- OpenAI GPT-4 Integration: Utilize the latest AI models to generate natural and contextually appropriate responses.
- Log Management: Save conversation logs to files for subsequent analysis and monitoring.
- FastAPI-based API: Provide a RESTful API that supports communication with various clients.
- AWS Deployment Support: Facilitate easy deployment on AWS EC2 and other AWS services with provided configurations.
`## Getting Started
This section outlines how to set up and run the project locally.
The project relies on the following major dependencies:
- Python 3.9 or higher
- FastAPI
- Uvicorn
- OpenAI
- Pydantic
- Git
-
Clone the Repository
git clone https://github.com/yasaenghwa/PLKIT-AI.chat.git cd PLKIT-AI.chat`
-
Set Up a Python Virtual Environment
python3 -m venv venv
source venv/bin/activate # For Windows: venv\Scripts\activate
-
Install Dependencies
pip install --upgrade pip
pip install -r requirements.txt
-
Set Up Environment Variables Configure the OpenAI API key as an environment variable. It is recommended to use a
.env
file for security.export OPENAI_API_KEY='your-openai-api-key' # For Unix/Linux set OPENAI_API_KEY='your-openai-api-key' # For Windows
Alternatively, create a
.env
file in the project root:OPENAI_API_KEY=your-openai-api-key
-
Run the Application
uvicorn app:app --host 0.0.0.0 --port 8000
Access the API documentation by navigating to
http://localhost:8000/docs
in your browser.
OPENAI_API_KEY
: Set your OpenAI API key to enable GPT-4 integration. This key is essential for accessing OpenAI's services.
app.py
: The main FastAPI application file that defines endpoints and application settings.set_persona.py
: Defines user personas and handles the chatbot's response logic.set_connection.py
: Contains functions to retrieve and manage the OpenAI API key.requirements.txt
: Lists all Python packages required for the project.Dockerfile
: Configuration file for building the Docker image of the application.chatbot.log
: Log file where the application's runtime logs are stored.README.md
: Documentation file for the project..gitignore
: Specifies files and directories that Git should ignore.
Contributions are welcome! Please follow these guidelines to contribute to the project:
-
Fork the Repository
Create a personal copy of the repository by forking it.
-
Create a Feature Branch
git checkout -b feature/your-feature-name
-
Commit Your Changes
git commit -m "Add your message here"
-
Push to the Branch
git push origin feature/your-feature-name
-
Create a Pull Request
- Code Style: Adhere to PEP 8 standards for Python code.
- Testing: Include tests for new features or bug fixes.
- Documentation: Update documentation to reflect changes made in your contributions.
This project is licensed under the MIT License.
Β© 2024 PLKIT-AI.chat. All rights reserved.