samagra44 commited on
Commit
e87cf80
Β·
1 Parent(s): f154798

initial commit

Browse files
Files changed (1) hide show
  1. README.md +17 -416
README.md CHANGED
@@ -1,419 +1,20 @@
1
- # πŸš€ LangGraph Post Generator
2
-
3
- An intelligent LinkedIn post generator powered by **LangGraph** and **Azure OpenAI** that creates engaging, professional content by intelligently routing queries through web search and content generation workflows.
4
-
5
- ## πŸ“‹ Table of Contents
6
-
7
- - [Overview](#overview)
8
- - [Features](#features)
9
- - [Architecture](#architecture)
10
- - [Tech Stack](#tech-stack)
11
- - [Installation](#installation)
12
- - [Configuration](#configuration)
13
- - [Usage](#usage)
14
- - [Project Structure](#project-structure)
15
- - [API Documentation](#api-documentation)
16
- - [Technical Details](#technical-details)
17
- - [Testing](#testing)
18
- - [Contributing](#contributing)
19
- - [License](#license)
20
-
21
- ## 🌟 Overview
22
-
23
- The **LangGraph Post Generator** is an AI-powered application that transforms simple topic inputs into compelling LinkedIn posts. It leverages the power of **LangGraph** to create an intelligent workflow that decides whether to search for additional context or directly generate content based on the input query.
24
-
25
- ### Key Capabilities:
26
- - **Intelligent Routing**: Automatically determines if web search is needed for better context
27
- - **Web Search Integration**: Uses DuckDuckGo to gather recent, relevant information
28
- - **Professional Content Generation**: Creates LinkedIn-optimized posts with proper tone and structure
29
- - **Real-time Processing**: Streamlit-based web interface for immediate results
30
- - **Comprehensive Logging**: Detailed logging for debugging and monitoring
31
-
32
- ## ✨ Features
33
-
34
- - 🧠 **Smart Query Routing**: AI-powered decision making for content enhancement
35
- - πŸ” **Real-time Web Search**: Integration with DuckDuckGo for up-to-date information
36
- - πŸ“ **Professional Content Creation**: LinkedIn-optimized posts with engaging tone
37
- - 🎯 **Context-Aware Generation**: Uses web search results to create informed content
38
- - πŸ“Š **Enhanced Streamlit Interface**: Beautiful, modern UI with sidebar configurations
39
- - βš™οΈ **Configurable Settings**: Customize post length, tone, hashtags, and call-to-action
40
- - 🎨 **Professional Styling**: LinkedIn-inspired design with gradients and modern components
41
- - πŸ“ˆ **Post Analytics**: Track generated posts and usage statistics
42
- - πŸ’‘ **Smart Suggestions**: Hashtag recommendations and example topics
43
- - πŸ”§ **Modular Architecture**: Clean, maintainable codebase with separation of concerns
44
- - πŸ“‹ **Comprehensive Logging**: Detailed logs for monitoring and debugging
45
- - πŸ”„ **Flexible Workflow**: LangGraph-powered state management
46
-
47
- ## πŸ—οΈ Architecture
48
-
49
- The application follows a **LangGraph-based workflow** with the following components:
50
-
51
- ```mermaid
52
- graph TD
53
- A[User Input] --> B[Question Router]
54
- B --> C{Route Decision}
55
- C -->|Need Context| D[Query Transform]
56
- C -->|Direct Generation| E[Content Generator]
57
- D --> F[Web Search]
58
- F --> E
59
- E --> G[LinkedIn Post Output]
60
- ```
61
-
62
- ### Workflow Steps:
63
- 1. **Input Processing**: User provides a topic through Streamlit interface
64
- 2. **Question Routing**: AI determines if web search is needed
65
- 3. **Query Transformation** (if needed): Optimizes the query for web search
66
- 4. **Web Search** (if needed): Gathers relevant context using DuckDuckGo
67
- 5. **Content Generation**: Creates professional LinkedIn post using Azure OpenAI
68
- 6. **Output**: Returns formatted LinkedIn post to user
69
-
70
- ## πŸ› οΈ Tech Stack
71
-
72
- ### Core Technologies:
73
- - **Python 3.8+** - Primary programming language
74
- - **LangGraph** - Workflow orchestration and state management
75
- - **LangChain** - LLM framework and prompt management
76
- - **Azure OpenAI** - Language model for content generation
77
- - **Streamlit** - Web application framework
78
- - **DuckDuckGo Search** - Web search functionality
79
-
80
- ### Dependencies:
81
- - `streamlit` - Web interface
82
- - `langchain` - LLM framework
83
- - `langchain-core` - Core LangChain functionality
84
- - `langchain-community` - Community tools and utilities
85
- - `langchain-openai` - Azure OpenAI integration
86
- - `langgraph` - Graph-based workflow management
87
- - `langsmith` - LangChain monitoring and debugging
88
- - `duckduckgo-search` - Web search capabilities
89
- - `python-dotenv` - Environment variable management
90
-
91
- ## πŸ“¦ Installation
92
-
93
- ### Prerequisites
94
- - Python 3.8 or higher
95
- - Azure OpenAI API access
96
- - Git (for cloning the repository)
97
-
98
- ### Step 1: Clone the Repository
99
- ```bash
100
- git clone https://github.com/your-username/langgraph-post-generator.git
101
- cd langgraph-post-generator/post-generator-agent
102
- ```
103
-
104
- ### Step 2: Create Virtual Environment
105
- ```bash
106
- # Create virtual environment
107
- python -m venv venv
108
-
109
- # Activate virtual environment
110
- # On Windows:
111
- venv\Scripts\activate
112
- # On macOS/Linux:
113
- source venv/bin/activate
114
- ```
115
-
116
- ### Step 3: Install Dependencies
117
- ```bash
118
- pip install -r requirements.txt
119
- ```
120
-
121
- ### Step 4: Run the Application
122
- ```bash
123
- streamlit run app.py
124
- ```
125
-
126
- ### Step 5: Configure Credentials
127
- 1. Open the app in your browser
128
- 2. Go to the sidebar configuration
129
- 3. Enter your Azure OpenAI credentials:
130
- - **API Key**: Your Azure OpenAI API key
131
- - **Endpoint**: Your Azure OpenAI endpoint (e.g., `https://your-resource.openai.azure.com/`)
132
- - **Deployment Name**: Your model deployment name (e.g., `gpt-35-turbo`)
133
- - **API Version**: API version (default: `2024-02-01`)
134
- 4. Click "Save Credentials"
135
- 5. Test the connection using the "Test Connection" button
136
-
137
- ## βš™οΈ Configuration
138
-
139
- ### Azure OpenAI Setup
140
-
141
- 1. **Create Azure OpenAI Resource**:
142
- - Go to [Azure Portal](https://portal.azure.com)
143
- - Create a new OpenAI resource
144
- - Note your endpoint and API key
145
-
146
- 2. **Deploy a Model**:
147
- - Deploy a GPT model (GPT-3.5-turbo or GPT-4)
148
- - Note your deployment name
149
-
150
- 3. **Update Configuration**:
151
- - Add your credentials to the `.env` file
152
- - Ensure the API version matches your Azure OpenAI service
153
-
154
- ### Environment Variables
155
-
156
- | Variable | Description | Example |
157
- |----------|-------------|---------|
158
- | `AZURE_OPENAI_API_KEY` | Your Azure OpenAI API key | `abc123...` |
159
- | `AZURE_OPENAI_ENDPOINT` | Your Azure OpenAI endpoint URL | `https://example.openai.azure.com/` |
160
- | `OPENAI_API_VERSION` | API version for Azure OpenAI | `2024-02-01` |
161
- | `AZURE_DEPLOYMENT` | Name of your model deployment | `gpt-35-turbo` |
162
-
163
- ## πŸš€ Usage
164
-
165
- ### Running the Application
166
-
167
- 1. **Start the Streamlit App**:
168
- ```bash
169
- streamlit run app.py
170
- ```
171
-
172
- 2. **Access the Interface**:
173
- - Open your browser to `http://localhost:8501`
174
- - Configure settings in the sidebar (post length, tone, hashtags)
175
- - Enter a topic in the main input area
176
- - Add optional context for better results
177
- - Click "Generate LinkedIn Post" to create content
178
- - View the generated post in a styled container
179
- - Use example topics for quick testing
180
-
181
- ### UI Features
182
-
183
- - **πŸ“Š Sidebar Configuration**:
184
- - **πŸ”‘ Azure Credentials Management**:
185
- - Manual credential input with password masking
186
- - Real-time credential validation for Azure OpenAI format
187
- - Connection testing functionality
188
- - Credential persistence across sessions
189
- - API status indicators with masked API keys
190
- - Post length options (Short, Medium, Long)
191
- - Tone selection (Professional, Casual, Enthusiastic, etc.)
192
- - Hashtag and call-to-action toggles
193
- - Hashtag suggestions based on topic
194
-
195
- - **🎯 Main Interface**:
196
- - Large text area for topic input
197
- - Optional context expander
198
- - Generate and Clear buttons
199
- - Tips for better posts
200
- - Post analytics tracking
201
- - Example topics for quick testing
202
-
203
- - **πŸ“„ Output Display**:
204
- - Styled output container
205
- - Success/error messages
206
- - Copy to clipboard functionality
207
-
208
- ### Example Usage
209
-
210
- **Input**: "Artificial Intelligence trends in 2024"
211
-
212
- **Output**: A professionally formatted LinkedIn post including:
213
- - Current AI trends and insights
214
- - Professional tone suitable for LinkedIn
215
- - Actionable insights for professionals
216
- - Engaging call-to-action or discussion points
217
-
218
- ### Command Line Testing
219
-
220
- You can also test individual components:
221
-
222
- ```bash
223
- # Test LLM configuration
224
- python tests/llm_test.py
225
-
226
- # Test web search functionality
227
- python tests/search_test.py
228
-
229
- # Test the complete agent workflow
230
- python utils/run_agent.py
231
- ```
232
-
233
- ## πŸ“ Project Structure
234
-
235
- ```
236
- post-generator-agent/
237
- β”œβ”€β”€ πŸ“„ app.py # Main Streamlit application
238
- β”œβ”€β”€ πŸ“ config/
239
- β”‚ β”œβ”€β”€ configs.py # Environment configuration
240
- β”‚ └── generation_config.py # Generation settings and prompts
241
- β”œβ”€β”€ πŸ“ helper/
242
- β”‚ β”œβ”€β”€ configure_llm.py # Azure OpenAI LLM setup
243
- β”‚ β”œβ”€β”€ graphs.py # LangGraph workflow definition
244
- β”‚ β”œβ”€β”€ model_load.py # Graph state model
245
- β”‚ └── web_search_agent.py # DuckDuckGo search configuration
246
- β”œβ”€β”€ πŸ“ loggers/
247
- β”‚ └── logger.py # Logging configuration
248
- β”œβ”€β”€ πŸ“ template/
249
- β”‚ β”œβ”€β”€ response_prompt.py # Content generation prompts
250
- β”‚ β”œβ”€β”€ router_prompt.py # Query routing prompts
251
- β”‚ └── transform_prompt.py # Query transformation prompts
252
- β”œβ”€β”€ πŸ“ tests/
253
- β”‚ β”œβ”€β”€ llm_test.py # LLM functionality tests
254
- β”‚ └── search_test.py # Search functionality tests
255
- β”œβ”€β”€ πŸ“ utils/
256
- β”‚ β”œβ”€β”€ credential_manager.py # Azure credentials management
257
- β”‚ β”œβ”€β”€ generate_content.py # Content generation logic
258
- β”‚ β”œβ”€β”€ query_transform.py # Query transformation logic
259
- β”‚ β”œβ”€β”€ question_route.py # Question routing logic
260
- β”‚ β”œβ”€β”€ run_agent.py # Main agent execution
261
- β”‚ └── search_web_content.py # Web search implementation
262
- β”œβ”€β”€ πŸ“„ requirements.txt # Python dependencies
263
- └── πŸ“„ README.md # This documentation
264
- ```
265
-
266
- ## πŸ“– API Documentation
267
-
268
- ### Core Functions
269
-
270
- #### `execute_agent(query: str) -> str`
271
- Main function to execute the LangGraph workflow.
272
-
273
- **Parameters:**
274
- - `query` (str): The topic or question for LinkedIn post generation
275
-
276
- **Returns:**
277
- - `str`: Generated LinkedIn post content
278
-
279
- **Example:**
280
- ```python
281
- from utils.run_agent import execute_agent
282
-
283
- result = execute_agent("Latest trends in machine learning")
284
- print(result)
285
- ```
286
-
287
- #### `route_question(state: dict) -> str`
288
- Routes questions to appropriate workflow paths.
289
-
290
- **Parameters:**
291
- - `state` (dict): Current graph state containing the question
292
-
293
- **Returns:**
294
- - `str`: Routing decision ("websearch" or "generate")
295
-
296
- #### `transform_query(state: dict) -> dict`
297
- Transforms user queries for optimal web search.
298
-
299
- **Parameters:**
300
- - `state` (dict): Current graph state
301
-
302
- **Returns:**
303
- - `dict`: Updated state with optimized search query
304
-
305
- #### `web_search(state: dict) -> dict`
306
- Performs web search using DuckDuckGo.
307
-
308
- **Parameters:**
309
- - `state` (dict): Current graph state with search query
310
-
311
- **Returns:**
312
- - `dict`: Updated state with search results context
313
-
314
- #### `generate(state: dict) -> dict`
315
- Generates final LinkedIn post content.
316
-
317
- **Parameters:**
318
- - `state` (dict): Current graph state with question and optional context
319
-
320
- **Returns:**
321
- - `dict`: Updated state with generated content
322
-
323
- ## πŸ”§ Technical Details
324
-
325
- ### LangGraph Workflow
326
-
327
- The application uses **LangGraph** to create a stateful workflow:
328
-
329
- ```python
330
- # Graph state definition
331
- class GraphState(TypedDict):
332
- question: str # Original user question
333
- generation: str # Generated LinkedIn post
334
- search_query: str # Optimized search query
335
- context: str # Web search results
336
- ```
337
-
338
- ### Prompt Engineering
339
-
340
- The system uses three specialized prompt templates:
341
-
342
- 1. **Router Prompt**: Determines routing strategy
343
- 2. **Transform Prompt**: Optimizes queries for web search
344
- 3. **Response Prompt**: Generates LinkedIn-optimized content
345
-
346
- ### Logging System
347
-
348
- Comprehensive logging with:
349
- - **File Logging**: Timestamped log files in `logs/` directory
350
- - **Console Logging**: Real-time feedback during execution
351
- - **Multiple Log Levels**: DEBUG, INFO, WARNING, ERROR
352
-
353
- ### Error Handling
354
-
355
- Robust error handling including:
356
- - Graceful fallbacks when web search fails
357
- - Retry mechanisms for API calls
358
- - Comprehensive error logging
359
-
360
- ## πŸ§ͺ Testing
361
-
362
- ### Running Tests
363
-
364
- ```bash
365
- # Test Azure OpenAI connection
366
- python tests/llm_test.py
367
-
368
- # Test web search functionality
369
- python tests/search_test.py
370
-
371
- # Test complete workflow
372
- python utils/run_agent.py
373
- ```
374
-
375
- ### Test Coverage
376
-
377
- - **LLM Integration**: Validates Azure OpenAI connectivity
378
- - **Web Search**: Tests DuckDuckGo search functionality
379
- - **End-to-End**: Complete workflow validation
380
-
381
- ## 🀝 Contributing
382
-
383
- We welcome contributions! Please follow these steps:
384
-
385
- 1. **Fork the Repository**
386
- 2. **Create Feature Branch**: `git checkout -b feature/amazing-feature`
387
- 3. **Commit Changes**: `git commit -m 'Add amazing feature'`
388
- 4. **Push to Branch**: `git push origin feature/amazing-feature`
389
- 5. **Open Pull Request**
390
-
391
- ### Development Guidelines
392
-
393
- - Follow PEP 8 style guidelines
394
- - Add comprehensive docstrings
395
- - Include tests for new features
396
- - Update documentation as needed
397
-
398
- ## πŸ“„ License
399
-
400
- This project is licensed under the MIT License. See the `LICENSE` file for details.
401
-
402
- ## πŸ†˜ Support
403
-
404
- For support and questions:
405
-
406
- - **Issues**: Open an issue on GitHub
407
- - **Documentation**: Check this README and code comments
408
- - **Community**: Join our discussions
409
-
410
- ## πŸ™ Acknowledgments
411
 
412
- - **LangChain Team** for the excellent LLM framework
413
- - **Azure OpenAI** for powerful language models
414
- - **Streamlit** for the intuitive web framework
415
- - **DuckDuckGo** for search capabilities
416
 
417
- ---
 
418
 
419
- **Built with ❀️ using LangGraph and Azure OpenAI**
 
 
 
 
 
1
+ ---
2
+ title: LinkedIn Post Generator
3
+ emoji: πŸš€
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ # πŸš€ LinkedIn Post Generator
 
 
 
12
 
13
+ An AI-powered LinkedIn post generator built with **LangGraph**, **Azure OpenAI**, and **Streamlit**.
14
+ It intelligently decides whether to search the web for fresh content before generating professional LinkedIn posts.
15
 
16
+ ## Features
17
+ - Smart query routing with LangGraph
18
+ - DuckDuckGo real-time web search
19
+ - Azure OpenAI content generation
20
+ - Streamlit web interface