11from __future__ import annotations
22
3+ import logging
34from typing import TYPE_CHECKING
45
56from bottle import Bottle
1920 from .llm .provider import LLMProvider
2021
2122
23+ _logger = logging .getLogger (__name__ )
24+
25+
2226def register_llm_route (app : Bottle , llm_provider : LLMProvider | None ) -> None :
2327 @app .post ("/api/llm/trial_filter_query" )
2428 @json_api_view
@@ -71,10 +75,6 @@ def get_generate_plotly_graph_func_str() -> dict[str, str]:
7175 try :
7276 prompt_for_func = get_generate_plotly_graph_prompt (user_query , func_str , err_msg )
7377 generate_plotly_graph_func_str = llm_provider .call (prompt_for_func )
74- prompt_for_title = get_generate_plotly_graph_title_prompt (
75- user_query , generate_plotly_graph_func_str
76- )
77- generated_plotly_graph_title = llm_provider .call (prompt_for_title )
7878 except RateLimitExceeded as e :
7979 response .status = 429 # Too Many Requests
8080 reason = f"Rate limit exceeded. Try again later. The actual error: { str (e )} "
@@ -87,6 +87,17 @@ def get_generate_plotly_graph_func_str() -> dict[str, str]:
8787 response .status = 500
8888 return {"reason" : str (e )}
8989
90+ try :
91+ # TODO(c-bata): Consider removing the generate_plotly_graph_func_str argument
92+ # to enable parallel llm provider calls
93+ prompt_for_title = get_generate_plotly_graph_title_prompt (
94+ user_query , generate_plotly_graph_func_str
95+ )
96+ generated_plotly_graph_title = llm_provider .call (prompt_for_title )
97+ except Exception as e :
98+ _logger .error ("Failed to generate title for plotly graph: %s" , e )
99+ generated_plotly_graph_title = f'Graph generated by "{ user_query } "'
100+
90101 response .status = 200
91102 return {
92103 "generate_plotly_graph_func_str" : generate_plotly_graph_func_str ,
0 commit comments