Skip to content

Commit 8f17ce7

Browse files
committed
fix it
1 parent 7411334 commit 8f17ce7

6 files changed

Lines changed: 176 additions & 180 deletions

File tree

Lines changed: 114 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,147 @@
1-
# Portfolio Commentary Copilot
2-
3-
This is a FastAPI-based copilot service that provides portfolio commentary and analysis capabilities. The service utilizes DeepSeek for reasoning and Perplexity for web search based on user requests. It is designed to work with OpenBB Workspace and can be deployed using Docker or run locally.
4-
5-
## Architecture
6-
7-
```sh
8-
┌─────────────────────┐ ┌─────────────────────┐
9-
│ │ │ │
10-
│ OpenBB Workspace │ ───────────> │ Portfolio │
11-
│ (Frontend) │ HTTP │ Commentary │
12-
│ │ Request │ Copilot │
13-
│ │ │ (Backend) │
14-
│ │ <───────────-│ │
15-
│ │ SSE │ │
16-
└─────────────────────┘ └─────────────────────┘
17-
```
18-
19-
The architecture consists of two main components:
20-
21-
1. **OpenBB Workspace (Frontend)**: The user interface where queries are entered
22-
2. **Portfolio Commentary Copilot (Backend)**: A FastAPI service that processes queries and returns analysis
1+
# Portfolio Commentary Agent
232

24-
## Project Structure
25-
26-
```
27-
portfolio-commentary/
28-
├── portfolio_commentary/
29-
│ ├── main.py # Main FastAPI application
30-
│ ├── functions.py # Core functionality
31-
│ ├── prompts.py # LLM prompts
32-
│ └── agents.json # Copilot configuration
33-
├── common/ # Shared utilities
34-
├── pyproject.toml # Project dependencies
35-
├── Dockerfile # Docker configuration
36-
└── fly.toml # Fly.io deployment config
37-
```
3+
A sophisticated AI-powered portfolio analysis agent built for OpenBB Workspace. This agent provides intelligent commentary and insights on portfolio performance, allocation, and risk metrics by analyzing widget data from your dashboard.
384

395
## Getting Started
406

41-
Here's how to get your copilot up and running:
42-
437
### Prerequisites
448

459
- Python 3.10 or higher
46-
- Poetry for dependency management
10+
- Poetry for dependency management (or pip)
4711
- Docker (optional, for containerized deployment)
48-
- Your OpenRouter API key
12+
- OpenRouter API key for AI model access
4913

50-
### Installation and Running
14+
### Environment Setup
5115

52-
1. Clone this repository to your local machine.
16+
1. **Clone and navigate to the project:**
17+
```bash
18+
cd 99-advanced-examples/70-portfolio-commentary
19+
```
5320

54-
2. Create and activate a virtual environment:
55-
```sh
56-
python -m venv .venv
57-
source .venv/bin/activate # On Windows: .venv\Scripts\activate
21+
2. **Create environment file:**
22+
Create a `.env` file with the following variables:
23+
```env
24+
OPENROUTER_API_KEY=your_openrouter_api_key_here
25+
OPENROUTER_MODEL=deepseek/deepseek-chat-v3-0324
26+
OPENROUTER_MODEL_PERPLEXITY=perplexity/sonar
5827
```
5928

60-
3. Install dependencies using Poetry:
61-
```sh
29+
### Local Development
30+
31+
**Option 1: Using Poetry**
32+
```bash
33+
# Install dependencies
6234
poetry install --no-root
63-
```
6435

65-
4. Set up environment variables:
66-
Create a `.env` file in the root directory with the following content:
67-
```
68-
OPENROUTER_API_KEY=<your-api-key>
36+
# Run the server
37+
poetry run uvicorn portfolio_commentary.main:app --reload --port 7777
6938
```
7039

71-
5. Run the development server:
72-
```sh
73-
cd 70-portfolio-commentary
74-
poetry run uvicorn portfolio_commentary.main:app --reload --port 7777
40+
**Option 2: Using pip**
41+
```bash
42+
# Create virtual environment
43+
python -m venv .venv
44+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
45+
46+
# Install dependencies
47+
pip install fastapi uvicorn python-dotenv httpx sse-starlette openbb-ai
48+
49+
# Run the server
50+
uvicorn portfolio_commentary.main:app --reload --port 7777
7551
```
7652

7753
### Docker Deployment
7854

79-
1. Build the Docker image:
80-
```sh
55+
```bash
56+
# Build the image
8157
docker build -t portfolio-commentary .
82-
```
8358

84-
2. Run the container:
85-
```sh
59+
# Run the container
8660
docker run -p 7777:7777 --env-file .env portfolio-commentary
8761
```
8862

89-
### Fly.io Deployment
63+
## Configuration
64+
65+
### OpenBB Workspace Integration
66+
67+
The agent automatically registers with OpenBB Workspace through the `/agents.json` endpoint. It supports:
68+
69+
- **Streaming responses** for real-time analysis
70+
- **Widget dashboard selection** for data source integration
71+
- **Perplexity search feature** as an optional enhancement
72+
73+
### Feature Toggles
74+
75+
**Perplexity Search** (`perplexity-search`):
76+
- Enables real-time web search capabilities
77+
- Provides current market context and news
78+
- Uses Perplexity model via OpenRouter
79+
- Default: Disabled
80+
81+
## Usage
82+
83+
### 1. **Add Portfolio Widgets**
84+
- Add relevant widgets to your OpenBB Workspace dashboard
85+
- Common widgets: Performance charts, Holdings tables, Allocation breakdowns, Risk metrics
86+
87+
### 2. **Select Widget Data**
88+
- Use the widget selection feature in OpenBB Workspace
89+
- The agent will automatically detect and process the selected widget data
9090

91-
The project includes a `fly.toml` configuration for deployment to Fly.io. To deploy:
91+
### 3. **Enable Features (Optional)**
92+
- Toggle "Perplexity for Search" for enhanced market context
93+
- This adds real-time research capabilities to your analysis
9294

93-
0. Go into agents.json and change `"query": "https://portfolio-commentary.fly.dev/v1/query"` to `"query": "https://<YOUR-FLY-IO-APP-NAME>.fly.dev/v1/query"`. This will make sure that OpenBB workspace utilizes this endpoint.
94-
1. Install the Fly CLI
95-
2. Run `fly launch` to create a new app
96-
3. Set your environment variables using `fly secrets set`
97-
4. Deploy with `fly deploy`
95+
### 4. **Request Analysis**
96+
- Ask questions about your portfolio
97+
- Examples:
98+
- "Provide a commentary on my portfolio performance"
99+
- "What are the key risks in my current allocation?"
100+
- "How has my portfolio performed relative to benchmarks?"
98101

99-
### Accessing the Documentation
102+
## API Endpoints
103+
104+
- **GET `/agents.json`**: Agent configuration for OpenBB Workspace
105+
- **POST `/v1/query`**: Main query endpoint for portfolio analysis
106+
- **GET `/docs`**: Interactive API documentation (FastAPI Swagger UI)
107+
108+
## Technical Details
109+
110+
### AI Models
111+
- **Default**: DeepSeek Chat v3 (cost-effective, high-quality analysis)
112+
- **Enhanced**: Perplexity Sonar (when search feature is enabled)
113+
- **Streaming**: Real-time response delivery via Server-Sent Events
114+
115+
### Dependencies
116+
- **FastAPI**: Web framework and API server
117+
- **OpenBB AI**: Widget data integration and processing
118+
- **OpenRouter**: AI model access and management
119+
- **httpx**: HTTP client for external API calls
120+
121+
### Dynamic Prompt System
122+
The agent uses intelligent prompt generation that adapts based on:
123+
- Available widget data and context
124+
- Enabled features (Perplexity search)
125+
- Analysis requirements and user requests
126+
127+
## Development
128+
129+
### Local Testing
130+
```bash
131+
# Access API documentation
132+
http://localhost:7777/docs
133+
134+
# Test agent configuration
135+
curl http://localhost:7777/agents.json
136+
```
100137

101-
Once the API server is running, you can view the documentation and interact with
102-
the API by visiting: http://localhost:7777/docs
138+
### Debugging
139+
The application logs detailed information about:
140+
- Widget data processing
141+
- AI model selection (DeepSeek vs Perplexity)
142+
- API calls and responses
143+
- Error handling and fallbacks
103144

104145
## License
105146

106-
This project is licensed under the MIT License - see the LICENSE file for details.
147+
This project is licensed under the MIT License.

99-advanced-examples/70-portfolio-commentary/portfolio_commentary/agents.json

Lines changed: 0 additions & 15 deletions
This file was deleted.
Binary file not shown.

99-advanced-examples/70-portfolio-commentary/portfolio_commentary/functions.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)