Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

nba recap writer #92

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/fast-api-server/dummy-data/game_summaries.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
game_id,status,status_detail,date,season,home_team,away_team,home_team_score,away_team_score,location,venue,venue_id,attendance,game_type,headline_long,headline_short,home_team_abbr,home_team_id,home_team_winner,away_team_abbr,away_team_id,away_team_winner,playoff_series_summary,home_team_overall_record,home_team_home_record,home_team_away_record,away_team_overall_record,away_team_home_record,away_team_away_record
401585130,Final,Final,2024-01-07,2024,Denver Nuggets,Detroit Pistons,131.0,114.0,"Denver, CO",Ball Arena,892.0,,Regular Season,None,None,DEN,7,true,DET,8,false,None,26-12,15-4,None,3-33,None,1-19
401585125,Final,Final,2024-01-07,2024,Cleveland Cavaliers,San Antonio Spurs,117.0,115.0,"Cleveland, OH",Rocket Mortgage FieldHouse,3417.0,,Regular Season,None,None,CLE,5,true,SA,24,false,None,21-15,12-8,None,5-30,None,3-15
401585133,Final,Final,2024-01-07,2024,Los Angeles Lakers,LA Clippers,106.0,103.0,"Los Angeles, CA",crypto.com Arena,1841.0,,Regular Season,None,None,LAL,13,true,LAC,12,false,None,18-19,12-6,None,22-13,None,8-9
401585127,Final,Final/OT,2024-01-07,2024,Orlando Magic,Atlanta Hawks,117.0,110.0,"Orlando, FL",Kia Center,3432.0,,Regular Season,None,None,ORL,19,true,ATL,1,false,None,21-15,13-4,None,14-21,None,9-12
401585129,Final,Final,2024-01-07,2024,Dallas Mavericks,Minnesota Timberwolves,115.0,108.0,"Dallas, TX",American Airlines Center,516.0,,Regular Season,None,None,DAL,6,true,MIN,16,false,None,22-15,11-7,None,25-10,None,11-8
401585131,Final,Final,2024-01-07,2024,Phoenix Suns,Memphis Grizzlies,115.0,121.0,"Phoenix, AZ",Footprint Center,1949.0,,Regular Season,None,None,PHX,21,false,MEM,29,true,None,19-17,11-11,None,13-23,None,10-10
401585132,Final,Final,2024-01-07,2024,Golden State Warriors,Toronto Raptors,118.0,133.0,"San Francisco, CA",Chase Center,6270.0,,Regular Season,None,None,GS,9,false,TOR,28,true,None,17-19,11-10,None,15-21,None,6-12
401585126,Final,Final/OT,2024-01-07,2024,Brooklyn Nets,Portland Trail Blazers,127.0,134.0,"Brooklyn, NY",Barclays Center,3559.0,,Regular Season,None,None,BKN,17,false,POR,22,true,None,16-21,10-9,None,10-25,None,5-14
401585128,Final,Final,2024-01-07,2024,Sacramento Kings,New Orleans Pelicans,100.0,133.0,"Sacramento, CA",Golden 1 Center,5310.0,,Regular Season,None,None,SAC,23,false,NO,3,true,None,21-14,13-7,None,22-15,None,10-7
191 changes: 191 additions & 0 deletions examples/fast-api-server/dummy-data/player_boxscores.csv

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions examples/fast-api-server/dummy-data/team_boxscores.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
game_id,team_abbr,pts,fg,fgm,fga,fg_pct,fg3,fg3m,fg3a,fg3_pct,ft,ftm,fta,ft_pct,oreb,dreb,reb,ast,stl,blk,tov,pts_off_tov,fst_brk_pts,pts_in_pnt,pf,tech_fl,flag_fl,opp_team_abbr,pts_opp,fg_opp,fgm_opp,fga_opp,fg_pct_opp,fg3_opp,fg3m_opp,fg3a_opp,fg3_pct_opp,ft_opp,ftm_opp,fta_opp,ft_pct_opp,oreb_opp,dreb_opp,reb_opp,ast_opp,stl_opp,blk_opp,tov_opp,pts_off_tov_opp,fst_brk_pts_opp,pts_in_pnt_opp,pf_opp,tech_fl_opp,flag_fl_opp,poss,poss_opp,ortg,drtg,net_rtg
401585128,NO,133,50-82,50,82,61.0,19-35,19,35,54.3,14-16,14,16,87.5,9,42,51,35,2,9,16,23.0,19.0,48.0,14,0.0,0.0,SAC,100,38-91,38,91,41.8,15-45,15,45,33.3,9-12,9,12,75.0,8,17,25,28,9,2,9,12.0,6.0,44.0,12,0.0,0.0,93.272893772893781,90.99967058823529,142.59233805250651,107.2122842500049,35.380053802501614
401585128,SAC,100,38-91,38,91,41.8,15-45,15,45,33.3,9-12,9,12,75.0,8,17,25,28,9,2,9,12.0,6.0,44.0,12,0.0,0.0,NO,133,50-82,50,82,61.0,19-35,19,35,54.3,14-16,14,16,87.5,9,42,51,35,2,9,16,23.0,19.0,48.0,14,0.0,0.0,90.99967058823529,93.272893772893781,109.89050768380287,146.15437521945782,-36.263867535654946
401585125,SA,115,41-86,41,86,47.7,14-37,14,37,37.8,19-22,19,22,86.4,8,32,40,22,10,6,11,18.0,21.0,44.0,18,0.0,0.0,CLE,117,43-88,43,88,48.9,16-43,16,43,37.2,15-21,15,21,71.4,12,32,44,27,6,3,16,22.0,20.0,50.0,16,2.0,0.0,95.256875000000008,96.515340909090909,120.72619430356076,122.82578029144877,-2.099585987888013
401585133,LAC,103,36-91,36,91,39.6,14-37,14,37,37.8,17-19,17,19,89.5,13,27,40,21,12,5,16,14.0,19.0,40.0,19,0.0,0.0,LAL,106,42-82,42,82,51.2,11-29,11,29,37.9,11-16,11,16,68.8,8,32,40,23,9,6,19,18.0,15.0,46.0,11,2.0,1.0,96.158703703703708,94.154665178571435,107.11458872966566,110.23443111985009,-3.1198423901844365
401585126,BKN,127,46-91,46,91,50.5,14-37,14,37,37.8,21-25,21,25,84.0,9,35,44,29,7,7,16,18.0,17.0,62.0,25,0.0,0.0,POR,134,45-95,45,95,47.4,20-38,20,38,52.6,24-30,24,30,80.0,9,29,38,21,5,5,10,13.0,7.0,38.0,20,1.0,0.0,104.41945488721805,104.05685736677117,121.62484485019661,128.32857645611296,-6.7037316059163485
401585131,MEM,121,43-97,43,97,44.3,17-49,17,49,34.7,18-24,18,24,75.0,15,39,54,29,7,8,18,18.0,15.0,48.0,24,0.0,0.0,PHX,115,46-102,46,102,45.1,8-28,8,28,28.6,15-22,15,22,68.2,16,34,50,29,5,6,12,12.0,12.0,62.0,27,1.0,0.0,102.56484039769754,102.23877540106952,117.9741513084013,112.12419339228224,5.8499579161190729
401585129,MIN,108,41-94,41,94,43.6,13-41,13,41,31.7,13-21,13,21,61.9,18,33,51,22,6,4,13,17.0,12.0,50.0,22,0.0,0.0,DAL,115,43-95,43,95,45.3,15-40,15,40,37.5,14-20,14,20,70.0,15,29,44,20,7,8,11,11.0,7.0,44.0,19,1.0,0.0,91.19518375241779,88.406594827586218,118.4273067459406,126.10315070169601,-7.6758439557554095
401585125,CLE,117,43-88,43,88,48.9,16-43,16,43,37.2,15-21,15,21,71.4,12,32,44,27,6,3,16,22.0,20.0,50.0,16,2.0,0.0,SA,115,41-86,41,86,47.7,14-37,14,37,37.8,19-22,19,22,86.4,8,32,40,22,10,6,11,18.0,21.0,44.0,18,0.0,0.0,96.515340909090909,95.256875000000008,121.22425191473329,119.1520424802934,2.0722094344398854
401585133,LAL,106,42-82,42,82,51.2,11-29,11,29,37.9,11-16,11,16,68.8,8,32,40,23,9,6,19,18.0,15.0,46.0,11,2.0,1.0,LAC,103,36-91,36,91,39.6,14-37,14,37,37.8,17-19,17,19,89.5,13,27,40,21,12,5,16,14.0,19.0,40.0,19,0.0,0.0,94.154665178571435,96.158703703703708,112.58072003013658,109.39447323683082,3.1862467933057523
401585130,DET,114,42-89,42,89,47.2,9-24,9,24,37.5,21-30,21,30,70.0,13,24,37,28,6,0,12,17.0,12.0,58.0,20,2.0,1.0,DEN,131,47-80,47,80,58.8,10-27,10,27,37.0,27-31,27,31,87.1,6,32,38,35,6,10,14,19.0,11.0,54.0,23,1.0,0.0,98.02213888888889,95.95384375,116.30025756653046,133.64327843171483,-17.343020865184368
401585132,TOR,133,55-94,55,94,58.5,15-33,15,33,45.5,8-14,8,14,57.1,9,36,45,38,7,6,7,12.0,24.0,66.0,14,2.0,0.0,GS,118,45-100,45,100,45.0,14-46,14,46,30.4,14-15,14,15,93.3,15,28,43,30,5,4,11,23.0,8.0,54.0,11,1.0,0.0,94.464313063063059,96.438981092436961,140.79391008878775,124.91489767275907,15.879012416028695
401585126,POR,134,45-95,45,95,47.4,20-38,20,38,52.6,24-30,24,30,80.0,9,29,38,21,5,5,10,13.0,7.0,38.0,20,1.0,0.0,BKN,127,46-91,46,91,50.5,14-37,14,37,37.8,21-25,21,25,84.0,9,35,44,29,7,7,16,18.0,17.0,62.0,25,0.0,0.0,104.05685736677117,104.41945488721805,128.77575144104887,122.04865994785976,6.72709149318912
401585131,PHX,115,46-102,46,102,45.1,8-28,8,28,28.6,15-22,15,22,68.2,16,34,50,29,5,6,12,12.0,12.0,62.0,27,1.0,0.0,MEM,121,43-97,43,97,44.3,17-49,17,49,34.7,18-24,18,24,75.0,15,39,54,29,7,8,18,18.0,15.0,48.0,24,0.0,0.0,102.23877540106952,102.56484039769754,112.48178545651574,118.35040034989916,-5.8686148933834295
401585129,DAL,115,43-95,43,95,45.3,15-40,15,40,37.5,14-20,14,20,70.0,15,29,44,20,7,8,11,11.0,7.0,44.0,19,1.0,0.0,MIN,108,41-94,41,94,43.6,13-41,13,41,31.7,13-21,13,21,61.9,18,33,51,22,6,4,13,17.0,12.0,50.0,22,0.0,0.0,88.406594827586218,91.19518375241779,130.08079343433283,122.16283209485169,7.9179613394811286
401585132,GS,118,45-100,45,100,45.0,14-46,14,46,30.4,14-15,14,15,93.3,15,28,43,30,5,4,11,23.0,8.0,54.0,11,1.0,0.0,TOR,133,55-94,55,94,58.5,15-33,15,33,45.5,8-14,8,14,57.1,9,36,45,38,7,6,7,12.0,24.0,66.0,14,2.0,0.0,96.438981092436961,94.464313063063059,122.35716166152436,137.91103814392153,-15.553876482397165
401585130,DEN,131,47-80,47,80,58.8,10-27,10,27,37.0,27-31,27,31,87.1,6,32,38,35,6,10,14,19.0,11.0,54.0,23,1.0,0.0,DET,114,42-89,42,89,47.2,9-24,9,24,37.5,21-30,21,30,70.0,13,24,37,28,6,0,12,17.0,12.0,58.0,20,2.0,1.0,95.95384375,98.02213888888889,136.52397327751655,118.80712178348769,17.716851494028866
401585127,ORL,117,43-98,43,98,43.9,17-41,17,41,41.5,14-22,14,22,63.6,13,44,57,25,8,3,13,10.0,11.0,42.0,24,1.0,0.0,ATL,110,42-91,42,91,46.2,9-30,9,30,30.0,17-29,17,29,58.6,8,42,50,21,9,10,13,17.0,15.0,60.0,23,1.0,0.0,105.97863636363635,104.55918498168498,110.39960884054678,103.79450403812091,6.6051048024258758
401585127,ATL,110,42-91,42,91,46.2,9-30,9,30,30.0,17-29,17,29,58.6,8,42,50,21,9,10,13,17.0,15.0,60.0,23,1.0,0.0,ORL,117,43-98,43,98,43.9,17-41,17,41,41.5,14-22,14,22,63.6,13,44,57,25,8,3,13,10.0,11.0,42.0,24,1.0,0.0,104.55918498168498,105.97863636363635,105.20357443420016,111.89834735274017,-6.6947729185400107
4 changes: 2 additions & 2 deletions examples/fast-api-server/fast_api_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@


hooli_assistant = Assistant(
libraries=["piedpiper", custom_python_lib, openapi_lib],
scope_description="""Only answer questions about Hooli company related matters.
libraries=["nba","piedpiper", custom_python_lib, openapi_lib],
scope_description="""Only answer questions about NBA related matters.
You're also allowed to answer questions that refer to anything in the current chat history.""", # noqa: E501
entity_embedding_model=entity_embedding_model,
)
Expand Down
123 changes: 123 additions & 0 deletions examples/fast-api-server/library/nba/game_recap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
display_name: Recap NBA game
description: |
Recap the NBA game (i.e. "Recap the Knicks game")
sample_questions:
- Recap the NBA game
parameters:
json_schema:
type: object
properties:
team:
type: string
format: STRING
description: NBA team name
required:
- team
type: DuckDBQueryFunction
dataset: 'dummy-data/'
data_table_output: False
sqls:
- |
SELECT date,home_team,away_team,home_team_abbr,away_team_abbr,home_team_winner,away_team_winner,home_team_score,away_team_score,venue,location,home_team_overall_record,away_team_overall_record,
CASE WHEN status_detail like '%3OT%' THEN '3OT' WHEN status_detail like '%2OT%' THEN '2OT' WHEN status_detail like '%OT%' THEN 'OT' ELSE NULL end as overtime_status
FROM "game_summaries.csv"
WHERE (
lower(home_team) like CONCAT('%',lower(:team),'%') or
lower(away_team) like CONCAT('%',lower(:team),'%') or
lower(home_team_abbr) like CONCAT('%',lower(:team),'%') or
lower(away_team_abbr) like CONCAT('%',lower(:team),'%')
)
- |
SELECT team_abbr,pts,fg_pct,fg3m,fg3_pct,ftm,ft_pct,oreb,dreb,reb,ast,stl,blk,tov,pts_off_tov,fst_brk_pts,pts_in_pnt,pf
FROM "team_boxscores.csv"
WHERE game_id in (
SELECT game_id
FROM "game_summaries.csv"
WHERE (
lower(home_team) like CONCAT('%',lower(:team),'%') or
lower(away_team) like CONCAT('%',lower(:team),'%') or
lower(home_team_abbr) like CONCAT('%',lower(:team),'%') or
lower(away_team_abbr) like CONCAT('%',lower(:team),'%')
)
)
ORDER BY team_abbr
- |
WITH ranked_players AS (
SELECT
player_name,
position,
team_abbr,
starter_flg,
mp,
fg,
fg3,
ft,
oreb,
dreb,
reb,
ast,
stl,
blk,
tov,
pf,
plus_minus,
pts,
ROW_NUMBER() OVER (
PARTITION BY team_abbr
ORDER BY
CAST(pts AS FLOAT) + 0.4 * CAST(SPLIT_PART(fg, '-', 1) AS FLOAT) + 0.7 * CAST(oreb AS FLOAT) +
0.3 * CAST(dreb AS FLOAT) + CAST(stl AS FLOAT) + 0.7 * CAST(ast AS FLOAT) + 0.7 * CAST(blk AS FLOAT) -
0.7 * CAST(SPLIT_PART(fg, '-', 2) AS FLOAT) - 0.4 * (CAST(SPLIT_PART(ft, '-', 2) AS FLOAT) - CAST(SPLIT_PART(ft, '-', 1) AS FLOAT)) -
0.4 * CAST(pf AS FLOAT) - CAST(tov AS FLOAT) DESC
) AS rn
FROM "player_boxscores.csv"
WHERE game_id IN (
SELECT game_id
FROM "game_summaries.csv"
WHERE (
lower(home_team) like CONCAT('%',lower(:team),'%') or
lower(away_team) like CONCAT('%',lower(:team),'%') or
lower(home_team_abbr) like CONCAT('%',lower(:team),'%') or
lower(away_team_abbr) like CONCAT('%',lower(:team),'%')
)
)
)
SELECT
player_name,
position,
team_abbr,
starter_flg,
mp,
fg,
fg3,
ft,
oreb,
dreb,
reb,
ast,
stl,
blk,
tov,
pf,
plus_minus,
pts
FROM ranked_players
WHERE rn <= 3
ORDER BY rn
LIMIT 4;

visualizations: []
summarization: |
Please provide a succinct yet engaging recap of the latest NBA game, strictly adhering to the provided format and utilizing the available high-level box score stats. The recap should be informative yet conversational, focusing on the statistics to explain the game's outcome:

INTRODUCTION: Introduce the teams, the game date, the final score, mention only if the game went into overtime (ignore if it didn't), the winner, the game location, the top scorer from the winning team, and the teams' updated records

MATCHUP BREAKDOWN: Use team stats to succinctly explain why the winning team prevailed. Avoid over-elaboration, but provide enough detail to give a clear understanding of how the game was won, highlighting critical statistical advantages for the winning team. Avoid overstating areas where the winning team was not statistically superior, unless to say that they overcame that category.

KEY PLAYERS: Identify the standout players from each team, using their box score stats. Briefly describe how their performance was instrumental to their team's efforts in the game. Focus on weaving the players' stats into the narrative without lengthy elaboration.

CONCLUSION: Summarize the game with a focus on the statistical strengths that led to the winning team's victory. The conclusion should be brief, tying together the key points from the game.

The aim is to balance between a dry listing of statistics and an overly narrative approach. Use the stats to support concise explanations of the game's dynamics and outcomes. Be particularly careful that the statistics are accurately presented and associate players correctly with their teams.

Note: Be VERY careful not to misrepresent statistics. If team had a lower 3 point percentage or fewer 3 pointers made, that means they DID NOT have the edge in three-point shooting. This statement is WRONG: "However, the Kings had the edge in three-point shooting, making 15 three-pointers compared to the Magic's 25. The Kings had a three-point percentage of 37.5%, while the Magic had an impressive 56.8% from beyond the arc."
19 changes: 9 additions & 10 deletions examples/next/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ export default function Home() {
<div className="relative flex w-full h-full overflow-hidden">
<div className="group w-full pl-0 animate-in duration-300 ease-in-out peer-[[data-state=open]]:lg:pl-[250px] peer-[[data-state=open]]:xl:pl-[300px]">
<OpenAssistantsChat
api={`${process.env.NEXT_PUBLIC_API_URL ||
'http://localhost:8000'}/v1alpha/assistants/hooli/chat`}
name="Example Assistant"
api={`https://openassistants-fast-api-server-pr-92.onrender.com/v1alpha/assistants/hooli/chat`}
name="NBA Recap Writing Assistant"
starterPrompts={[
{
title: 'Show recent purchases',
prompt: 'Show recent purchases',
title: 'Recap the Warriors game',
prompt: 'Recap the Warriors game',
},
{
title: 'Show spend all products',
prompt: 'Show spend all products',
title: 'Recap the Nuggets game',
prompt: 'Recap the Nuggets game',
},
{
title: 'What can I ask?',
prompt: 'What can I ask?',
title: 'Recap the Lakers game',
prompt: 'Recap the Lakers game',
},
]}
welcomeMessage="This is a simple starter for deploying a nextjs app with an open assistant chat widget. This is configured to use the example library which builds off a couple csvs of employee and purchase data"
welcomeMessage="Stay updated with last night's NBA games! This application offers concise recaps, focusing on team statistics and key player performances to summarize the game's results."
getToken={() => Promise.resolve('token')}
></OpenAssistantsChat>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
import asyncio
from typing import Annotated, Any, List, Literal, Sequence
from typing import Annotated, Any, List, Literal, Sequence, Optional

import jsonschema
import pandas as pd
Expand Down Expand Up @@ -77,6 +77,7 @@ class QueryFunction(BaseFunction, abc.ABC):
sqls: List[str]
visualizations: List[str]
summarization: str
data_table_output: Optional[bool] = True
suggested_follow_ups: Annotated[List[SuggestedPrompt], Field(default_factory=list)]

@abc.abstractmethod
Expand Down Expand Up @@ -159,14 +160,15 @@ async def execute(
results: List[FunctionOutput] = []

dataframes = await self._execute_sqls(deps)
results.extend(
[
DataFrameOutput(dataframe=SerializedDataFrame.from_pd(df))
for df in dataframes
]
)
if self.data_table_output:
results.extend(
[
DataFrameOutput(dataframe=SerializedDataFrame.from_pd(df))
for df in dataframes
]
)

yield results
yield results

visualizations = await self._execute_visualizations(dataframes, deps)

Expand Down