Skip to content

Commit f67b0ed

Browse files
authored
refactor: use query insteaad of prompt (#23)
2 parents 8d571d9 + 3f8dbf7 commit f67b0ed

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Have a specific question?
5959
```bash
6060
uvx timecopilot forecast https://otexts.com/fpppy/data/AirPassengers.csv \
6161
--model openai:gpt-4o \
62-
--prompt "How many air passengers are expected in total in the next 12 months?"
62+
--query "How many air passengers are expected in total in the next 12 months?"
6363
```
6464

6565
## Installation
@@ -120,7 +120,7 @@ result = forecasting_agent.forecast(df=df)
120120
# - reason_for_selection: Explanation for model choice
121121
# - forecast: List of future predictions with dates
122122
# - forecast_analysis: Interpretation of the forecast results
123-
# - user_prompt_response: Response to the user prompt, if any
123+
# - user_query_response: Response to the user prompt, if any
124124
print(result.output)
125125
```
126126
<details> <summary>Click to expand full forecast output</summary>
@@ -164,7 +164,7 @@ with historical patterns. The strong seasonality is evident in the periodic peak
164164
slight smoothing over time due to parameter adjustment for stability. The forecasts are
165165
reliable given the past performance metrics and the model's rigorous tuning. However,
166166
potential uncertainties could arise from structural breaks or changes in pattern, not
167-
reflected in historical data." user_prompt_response='The analysis determined the best
167+
reflected in historical data." user_query_response='The analysis determined the best
168168
performing model and generated forecasts considering seasonality and trend, aiming for
169169
accuracy and reliability surpassing basic seasonal models.'
170170
"""
@@ -180,14 +180,14 @@ You can ask questions about the forecast in natural language. The agent will ana
180180
# Ask specific questions about the forecast
181181
result = forecasting_agent.forecast(
182182
df=df,
183-
prompt="how many air passengers are expected in the next 12 months?",
183+
query="how many air passengers are expected in the next 12 months?",
184184
)
185185

186186
# The output will include:
187187
# - All the standard forecast information
188-
# - user_prompt_response: Detailed answer to your specific question
188+
# - user_query_response: Detailed answer to your specific question
189189
# analyzing the forecast in the context of your query
190-
print(result.output.user_prompt_response)
190+
print(result.output.user_query_response)
191191

192192
"""
193193
The total expected air passengers for the next 12 months is approximately 5,919.

timecopilot/_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def forecast(
2020
self,
2121
path: str | Path,
2222
model: str = "openai:gpt-4o-mini",
23-
prompt: str = "",
23+
query: str | None = None,
2424
retries: int = 3,
2525
):
2626
with self.console.status(
@@ -29,7 +29,7 @@ def forecast(
2929
forecasting_agent = TimeCopilotAgent(model=model, retries=retries)
3030
result = forecasting_agent.forecast(
3131
df=path,
32-
prompt=prompt,
32+
query=query,
3333
)
3434

3535
result.output.prettify(self.console)

timecopilot/agent.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ class ForecastAgentOutput(BaseModel):
130130
"and potential problems."
131131
)
132132
)
133-
user_prompt_response: str = Field(
134-
description="The response to the user's prompt, if any"
133+
user_query_response: str | None = Field(
134+
description=(
135+
"The response to the user's query, if any. "
136+
"If the user did not provide a query, this field will be None."
137+
)
135138
)
136139

137140
def prettify(self, console: Console | None = None) -> None:
@@ -230,9 +233,9 @@ def prettify(self, console: Console | None = None) -> None:
230233

231234
# Optional user response section
232235
user_response = None
233-
if self.user_prompt_response:
236+
if self.user_query_response:
234237
user_response = Panel(
235-
self.user_prompt_response,
238+
self.user_query_response,
236239
title="[bold]Response to Query[/bold]",
237240
style="cyan",
238241
)
@@ -440,18 +443,18 @@ async def validate_best_model(
440443
)
441444
return output
442445

443-
def forecast(self, df: pd.DataFrame | str | Path, prompt: str = ""):
444-
prompt = f"User prompt: {prompt}" if prompt else "User did not provide a prompt"
446+
def forecast(self, df: pd.DataFrame | str | Path, query: str | None = None):
447+
query = f"User query: {query}" if query else "User did not provide a query"
445448
if isinstance(df, str | Path):
446449
dataset = ExperimentDataset.from_path(df)
447-
prompt = f"The time series was read from {df}. {prompt}"
450+
query = f"The time series was read from {df}. {query}"
448451
elif isinstance(df, pd.DataFrame):
449452
dataset = ExperimentDataset.from_df(df=df)
450453
else:
451454
raise ValueError(f"Invalid input type: {type(df)}")
452455

453456
result = self.forecasting_agent.run_sync(
454-
user_prompt=prompt,
457+
user_prompt=query,
455458
deps=dataset,
456459
)
457460

0 commit comments

Comments
 (0)