Skip to content

Commit 53433c6

Browse files
committed
fix port commentary
1 parent 39e8a41 commit 53433c6

2 files changed

Lines changed: 20 additions & 27 deletions

File tree

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import AsyncGenerator, Callable
2-
from common.agent import reasoning_step, get_remote_data, remote_function_call
2+
from openbb_ai import reasoning_step, get_widget_data
33
from openbb_ai.models import (
44
DataContent,
55
FunctionCallSSE,
@@ -27,9 +27,6 @@ def get_widget_data(widget_collection: WidgetCollection) -> Callable:
2727
else []
2828
)
2929

30-
@remote_function_call(
31-
function="get_widget_data", output_formatter=handle_widget_data
32-
)
3330
async def _get_widget_data(
3431
widget_uuid: str,
3532
) -> AsyncGenerator[FunctionCallSSE | StatusUpdateSSE, None]:
@@ -59,16 +56,14 @@ async def _get_widget_data(
5956
details={"widget_uuid": widget_uuid},
6057
)
6158

62-
# And now let's make the request to the front-end for the widget data.
63-
# NB: You *must* yield using `agent.remote_data_request` from inside
64-
# remote functions (i.e. those decorated with `@remote_function`).
65-
yield get_remote_data(
66-
widget=widget,
67-
# In this example we will just re-use the currently-set values of
68-
# the widget parameters.
69-
input_arguments={
70-
param.name: param.current_value for param in widget.params
71-
},
59+
# Request the widget data using the new API
60+
from openbb_ai.models import WidgetRequest
61+
widget_request = WidgetRequest(
62+
widget_uuid=widget.uuid,
63+
origin=widget.origin,
64+
id=widget.widget_id,
65+
input_args={param.name: param.current_value for param in widget.params},
7266
)
67+
yield get_widget_data([widget_request]).model_dump()
7368

7469
return _get_widget_data

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import AsyncGenerator, Callable
77

88
import httpx
9-
from common.agent import get_remote_data, reasoning_step, remote_function_call
9+
from openbb_ai import reasoning_step, get_widget_data
1010
from dotenv import load_dotenv
1111
from fastapi import FastAPI
1212
from fastapi.middleware.cors import CORSMiddleware
@@ -94,7 +94,7 @@ async def perplexity_web_search(query: str) -> str:
9494
}
9595

9696
try:
97-
async with httpx.AsyncClient() as client:
97+
async with httpx.AsyncClient(timeout=30.0) as client:
9898
response = await client.post(url, headers=headers, json=data)
9999
response.raise_for_status()
100100
response_json = response.json()
@@ -258,9 +258,6 @@ def get_widget_data(widget_collection: WidgetCollection) -> Callable:
258258
else []
259259
)
260260

261-
@remote_function_call(
262-
function="get_widget_data", output_formatter=handle_widget_data
263-
)
264261
async def _get_widget_data(
265262
widget_uuid: str,
266263
) -> AsyncGenerator[FunctionCallSSE | StatusUpdateSSE, None]:
@@ -289,14 +286,15 @@ async def _get_widget_data(
289286
details={"widget_uuid": widget_uuid},
290287
)
291288

292-
# Request the widget data
293-
yield get_remote_data(
294-
widget=widget,
295-
# Use the current values of widget parameters
296-
input_arguments={
297-
param.name: param.current_value for param in widget.params
298-
},
289+
# Request the widget data using the new API
290+
from openbb_ai.models import WidgetRequest
291+
widget_request = WidgetRequest(
292+
widget_uuid=widget.uuid,
293+
origin=widget.origin,
294+
id=widget.widget_id,
295+
input_args={param.name: param.current_value for param in widget.params},
299296
)
297+
yield get_widget_data([widget_request]).model_dump()
300298

301299
return _get_widget_data
302300

@@ -583,7 +581,7 @@ async def direct_response():
583581
logger.info(
584582
f"Making initial request to detect tool calls with messages: {formatted_messages}"
585583
)
586-
async with httpx.AsyncClient() as client:
584+
async with httpx.AsyncClient(timeout=30.0) as client:
587585
response = await client.post(url, headers=headers, json=data)
588586
response.raise_for_status()
589587
result = response.json()

0 commit comments

Comments
 (0)