This bot integrates ChatGPT with LINE messaging platform, allowing users to interact with ChatGPT through LINE messages.
The following diagram illustrates the architecture and data flow of the LineGPT application:
flowchart LR User(LINE User) <-->|Messages| LINE[LINE Platform] LINE <-->|Webhook Events| Server[LineGPT Server] Server -->|User Query| Process[Message Processing] Process -->|Command Handling| Commands{Commands} Process -->|Regular Message| Chat[Chat Processing] Commands -->|/chat| Chat Commands -->|/reset| Reset[Reset Conversation] Commands -->|/news| News[Financial News] Commands -->|/help| Help[Command List] Chat -->|API Request| OpenAI[OpenAI GPT API] OpenAI -->|AI Response| Chat News -->|API Request| FinAPI[Financial News API] FinAPI -->|News Data| News Chat -->|Format Response| Response[Format Response] News -->|Format News| Response Reset -->|Confirmation| Response Help -->|Command Info| Response Response -->|LINE Message| Server subgraph "Debug Endpoints" Debug[Debug Routes] Server -.->|Testing| Debug Debug -.->|Raw Message| LINE Debug -.->|Test Encoding| OpenAI end style User fill:#f9d71c,stroke:#333,stroke-width:2px style LINE fill:#00c300,stroke:#333,stroke-width:2px,color:#fff style Server fill:#5762d5,stroke:#333,stroke-width:2px,color:#fff style OpenAI fill:#74aa9c,stroke:#333,stroke-width:2px,color:#fff style FinAPI fill:#ff6b6b,stroke:#333,stroke-width:2px style Debug fill:#ff9e00,stroke:#333,stroke-width:2px
This diagram shows how user messages flow through the LINE platform to the LineGPT server, where they are processed based on command type, then routed to appropriate services (OpenAI API or Financial News API), and finally formatted and sent back to the user through LINE.
Here are some examples of how to test your LineGPT setup:
# Test sending a simple message to a user curl "http://localhost:5000/test_message?user_id=USER_ID_HERE&message=Hello from LineGPT!" # Test sending Chinese and other non-ASCII messages curl "http://localhost:5000/test_chinese?user_id=USER_ID_HERE" # Test sending a message to all registered users curl "http://localhost:5000/test_broadcast?message=Hello everyone from LineGPT!" # Test encoding with specific text curl "http://localhost:5000/test_encoding?user_id=USER_ID_HERE&text=ζ΅θ―δΈζζΆζ―"
Replace USER_ID_HERE
with your actual LINE user ID, which you can obtain from the /get_user_id
endpoint.
With LineGPT, you can ask GPT about virtually anything, including:
Simply start your message with a question or statement, or use the /chat
command followed by your query.
Here are some examples of how you can interact with GPT through LINE:
You: What is the capital of France?
GPT: The capital of France is Paris.
You: /chat Translate "Hello, how are you?" to Chinese
GPT: δ½ ε₯½οΌδ½ ε₯½εοΌ(NΗ hΗo, nΗ hΗo ma?)
You: /chat Write a Python function to calculate Fibonacci numbers
GPT: Here's a Python function to calculate Fibonacci numbers:
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
# More efficient version using dynamic programming
def fibonacci_efficient(n):
fib = [0, 1]
for i in range(2, n+1):
fib.append(fib[i-1] + fib[i-2])
return fib[n]
You: /chat What factors are affecting the tech stock market right now?
GPT: Several factors currently affecting the tech stock market include:
1. Interest rate changes by central banks
2. Inflation concerns
3. Earnings reports from major tech companies
4. AI development and adoption rates
5. Regulatory changes and antitrust investigations
6. Supply chain challenges
7. Consumer spending patterns
...
GPT-4 and similar models have impressive capabilities that make them useful for many different tasks:
GPT can understand nuanced questions and provide relevant, contextual responses.
It can communicate in dozens of languages, including Chinese, Japanese, Korean, Spanish, French, and many more.
The model contains knowledge about a wide range of topics up to its training cutoff date.
GPT can write code in many programming languages, debug existing code, and explain how code works.
It can help with writing stories, poems, essays, emails, and other forms of creative or professional writing.
GPT can follow complex instructions and solve problems step by step.
git clone https://github.com/yourusername/LineGPT.git cd LineGPT
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt
.env
file in the root directory with your credentials:LINE_CHANNEL_ACCESS_TOKEN=your_line_channel_access_token
LINE_CHANNEL_SECRET=your_line_channel_secret
OPENAI_API_KEY=your_openai_api_key
FINANCIAL_NEWS_API_KEY=your_financial_news_api_key
USER_IDS=user_id1,user_id2 # Comma-separated list of LINE user IDs to send news to
# Option 1: Using the run script ./run.sh # Option 2: Manually activating the virtual environment source venv/bin/activate python3 app.py
# In a new terminal window, run the webhook setup script ./setup_webhook.sh
This script will:
./setup_webhook.sh
, you'll be prompted to enter this authtoken if ngrok is not already configured./run.sh
./setup_webhook.sh
to start ngrok/callback
) in the "Webhook URL" field.env
file.env
file/chat [message]
- Explicitly ask ChatGPT a question/reset
- Clear conversation history/news
- Get the latest financial news on demand/help
- Show available commandsYou can modify the following parameters in .env
:
For production deployment:
To expose your local development server for testing:
setup_webhook.sh
scriptngrok http 8080
If you're experiencing issues with the webhook:
.env
file.The application includes several debugging endpoints to help diagnose issues:
/debug
- Provides general debugging information about the application, including encoding settings and API key status./test_message?user_id=USER_ID&message=MESSAGE
- Sends a test message to a specific user./test_chinese?user_id=USER_ID
- Tests sending messages in multiple languages (English, Chinese, Japanese, Korean)./raw_message?user_id=USER_ID&message=MESSAGE
- Sends a raw message directly to the LINE API, bypassing the application's message handling./test_broadcast?message=MESSAGE
- Sends a message to all registered users./test_encoding?user_id=USER_ID&text=TEXT
- Tests text encoding and sends a message.These endpoints can be accessed when the application is running, for example:
http://localhost:5000/debug
http://localhost:5000/test_message?user_id=YOUR_USER_ID&message=Test message
If the bot is not responding to messages:
/test_message
endpoint to send a test message directly./test_chinese
endpoint.If you see warnings related to LibreSSL:
urllib3.exceptions.InsecureRequestWarning: Unverified HTTPS request is being made to host
This is a warning and not an error. The application should still function correctly. To resolve this warning:
pyopenssl
package: pip install pyopenssl
MIT License
There are no datasets linked
There are no models linked
There are no models linked
There are no datasets linked