Skip to content

Commit 34bec94

Browse files
authored
Merge pull request #80 from OpenBB-finance/hotfix/orchestration_request
2 parents bdb9ba3 + 000837a commit 34bec94

12 files changed

Lines changed: 104 additions & 109 deletions

File tree

  • 20-financial-prompt-optimizer
  • 30-vanilla-agent-raw-widget-data/vanilla_agent_raw_context
  • 31-vanilla-agent-reasoning-steps/vanilla_agent_reasoning_steps
  • 32-vanilla-agent-raw-widget-data-citations/vanilla_agent_raw_context_citations
  • 33-vanilla-agent-charts/vanilla_agent_charts
  • 34-vanilla-agent-tables/vanilla_agent_tables
  • 35-vanilla-agent-pdf/vanilla_agent_pdf
  • 36-vanilla-agent-pdf-citations/vanilla_agent_pdf_citations
  • 40-vanilla-agent-dashboard-widgets/vanilla_agent_dashboard_widgets
  • 99-advanced-examples/70-portfolio-commentary/portfolio_commentary

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
__pycache__/
22
/.env
3+
venv
4+
.venv
35
*.DS_Store
46
*pycache*
57
*.ruff_cache
68
*.pytest_cache
7-
*.ipynb_checkpoints
9+
*.ipynb_checkpoints

20-financial-prompt-optimizer/main.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from typing import AsyncGenerator
2-
import openai
32

3+
import openai
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66
from fastapi.responses import JSONResponse
7-
from sse_starlette.sse import EventSourceResponse
8-
9-
from openbb_ai.models import MessageChunkSSE, QueryRequest
10-
from openbb_ai import message_chunk
11-
127
from openai.types.chat import (
13-
ChatCompletionMessageParam,
14-
ChatCompletionUserMessageParam,
158
ChatCompletionAssistantMessageParam,
9+
ChatCompletionMessageParam,
1610
ChatCompletionSystemMessageParam,
11+
ChatCompletionUserMessageParam,
1712
)
18-
13+
from openbb_ai import message_chunk
14+
from openbb_ai.models import MessageChunkSSE, QueryRequest
15+
from sse_starlette.sse import EventSourceResponse
1916

2017
app = FastAPI()
2118

@@ -37,7 +34,7 @@ def get_copilot_description():
3734
"name": "Financial Prompt Optimizer",
3835
"description": "Optimizes a user's prompt for finance: clearer, more specific, and actionable.",
3936
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
40-
"endpoints": {"query": "http://localhost:7777/v1/query"},
37+
"endpoints": {"query": "/v1/query"},
4138
"features": {
4239
"streaming": True,
4340
"widget-dashboard-select": False,

30-vanilla-agent-raw-widget-data/vanilla_agent_raw_context/main.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from typing import AsyncGenerator
2-
import openai
32

3+
import openai
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66
from fastapi.responses import JSONResponse
7-
from sse_starlette.sse import EventSourceResponse
8-
9-
from openbb_ai.models import MessageChunkSSE, QueryRequest
10-
from openbb_ai import get_widget_data, WidgetRequest, message_chunk
11-
127
from openai.types.chat import (
13-
ChatCompletionMessageParam,
14-
ChatCompletionUserMessageParam,
158
ChatCompletionAssistantMessageParam,
9+
ChatCompletionMessageParam,
1610
ChatCompletionSystemMessageParam,
11+
ChatCompletionUserMessageParam,
1712
)
18-
13+
from openbb_ai import WidgetRequest, get_widget_data, message_chunk
14+
from openbb_ai.models import MessageChunkSSE, QueryRequest
15+
from sse_starlette.sse import EventSourceResponse
1916

2017
app = FastAPI()
2118

@@ -37,7 +34,7 @@ def get_copilot_description():
3734
"name": "Vanilla Agent Raw Context",
3835
"description": "A vanilla agent that automatically retrieves widget data and passes it as raw context to the LLM.",
3936
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
40-
"endpoints": {"query": "http://localhost:7777/v1/query"},
37+
"endpoints": {"query": "/v1/query"},
4138
"features": {
4239
"streaming": True,
4340
"widget-dashboard-select": True,
@@ -54,8 +51,12 @@ async def query(request: QueryRequest) -> EventSourceResponse:
5451

5552
# We only automatically fetch widget data if the last message is from a
5653
# human, and widgets have been explicitly added to the request.
54+
last_message = request.messages[-1]
55+
orchestration_requested = (
56+
last_message.role == "ai" and last_message.agent_id == "openbb-copilot"
57+
)
5758
if (
58-
request.messages[-1].role == "human"
59+
(last_message.role == "human" or orchestration_requested)
5960
and request.widgets
6061
and request.widgets.primary
6162
):

31-vanilla-agent-reasoning-steps/vanilla_agent_reasoning_steps/main.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from typing import AsyncGenerator
2-
import openai
32

3+
import openai
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66
from fastapi.responses import JSONResponse
7-
from sse_starlette.sse import EventSourceResponse
8-
9-
from openbb_ai.models import MessageChunkSSE, QueryRequest
10-
from openbb_ai import reasoning_step, message_chunk
11-
127
from openai.types.chat import (
13-
ChatCompletionMessageParam,
14-
ChatCompletionUserMessageParam,
158
ChatCompletionAssistantMessageParam,
9+
ChatCompletionMessageParam,
1610
ChatCompletionSystemMessageParam,
11+
ChatCompletionUserMessageParam,
1712
)
18-
13+
from openbb_ai import message_chunk, reasoning_step
14+
from openbb_ai.models import MessageChunkSSE, QueryRequest
15+
from sse_starlette.sse import EventSourceResponse
1916

2017
app = FastAPI()
2118

@@ -37,14 +34,14 @@ def get_copilot_description():
3734
"name": "Vanilla Agent Reasoning Steps",
3835
"description": "A vanilla agent that returns reasoning steps to the OpenBB Workspace.",
3936
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
40-
"endpoints": {"query": "http://localhost:7777/v1/query"},
37+
"endpoints": {"query": "/v1/query"},
4138
"features": {
4239
"streaming": True,
4340
"widget-dashboard-select": False,
4441
"widget-dashboard-search": False,
4542
},
4643
}
47-
}
44+
},
4845
)
4946

5047

32-vanilla-agent-raw-widget-data-citations/vanilla_agent_raw_context_citations/main.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from typing import AsyncGenerator
2-
import openai
32

3+
import openai
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66
from fastapi.responses import JSONResponse
7-
from sse_starlette.sse import EventSourceResponse
8-
9-
from openbb_ai.models import MessageChunkSSE, QueryRequest
10-
from openbb_ai import get_widget_data, WidgetRequest, message_chunk, cite, citations
11-
127
from openai.types.chat import (
13-
ChatCompletionMessageParam,
14-
ChatCompletionUserMessageParam,
158
ChatCompletionAssistantMessageParam,
9+
ChatCompletionMessageParam,
1610
ChatCompletionSystemMessageParam,
11+
ChatCompletionUserMessageParam,
1712
)
18-
13+
from openbb_ai import WidgetRequest, citations, cite, get_widget_data, message_chunk
14+
from openbb_ai.models import MessageChunkSSE, QueryRequest
15+
from sse_starlette.sse import EventSourceResponse
1916

2017
app = FastAPI()
2118

@@ -37,7 +34,7 @@ def get_copilot_description():
3734
"name": "Vanilla Agent Raw Widget Data Citations",
3835
"description": "A vanilla agent that automatically retrieves widget data and passes it as raw context to the LLM, and then cites the data that has been retrieved.",
3936
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
40-
"endpoints": {"query": "http://localhost:7777/v1/query"},
37+
"endpoints": {"query": "/v1/query"},
4138
"features": {
4239
"streaming": True,
4340
"widget-dashboard-select": True,
@@ -54,8 +51,12 @@ async def query(request: QueryRequest) -> EventSourceResponse:
5451

5552
# We only automatically fetch widget data if the last message is from a
5653
# human, and widgets have been explicitly added to the request.
54+
last_message = request.messages[-1]
55+
orchestration_requested = (
56+
last_message.role == "ai" and last_message.agent_id == "openbb-copilot"
57+
)
5758
if (
58-
request.messages[-1].role == "human"
59+
(last_message.role == "human" or orchestration_requested)
5960
and request.widgets
6061
and request.widgets.primary
6162
):

33-vanilla-agent-charts/vanilla_agent_charts/main.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from typing import AsyncGenerator
2-
import openai
32

3+
import openai
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66
from fastapi.responses import JSONResponse
7-
from sse_starlette.sse import EventSourceResponse
8-
9-
from openbb_ai.models import MessageChunkSSE, QueryRequest
10-
from openbb_ai import message_chunk, chart
11-
127
from openai.types.chat import (
13-
ChatCompletionMessageParam,
14-
ChatCompletionUserMessageParam,
158
ChatCompletionAssistantMessageParam,
9+
ChatCompletionMessageParam,
1610
ChatCompletionSystemMessageParam,
11+
ChatCompletionUserMessageParam,
1712
)
18-
13+
from openbb_ai import chart, message_chunk
14+
from openbb_ai.models import MessageChunkSSE, QueryRequest
15+
from sse_starlette.sse import EventSourceResponse
1916

2017
app = FastAPI()
2118

@@ -37,7 +34,7 @@ def get_copilot_description():
3734
"name": "Vanilla Agent Charts",
3835
"description": "A vanilla agent that can produce charts as part of its response.",
3936
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
40-
"endpoints": {"query": "http://localhost:7777/v1/query"},
37+
"endpoints": {"query": "/v1/query"},
4138
"features": {
4239
"streaming": True,
4340
"widget-dashboard-select": True,

34-vanilla-agent-tables/vanilla_agent_tables/main.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from typing import AsyncGenerator
2-
import openai
32

3+
import openai
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66
from fastapi.responses import JSONResponse
7-
from sse_starlette.sse import EventSourceResponse
8-
9-
from openbb_ai.models import MessageChunkSSE, QueryRequest
10-
from openbb_ai import message_chunk, table
11-
127
from openai.types.chat import (
13-
ChatCompletionMessageParam,
14-
ChatCompletionUserMessageParam,
158
ChatCompletionAssistantMessageParam,
9+
ChatCompletionMessageParam,
1610
ChatCompletionSystemMessageParam,
11+
ChatCompletionUserMessageParam,
1712
)
18-
13+
from openbb_ai import message_chunk, table
14+
from openbb_ai.models import MessageChunkSSE, QueryRequest
15+
from sse_starlette.sse import EventSourceResponse
1916

2017
app = FastAPI()
2118

@@ -37,7 +34,7 @@ def get_copilot_description():
3734
"name": "Vanilla Agent Tables",
3835
"description": "A vanilla agent that can produce tables as part of its response.",
3936
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
40-
"endpoints": {"query": "http://localhost:7777/v1/query"},
37+
"endpoints": {"query": "/v1/query"},
4138
"features": {
4239
"streaming": True,
4340
"widget-dashboard-select": True,

35-vanilla-agent-pdf/vanilla_agent_pdf/main.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
import base64
2+
import io
3+
import logging
24
from typing import AsyncGenerator
5+
36
import httpx
47
import openai
5-
8+
import pdfplumber
69
from fastapi import FastAPI
710
from fastapi.middleware.cors import CORSMiddleware
811
from fastapi.responses import JSONResponse
9-
from sse_starlette.sse import EventSourceResponse
10-
12+
from openai.types.chat import (
13+
ChatCompletionAssistantMessageParam,
14+
ChatCompletionMessageParam,
15+
ChatCompletionSystemMessageParam,
16+
ChatCompletionUserMessageParam,
17+
)
18+
from openbb_ai import citations, cite, get_widget_data, message_chunk
1119
from openbb_ai.models import (
1220
Citation,
13-
CitationHighlightBoundingBox,
1421
CitationCollectionSSE,
15-
MessageChunkSSE,
22+
CitationHighlightBoundingBox,
23+
DataContent,
24+
DataFileReferences,
1625
FunctionCallSSE,
26+
MessageChunkSSE,
27+
PdfDataFormat,
1728
QueryRequest,
18-
SingleFileReference,
1929
SingleDataContent,
20-
PdfDataFormat,
21-
DataContent,
22-
DataFileReferences,
30+
SingleFileReference,
2331
WidgetRequest,
2432
)
25-
from openbb_ai import message_chunk, get_widget_data, citations, cite
26-
27-
from openai.types.chat import (
28-
ChatCompletionMessageParam,
29-
ChatCompletionUserMessageParam,
30-
ChatCompletionAssistantMessageParam,
31-
ChatCompletionSystemMessageParam,
32-
)
33-
34-
import logging
35-
import pdfplumber
36-
import io
33+
from sse_starlette.sse import EventSourceResponse
3734

3835
logger = logging.getLogger(__name__)
3936

@@ -58,7 +55,7 @@ def get_copilot_description():
5855
"name": "Vanilla Agent PDF",
5956
"description": "A vanilla agent that can handle PDF data as part of its response.",
6057
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
61-
"endpoints": {"query": "http://localhost:7777/v1/query"},
58+
"endpoints": {"query": "/v1/query"},
6259
"features": {
6360
"streaming": True,
6461
"widget-dashboard-select": True,
@@ -75,8 +72,12 @@ async def query(request: QueryRequest) -> EventSourceResponse:
7572

7673
# We only automatically fetch widget data if the last message is from a
7774
# human, and widgets have been explicitly added to the request.
75+
last_message = request.messages[-1]
76+
orchestration_requested = (
77+
last_message.role == "ai" and last_message.agent_id == "openbb-copilot"
78+
)
7879
if (
79-
request.messages[-1].role == "human"
80+
(last_message.role == "human" or orchestration_requested)
8081
and request.widgets
8182
and request.widgets.primary
8283
):

36-vanilla-agent-pdf-citations/vanilla_agent_pdf_citations/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
import io
33
import logging
4-
from typing import AsyncGenerator, List, Tuple, Dict, Any
4+
from typing import Any, AsyncGenerator, Dict, List, Tuple
55

66
import httpx
77
import openai
@@ -15,7 +15,7 @@
1515
ChatCompletionSystemMessageParam,
1616
ChatCompletionUserMessageParam,
1717
)
18-
from openbb_ai import cite, citations, get_widget_data, message_chunk
18+
from openbb_ai import citations, cite, get_widget_data, message_chunk
1919
from openbb_ai.models import (
2020
Citation,
2121
CitationCollectionSSE,
@@ -55,7 +55,7 @@ def get_copilot_description():
5555
"name": "Vanilla Agent PDF Citations",
5656
"description": "A vanilla agent that handles PDF data with citation support.",
5757
"image": "https://github.com/OpenBB-finance/copilot-for-terminal-pro/assets/14093308/7da2a512-93b9-478d-90bc-b8c3dd0cabcf",
58-
"endpoints": {"query": "http://localhost:7777/v1/query"},
58+
"endpoints": {"query": "/v1/query"},
5959
"features": {
6060
"streaming": True,
6161
"widget-dashboard-select": True,
@@ -72,8 +72,12 @@ async def query(request: QueryRequest) -> EventSourceResponse:
7272

7373
# We only automatically fetch widget data if the last message is from a
7474
# human, and widgets have been explicitly added to the request.
75+
last_message = request.messages[-1]
76+
orchestration_requested = (
77+
last_message.role == "ai" and last_message.agent_id == "openbb-copilot"
78+
)
7579
if (
76-
request.messages[-1].role == "human"
80+
(last_message.role == "human" or orchestration_requested)
7781
and request.widgets
7882
and request.widgets.primary
7983
):

0 commit comments

Comments
 (0)