├── .gitignore
├── 10-distillation
├── itinerary.ipynb
└── plane.ipynb
├── 11-recommendation
├── README.md
├── app.py
├── config.py
├── docker-compose.yaml
├── helper_functions.py
├── images.zip
├── pages
│ ├── page_1_semantic_search.py
│ └── page_2_explainable_recommendations.py
├── requirements.txt
├── upload-data
│ └── fake_hardware_data.csv
└── upload-to-qdrant.py
├── 12-agentic-tool-calling
├── 0_task.py
├── 1_agent.py
├── 2_tools.py
├── 3_simple_server.py
├── 4_queue_server.py
├── 5_todos.py
├── 6_delegation.py
├── mock_api.py
├── server.py
├── server_agents.py
└── utils.py
├── 13-image-gen
└── imagegen-demo
│ ├── .gitignore
│ ├── README.md
│ ├── components.json
│ ├── eslint.config.mjs
│ ├── next.config.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── postcss.config.mjs
│ ├── public
│ ├── OpenAI-black-monoblossom.svg
│ ├── OpenAI-black-wordmark.svg
│ ├── OpenAI_Frontiers-2025.svg
│ ├── file.svg
│ ├── frontiers-2025.svg
│ ├── globe.svg
│ ├── next.svg
│ ├── vercel.svg
│ └── window.svg
│ ├── src
│ ├── app
│ │ ├── api
│ │ │ ├── edit
│ │ │ │ └── route.ts
│ │ │ ├── generate
│ │ │ │ └── route.ts
│ │ │ ├── process
│ │ │ │ └── route.ts
│ │ │ └── stream
│ │ │ │ └── route.ts
│ │ ├── favicon.ico
│ │ ├── globals.css
│ │ ├── layout.tsx
│ │ └── page.tsx
│ ├── components
│ │ ├── error-message.tsx
│ │ ├── image-remix-tool.tsx
│ │ ├── image-uploader.tsx
│ │ ├── loading-overlay.tsx
│ │ ├── modifier-grid.tsx
│ │ ├── option-card.tsx
│ │ └── result-gallery.tsx
│ └── lib
│ │ ├── imageProcessing.ts
│ │ └── utils.ts
│ ├── tailwind.config.js
│ └── tsconfig.json
├── 2-assistants
├── 0_setup.py
├── 1_routines.py
├── 2_tools.py
├── 3_tools.py
├── 4_tools.py
├── 5_escalation.py
├── 6_agents.py
├── 7_orchestration.py
├── README.md
└── demo_util.py
├── 3-4o_mini_fine_tuning
├── 0_generate_eval_data.py
├── 1_eval_baseline.py
├── 2_fine_tuning.py
├── 3_eval_fine_tune.py
├── README.md
├── prompts
│ ├── cot3.json
│ └── verbatim_input.txt
└── py
│ └── assert_last_line_answer.py
├── 4-mmrag_tooluse
├── config.py
├── database.py
├── docker-compose.yaml
├── earnings.db
├── earnings_report_all
│ ├── Webslides_Q120_4.28.20_Final.pdf
│ ├── Webslides_Q121_Final.pdf
│ ├── Webslides_Q122_Final.pdf
│ ├── Webslides_Q123_Final.pdf
│ ├── Webslides_Q124_Final.pdf
│ ├── Webslides_Q220_Final.pdf
│ ├── Webslides_Q221_Final.pdf
│ ├── Webslides_Q222_Final.pdf
│ ├── Webslides_Q223_Final.pdf
│ ├── Webslides_Q224_Final.pdf
│ ├── Webslides_Q320_Final.pdf
│ ├── Webslides_Q321_Final.pdf
│ ├── Webslides_Q322_Final.pdf
│ ├── Webslides_Q420_Final.pdf
│ ├── Webslides_Q421_Final.pdf
│ ├── Webslides_Q422_Final.pdf
│ └── Webslides_Q423_Final.pdf
├── earnings_reports_sample
│ └── Webslides_Q323.pdf
├── ingest.py
├── mmrag_bh.py
├── schema_definitions.py
└── table_json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q120.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q121.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q122.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q123.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q124.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q220.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q221.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q222.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q223.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q224.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q320.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q321.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q322.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q323.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q420.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q421.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q422.json
│ ├── Free_Cash_Flow_Less_Equipment_Finance_Leases_Q423.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q120.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q121.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q122.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q123.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q124.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q220.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q221.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q222.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q223.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q224.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q320.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q321.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q322.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q323.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q420.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q421.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q422.json
│ ├── Free_Cash_Flow_Less_Principal_Repayments_Q423.json
│ ├── Free_Cash_Flow_Reconciliation_Q120.json
│ ├── Free_Cash_Flow_Reconciliation_Q121.json
│ ├── Free_Cash_Flow_Reconciliation_Q122.json
│ ├── Free_Cash_Flow_Reconciliation_Q123.json
│ ├── Free_Cash_Flow_Reconciliation_Q124.json
│ ├── Free_Cash_Flow_Reconciliation_Q220.json
│ ├── Free_Cash_Flow_Reconciliation_Q221.json
│ ├── Free_Cash_Flow_Reconciliation_Q222.json
│ ├── Free_Cash_Flow_Reconciliation_Q223.json
│ ├── Free_Cash_Flow_Reconciliation_Q224.json
│ ├── Free_Cash_Flow_Reconciliation_Q320.json
│ ├── Free_Cash_Flow_Reconciliation_Q321.json
│ ├── Free_Cash_Flow_Reconciliation_Q322.json
│ ├── Free_Cash_Flow_Reconciliation_Q323.json
│ ├── Free_Cash_Flow_Reconciliation_Q420.json
│ ├── Free_Cash_Flow_Reconciliation_Q421.json
│ ├── Free_Cash_Flow_Reconciliation_Q422.json
│ └── Free_Cash_Flow_Reconciliation_Q423.json
├── 5-4o_fine_tuning
├── .gitignore
├── README.md
├── data_explorer.py
├── data_validator.py
├── eval.py
├── example.py
├── example_cot.py
├── logs
│ ├── ft_gpt-3*5-turbo-0125_openai-gtm_vulnfixes0821_9ym18NbR-0-shot_20240823_0037.log
│ ├── ft_gpt-4o-2024-08-06_openai-gtm_vulnfixes-cot-0822_9zGknzVV-0-shot_20240822_2220.log
│ ├── ft_gpt-4o-2024-08-06_openai-gtm_vulnfixes-cot-0822_9zGknzVV-5-shot-sim_20240823_0000.log
│ ├── ft_gpt-4o-2024-08-06_openai-gtm_vulnfixes0821-long_9ymKVX9n-0-shot_20240825_2220.log
│ ├── ft_gpt-4o-mini-2024-07-18_openai-gtm_vulnfixes0822_9zILpnPW-0-shot_20240823_0027.log
│ ├── gpt-4o-0-shot_20240823_0018.log
│ ├── gpt-4o-5-shot_20240822_2310.log
│ └── gpt-4o-mini-0-shot_20240822_2322.log
├── reasoning.py
├── requirements.txt
├── static-vuln-fixes-eval.jsonl
├── synth-vuln-fixes-train-coft-commments-0822.jsonl
├── synth-vuln-fixes-train.jsonl
└── util.py
├── 6-structured_outputs
├── node-example
│ ├── app.js
│ ├── input.js
│ ├── package-lock.json
│ └── package.json
├── python-example
│ ├── data
│ │ ├── __init__.py
│ │ └── input.py
│ ├── main.py
│ └── requirements.txt
├── structured-outputs-assistant-final
│ ├── .eslintrc.json
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ ├── api
│ │ │ ├── assistant
│ │ │ │ ├── get_products
│ │ │ │ │ └── route.ts
│ │ │ │ ├── search_products
│ │ │ │ │ └── route.ts
│ │ │ │ └── turn_response
│ │ │ │ │ └── route.ts
│ │ │ └── db
│ │ │ │ ├── init
│ │ │ │ └── route.ts
│ │ │ │ └── route.ts
│ │ ├── favicon.ico
│ │ ├── globals.css
│ │ ├── layout.tsx
│ │ └── page.tsx
│ ├── components.json
│ ├── components
│ │ ├── assistant.tsx
│ │ ├── cart.tsx
│ │ ├── chat.tsx
│ │ ├── main-view.tsx
│ │ ├── message.css
│ │ ├── message.tsx
│ │ ├── tool-results.tsx
│ │ └── ui
│ │ │ ├── badge.tsx
│ │ │ ├── breadcrumb.tsx
│ │ │ ├── button.tsx
│ │ │ ├── card.tsx
│ │ │ ├── chart.tsx
│ │ │ ├── checkbox.tsx
│ │ │ ├── drawer.tsx
│ │ │ ├── dropdown-menu.tsx
│ │ │ ├── input.tsx
│ │ │ ├── label.tsx
│ │ │ ├── select.tsx
│ │ │ ├── sheet.tsx
│ │ │ ├── spinner.css
│ │ │ ├── spinner.tsx
│ │ │ ├── table.tsx
│ │ │ ├── textarea.tsx
│ │ │ ├── toggle-group.tsx
│ │ │ └── toggle.tsx
│ ├── data
│ │ ├── amazon_furniture_db.json
│ │ └── database.sqlite
│ ├── lib
│ │ ├── assistant.ts
│ │ ├── components-mapping.tsx
│ │ ├── database.ts
│ │ ├── tools.ts
│ │ └── utils.ts
│ ├── next.config.mjs
│ ├── package-lock.json
│ ├── package.json
│ ├── pnpm-lock.yaml
│ ├── postcss.config.mjs
│ ├── prettier.config.cjs
│ ├── public
│ │ └── imgs
│ │ │ └── user_profile.png
│ ├── tailwind.config.ts
│ └── tsconfig.json
├── structured-outputs-assistant-starting-point
│ ├── .eslintrc.json
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ ├── api
│ │ │ ├── assistant
│ │ │ │ ├── get_products
│ │ │ │ │ └── route.ts
│ │ │ │ ├── search_products
│ │ │ │ │ └── route.ts
│ │ │ │ └── turn_response
│ │ │ │ │ └── route.ts
│ │ │ └── db
│ │ │ │ ├── init
│ │ │ │ └── route.ts
│ │ │ │ └── route.ts
│ │ ├── favicon.ico
│ │ ├── globals.css
│ │ ├── layout.tsx
│ │ └── page.tsx
│ ├── components.json
│ ├── components
│ │ ├── assistant.tsx
│ │ ├── cart.tsx
│ │ ├── chat.tsx
│ │ ├── main-view.tsx
│ │ ├── message.css
│ │ ├── message.tsx
│ │ ├── tool-results.tsx
│ │ └── ui
│ │ │ ├── badge.tsx
│ │ │ ├── breadcrumb.tsx
│ │ │ ├── button.tsx
│ │ │ ├── card.tsx
│ │ │ ├── chart.tsx
│ │ │ ├── checkbox.tsx
│ │ │ ├── drawer.tsx
│ │ │ ├── dropdown-menu.tsx
│ │ │ ├── input.tsx
│ │ │ ├── label.tsx
│ │ │ ├── select.tsx
│ │ │ ├── sheet.tsx
│ │ │ ├── spinner.css
│ │ │ ├── spinner.tsx
│ │ │ ├── table.tsx
│ │ │ ├── textarea.tsx
│ │ │ ├── toggle-group.tsx
│ │ │ └── toggle.tsx
│ ├── data
│ │ ├── amazon_furniture_db.json
│ │ └── database.sqlite
│ ├── lib
│ │ ├── assistant.ts
│ │ ├── components-mapping.tsx
│ │ ├── database.ts
│ │ ├── tools.ts
│ │ └── utils.ts
│ ├── next.config.mjs
│ ├── package-lock.json
│ ├── package.json
│ ├── pnpm-lock.yaml
│ ├── postcss.config.mjs
│ ├── prettier.config.cjs
│ ├── public
│ │ └── imgs
│ │ │ └── user_profile.png
│ ├── tailwind.config.ts
│ └── tsconfig.json
├── structured-outputs-math-tutor-final
│ ├── .eslintrc.json
│ ├── .gitignore
│ ├── LICENSE
│ ├── README.md
│ ├── app
│ │ ├── api
│ │ │ └── math_responses
│ │ │ │ └── route.ts
│ │ ├── globals.css
│ │ ├── layout.tsx
│ │ └── page.tsx
│ ├── components.json
│ ├── components
│ │ ├── problem-card.tsx
│ │ ├── prompt-form.tsx
│ │ ├── sidebar.tsx
│ │ ├── solution.tsx
│ │ ├── step.tsx
│ │ ├── stepper.tsx
│ │ └── ui
│ │ │ ├── badge.tsx
│ │ │ ├── confetti.tsx
│ │ │ ├── icons.tsx
│ │ │ ├── spinner.css
│ │ │ ├── spinner.tsx
│ │ │ └── warning.tsx
│ ├── lib
│ │ ├── actions.ts
│ │ └── useSolution.ts
│ ├── next-env.d.ts
│ ├── next.config.js
│ ├── package.json
│ ├── pnpm-lock.yaml
│ ├── postcss.config.js
│ ├── prettier.config.cjs
│ ├── public
│ │ ├── apple-touch-icon.png
│ │ ├── avatar.png
│ │ ├── favicon-16x16.png
│ │ ├── favicon.ico
│ │ └── screenshot.png
│ ├── tailwind.config.ts
│ └── tsconfig.json
└── structured-outputs-math-tutor-starting-point
│ ├── .eslintrc.json
│ ├── .gitignore
│ ├── LICENSE
│ ├── README.md
│ ├── app
│ ├── api
│ │ └── math_responses
│ │ │ └── route.ts
│ ├── globals.css
│ ├── layout.tsx
│ └── page.tsx
│ ├── components.json
│ ├── components
│ ├── problem-card.tsx
│ ├── prompt-form.tsx
│ ├── sidebar.tsx
│ ├── solution.tsx
│ ├── step.tsx
│ ├── stepper.tsx
│ └── ui
│ │ ├── badge.tsx
│ │ ├── confetti.tsx
│ │ ├── icons.tsx
│ │ ├── spinner.css
│ │ ├── spinner.tsx
│ │ └── warning.tsx
│ ├── lib
│ ├── actions.ts
│ └── useSolution.ts
│ ├── next-env.d.ts
│ ├── next.config.js
│ ├── package.json
│ ├── pnpm-lock.yaml
│ ├── postcss.config.js
│ ├── prettier.config.cjs
│ ├── public
│ ├── apple-touch-icon.png
│ ├── avatar.png
│ ├── favicon-16x16.png
│ ├── favicon.ico
│ └── screenshot.png
│ ├── tailwind.config.ts
│ └── tsconfig.json
├── 7-reasoning
├── flightCancellationPolicy
│ ├── evals
│ │ └── functionCallingEval.csv
│ ├── evalsAndPromptImprovements.ipynb
│ ├── functionDefinitions.py
│ └── originalPolicy
│ │ └── flightCancellationsPolicy.md
└── shipmentPlanning
│ ├── ReadMe.md
│ ├── backend
│ ├── app.py
│ ├── functionDefinitions.py
│ └── requirements.txt
│ └── frontend
│ ├── .gitignore
│ ├── README.md
│ ├── package.json
│ ├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
│ └── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── ExecutionStream.js
│ ├── PlanDisplay.js
│ ├── ScenarioInput.js
│ ├── assets
│ └── logos
│ │ └── shippingLogo.jpg
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ ├── reportWebVitals.js
│ ├── setupTests.js
│ └── theme.js
├── 8-evals
├── 01_create_stanbot_draft_datasett.py
├── 02_stanbot_eval.py
├── 03_create_summary_grader_dataset.py
├── 04_summary_grader_eval.py
├── data
│ ├── draft_stanbot_outputs_n=18.csv
│ ├── draft_summary_grader_outputs_n=12.csv
│ ├── pfoo_eval_stanbot.yaml
│ ├── pfoo_eval_summary_grader.yaml
│ ├── reviewed_stanbot_outputs_n=18.csv
│ └── reviewed_summary_grader_outputs_n=12.csv
└── utils
│ └── constants.py
├── 9-realtime
├── .gitignore
├── README.md
├── openai-realtime-console-example
│ ├── .eslintrc.json
│ ├── .gitignore
│ ├── .prettierrc
│ ├── LICENSE
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ ├── openai-logomark.svg
│ │ └── robots.txt
│ ├── readme
│ │ └── realtime-console-demo.png
│ ├── relay-server
│ │ ├── index.js
│ │ └── lib
│ │ │ └── relay.js
│ ├── src
│ │ ├── App.scss
│ │ ├── App.tsx
│ │ ├── components
│ │ │ ├── Map.scss
│ │ │ ├── Map.tsx
│ │ │ ├── button
│ │ │ │ ├── Button.scss
│ │ │ │ └── Button.tsx
│ │ │ └── toggle
│ │ │ │ ├── Toggle.scss
│ │ │ │ └── Toggle.tsx
│ │ ├── index.css
│ │ ├── index.tsx
│ │ ├── lib
│ │ │ └── wavtools
│ │ │ │ ├── dist
│ │ │ │ ├── index.d.ts
│ │ │ │ ├── index.d.ts.map
│ │ │ │ └── lib
│ │ │ │ │ ├── analysis
│ │ │ │ │ ├── audio_analysis.d.ts
│ │ │ │ │ ├── audio_analysis.d.ts.map
│ │ │ │ │ ├── constants.d.ts
│ │ │ │ │ └── constants.d.ts.map
│ │ │ │ │ ├── wav_packer.d.ts
│ │ │ │ │ ├── wav_packer.d.ts.map
│ │ │ │ │ ├── wav_recorder.d.ts
│ │ │ │ │ ├── wav_recorder.d.ts.map
│ │ │ │ │ ├── wav_stream_player.d.ts
│ │ │ │ │ ├── wav_stream_player.d.ts.map
│ │ │ │ │ └── worklets
│ │ │ │ │ ├── audio_processor.d.ts
│ │ │ │ │ ├── audio_processor.d.ts.map
│ │ │ │ │ ├── stream_processor.d.ts
│ │ │ │ │ └── stream_processor.d.ts.map
│ │ │ │ ├── index.js
│ │ │ │ └── lib
│ │ │ │ ├── analysis
│ │ │ │ ├── audio_analysis.js
│ │ │ │ └── constants.js
│ │ │ │ ├── wav_packer.js
│ │ │ │ ├── wav_recorder.js
│ │ │ │ ├── wav_stream_player.js
│ │ │ │ └── worklets
│ │ │ │ ├── audio_processor.js
│ │ │ │ └── stream_processor.js
│ │ ├── logo.svg
│ │ ├── pages
│ │ │ ├── ConsolePage.scss
│ │ │ └── ConsolePage.tsx
│ │ ├── react-app-env.d.ts
│ │ ├── reportWebVitals.ts
│ │ ├── setupTests.ts
│ │ └── utils
│ │ │ ├── conversation_config.js
│ │ │ └── wav_renderer.ts
│ └── tsconfig.json
└── realtime-from-scratch
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ ├── favicon.ico
│ ├── fonts
│ │ ├── GeistMonoVF.woff
│ │ └── GeistVF.woff
│ ├── globals.css
│ ├── hooks
│ │ ├── useAudioPlayer.ts
│ │ └── useMicrophone.ts
│ ├── layout.tsx
│ └── page.tsx
│ ├── next.config.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── postcss.config.mjs
│ ├── public
│ ├── file.svg
│ ├── globe.svg
│ ├── next.svg
│ ├── vercel.svg
│ └── window.svg
│ ├── tailwind.config.ts
│ └── tsconfig.json
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | __pycache__/
3 | .DS_Store
4 | __pycache__/
5 |
6 | 3-4o_mini_fine_tuning/evals/*
7 | 3-4o_mini_fine_tuning/data/*
8 |
9 | 11-recommendation/images
10 |
11 | .venv/
12 |
--------------------------------------------------------------------------------
/11-recommendation/app.py:
--------------------------------------------------------------------------------
1 | # app.py
2 | import streamlit as st
3 |
4 |
5 | # Set the page configuration
6 | st.set_page_config(
7 | page_title="Recommendations with LLMs",
8 | page_icon=":rocket:", # You can use any emoji or a local image file
9 | layout="wide", # "centered" or "wide"
10 | initial_sidebar_state="expanded" # "auto", "expanded", "collapsed"
11 | )
12 |
13 | # Main content of the home page
14 | st.title("Welcome to the Recommendation System App")
15 | st.write("""
16 | This application leverages GPT-4o to provide personalized recommendations based on your past purchases and queries.
17 | Use the sidebar to navigate to different functionalities.
18 | """)
19 |
--------------------------------------------------------------------------------
/11-recommendation/config.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | class Config:
4 | OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
5 | QDRANT_HOST = 'localhost'
6 | QDRANT_PORT = 6333
7 | CSV_FILE_PATH = "upload-data/fake_hardware_data.csv"
8 | COLLECTION_NAME = "fake_hardware_data"
9 | EMBEDDING_MODEL = "text-embedding-3-small"
10 | VECTOR_SIZE = 1536
11 | MAX_WORKERS = 100
12 | BATCH_SIZE = 100
13 |
--------------------------------------------------------------------------------
/11-recommendation/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '3.4'
2 | services:
3 | qdrant:
4 | image: qdrant/qdrant:v1.3.0
5 | restart: on-failure
6 | ports:
7 | - "6333:6333"
8 | volumes:
9 | - qdrant_storage:/qdrant/storage
10 |
11 | volumes:
12 | qdrant_storage:
--------------------------------------------------------------------------------
/11-recommendation/images.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/11-recommendation/images.zip
--------------------------------------------------------------------------------
/11-recommendation/requirements.txt:
--------------------------------------------------------------------------------
1 | altair==5.5.0
2 | annotated-types==0.7.0
3 | anyio==4.6.2.post1
4 | attrs==24.2.0
5 | blinker==1.9.0
6 | cachetools==5.5.0
7 | certifi==2024.8.30
8 | charset-normalizer==3.4.0
9 | click==8.1.7
10 | distro==1.9.0
11 | gitdb==4.0.11
12 | GitPython==3.1.43
13 | grpcio==1.68.0
14 | grpcio-tools==1.68.0
15 | h11==0.14.0
16 | h2==4.1.0
17 | hpack==4.0.0
18 | httpcore==1.0.7
19 | httpx==0.27.2
20 | hyperframe==6.0.1
21 | idna==3.10
22 | Jinja2==3.1.4
23 | jiter==0.7.1
24 | jsonschema==4.23.0
25 | jsonschema-specifications==2024.10.1
26 | markdown-it-py==3.0.0
27 | MarkupSafe==3.0.2
28 | mdurl==0.1.2
29 | narwhals==1.14.2
30 | numpy==2.1.3
31 | openai==1.55.0
32 | packaging==24.2
33 | pandas==2.2.3
34 | pillow==11.0.0
35 | portalocker==2.10.1
36 | protobuf==5.28.3
37 | pyarrow==18.0.0
38 | pydantic==2.10.1
39 | pydantic_core==2.27.1
40 | pydeck==0.9.1
41 | Pygments==2.18.0
42 | python-dateutil==2.9.0.post0
43 | pytz==2024.2
44 | qdrant-client==1.12.1
45 | referencing==0.35.1
46 | requests==2.32.3
47 | rich==13.9.4
48 | rpds-py==0.21.0
49 | six==1.16.0
50 | smmap==5.0.1
51 | sniffio==1.3.1
52 | streamlit==1.40.1
53 | tenacity==9.0.0
54 | toml==0.10.2
55 | tornado==6.4.2
56 | tqdm==4.67.1
57 | typing_extensions==4.12.2
58 | tzdata==2024.2
59 | urllib3==2.2.3
--------------------------------------------------------------------------------
/12-agentic-tool-calling/0_task.py:
--------------------------------------------------------------------------------
1 | from openai import OpenAI
2 |
3 | client = OpenAI()
4 |
5 | response = client.responses.create(
6 | input="Hello, world!",
7 | model="o3",
8 | background=True,
9 | )
10 |
11 | print(response)
12 |
--------------------------------------------------------------------------------
/12-agentic-tool-calling/1_agent.py:
--------------------------------------------------------------------------------
1 | from agents import Agent, function_tool
2 | from utils import run_demo_loop
3 |
4 |
5 | agent = Agent(
6 | name="Assistant",
7 | model="o3",
8 | )
9 |
10 | run_demo_loop(agent)
11 |
--------------------------------------------------------------------------------
/12-agentic-tool-calling/2_tools.py:
--------------------------------------------------------------------------------
1 | from agents import Agent, function_tool as tool
2 | from utils import run_demo_loop
3 | from mock_api import MockAPI
4 | from typing import Optional
5 |
6 | mock_api = MockAPI()
7 |
8 |
9 | @tool
10 | def search_policies(query: str):
11 | return mock_api.search_policies(query)
12 |
13 |
14 | @tool
15 | def get_emails(to: Optional[str] = None):
16 | return mock_api.get_emails(to)
17 |
18 |
19 | @tool
20 | def send_email(from_addr: str, to_addr: str, subject: str, body: str):
21 | return mock_api.send_email(from_addr, to_addr, subject, body)
22 |
23 |
24 | agent = Agent(
25 | name="Assistant",
26 | model="o3",
27 | tools=[search_policies, get_emails, send_email],
28 | )
29 |
30 | run_demo_loop(agent)
31 |
--------------------------------------------------------------------------------
/12-agentic-tool-calling/3_simple_server.py:
--------------------------------------------------------------------------------
1 | from fastapi import FastAPI, Request
2 | from fastapi.responses import StreamingResponse
3 | from utils import encode_sse, to_dict
4 | from agents import Runner
5 | import uvicorn
6 | from server_agents import agent
7 |
8 | app = FastAPI()
9 |
10 |
11 | @app.post("/")
12 | async def endpoint(request: Request):
13 | body = await request.json()
14 |
15 | async def event_stream():
16 | run = Runner.run_streamed(
17 | agent,
18 | input=body.get("items", []),
19 | previous_response_id=body.get("previousResponseId"),
20 | )
21 | async for ev in run.stream_events():
22 | if ev.type == "raw_response_event":
23 | yield encode_sse(ev.type, to_dict(ev.data))
24 | yield encode_sse("done", {})
25 |
26 | return StreamingResponse(event_stream(), media_type="text/event-stream")
27 |
28 |
29 | if __name__ == "__main__":
30 | uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True)
31 |
--------------------------------------------------------------------------------
/12-agentic-tool-calling/6_delegation.py:
--------------------------------------------------------------------------------
1 | from agents import Agent, function_tool
2 | from utils import run_demo_loop
3 | from openai import OpenAI
4 |
5 |
6 | client = OpenAI()
7 |
8 |
9 | @function_tool
10 | def search_web(query: str):
11 | return "This is a test"
12 |
13 |
14 | @function_tool
15 | def start_task(description: str):
16 | response = client.responses.create(
17 | input=description,
18 | model="o3",
19 | background=True,
20 | )
21 | return response.id
22 |
23 |
24 | @function_tool
25 | def get_tasks(id: str):
26 | response = client.responses.retrieve(response_id=id)
27 | return response.output
28 |
29 |
30 | agent = Agent(
31 | name="Assistant",
32 | model="gpt-4.1-mini",
33 | tools=[search_web],
34 | )
35 |
36 | run_demo_loop(agent)
37 |
--------------------------------------------------------------------------------
/12-agentic-tool-calling/server.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/12-agentic-tool-calling/server.py
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.*
7 | .yarn/*
8 | !.yarn/patches
9 | !.yarn/plugins
10 | !.yarn/releases
11 | !.yarn/versions
12 |
13 | # testing
14 | /coverage
15 |
16 | # next.js
17 | /.next/
18 | /out/
19 |
20 | # production
21 | /build
22 |
23 | # misc
24 | .DS_Store
25 | *.pem
26 |
27 | # debug
28 | npm-debug.log*
29 | yarn-debug.log*
30 | yarn-error.log*
31 | .pnpm-debug.log*
32 |
33 | # env files (can opt-in for committing if needed)
34 | .env*
35 |
36 | # vercel
37 | .vercel
38 |
39 | # typescript
40 | *.tsbuildinfo
41 | next-env.d.ts
42 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/components.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://ui.shadcn.com/schema.json",
3 | "style": "new-york",
4 | "rsc": true,
5 | "tsx": true,
6 | "tailwind": {
7 | "config": "tailwind.config.js",
8 | "css": "src/app/globals.css",
9 | "baseColor": "neutral",
10 | "cssVariables": true,
11 | "prefix": ""
12 | },
13 | "aliases": {
14 | "components": "@/components",
15 | "utils": "@/lib/utils",
16 | "ui": "@/components/ui",
17 | "lib": "@/lib",
18 | "hooks": "@/hooks"
19 | },
20 | "iconLibrary": "lucide"
21 | }
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/eslint.config.mjs:
--------------------------------------------------------------------------------
1 | import { dirname } from "path";
2 | import { fileURLToPath } from "url";
3 | import { FlatCompat } from "@eslint/eslintrc";
4 |
5 | const __filename = fileURLToPath(import.meta.url);
6 | const __dirname = dirname(__filename);
7 |
8 | const compat = new FlatCompat({
9 | baseDirectory: __dirname,
10 | });
11 |
12 | const eslintConfig = [
13 | ...compat.extends("next/core-web-vitals", "next/typescript"),
14 | ];
15 |
16 | export default eslintConfig;
17 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/next.config.ts:
--------------------------------------------------------------------------------
1 | import type { NextConfig } from "next";
2 |
3 | const nextConfig: NextConfig = {
4 | /* config options here */
5 | };
6 |
7 | export default nextConfig;
8 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontiers",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev --turbopack",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "@ai-sdk/openai": "^1.3.20",
13 | "ai": "^4.3.10",
14 | "class-variance-authority": "^0.7.1",
15 | "clsx": "^2.1.1",
16 | "lucide-react": "^0.503.0",
17 | "next": "15.3.1",
18 | "openai": "^4.96.0",
19 | "react": "^19.0.0",
20 | "react-dom": "^19.0.0",
21 | "react-dropzone": "^14.3.8",
22 | "sharp": "^0.32.0",
23 | "tailwind-merge": "^3.2.0",
24 | "zod": "^3.24.3"
25 | },
26 | "devDependencies": {
27 | "@eslint/eslintrc": "^3",
28 | "@tailwindcss/postcss": "^4",
29 | "@types/node": "^20",
30 | "@types/react": "^19",
31 | "@types/react-dom": "^19",
32 | "autoprefixer": "^10.4.21",
33 | "eslint": "^9",
34 | "eslint-config-next": "15.3.1",
35 | "postcss": "^8.5.3",
36 | "tailwindcss": "^4.1.4",
37 | "tw-animate-css": "^1.2.8",
38 | "typescript": "^5"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/postcss.config.mjs:
--------------------------------------------------------------------------------
1 | const config = {
2 | plugins: ["@tailwindcss/postcss"],
3 | };
4 |
5 | export default config;
6 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/public/OpenAI_Frontiers-2025.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/public/file.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/public/globe.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/public/next.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/public/vercel.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/public/window.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/13-image-gen/imagegen-demo/src/app/favicon.ico
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/app/globals.css:
--------------------------------------------------------------------------------
1 | @import "tailwindcss";
2 |
3 |
4 | :root {
5 | --background: #ffffff;
6 | --foreground: #171717;
7 | }
8 |
9 | @theme inline {
10 | --color-background: var(--background);
11 | --color-foreground: var(--foreground);
12 | --font-sans: var(--font-geist-sans);
13 | --font-mono: var(--font-geist-mono);
14 | }
15 |
16 | @media (prefers-color-scheme: dark) {
17 | :root {
18 | --background: #0a0a0a;
19 | --foreground: #ededed;
20 | }
21 | }
22 |
23 | body {
24 | background: var(--background);
25 | color: var(--foreground);
26 | font-family: Arial, Helvetica, sans-serif;
27 | }
28 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import type { Metadata } from "next";
2 | import { Geist, Geist_Mono } from "next/font/google";
3 | import "./globals.css";
4 |
5 | const geistSans = Geist({
6 | variable: "--font-geist-sans",
7 | subsets: ["latin"],
8 | });
9 |
10 | const geistMono = Geist_Mono({
11 | variable: "--font-geist-mono",
12 | subsets: ["latin"],
13 | });
14 |
15 | export const metadata: Metadata = {
16 | title: "Create Next App",
17 | description: "Generated by create next app",
18 | };
19 |
20 | export default function RootLayout({
21 | children,
22 | }: Readonly<{
23 | children: React.ReactNode;
24 | }>) {
25 | return (
26 |
27 |
30 | {children}
31 |
32 |
33 | );
34 | }
35 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/app/page.tsx:
--------------------------------------------------------------------------------
1 | import { Suspense } from "react"
2 | import ImageRemixTool from "@/components/image-remix-tool"
3 | import LoadingOverlay from "@/components/loading-overlay"
4 |
5 | export default function Home() {
6 | return (
7 |
8 |
9 |
10 |
15 |
16 |
17 |
}>
18 |
19 |
20 |
21 |
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/components/error-message.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import { XCircle } from "lucide-react"
4 |
5 | interface ErrorMessageProps {
6 | message: string
7 | onDismiss?: () => void
8 | }
9 |
10 | export default function ErrorMessage({ message, onDismiss }: ErrorMessageProps) {
11 | return (
12 |
13 |
14 |
15 |
16 |
17 |
20 | {onDismiss && (
21 |
25 | )}
26 |
27 |
28 | )
29 | }
30 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/components/loading-overlay.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | interface LoadingOverlayProps {
4 | message?: string
5 | }
6 |
7 | export default function LoadingOverlay({ message = "Loading..." }: LoadingOverlayProps) {
8 | return (
9 |
15 | )
16 | }
17 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/components/result-gallery.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | interface ResultGalleryProps {
4 | images: { url: string; id: string | null }[]
5 | selectedIndex: number | null
6 | onSelect: (index: number) => void
7 | onPreview: (index: number) => void
8 | }
9 |
10 | export default function ResultGallery({ images, selectedIndex, onSelect, onPreview }: ResultGalleryProps) {
11 | return (
12 |
13 | {images.map((image, index) => (
14 |
{ onPreview(index); }}
20 | >
21 | {image.url ? (
22 |

23 | ) : (
24 |
25 | Generating...
26 |
27 | )}
28 |
{ e.stopPropagation(); onSelect(index); }}
33 | >
34 | {selectedIndex === index && (
35 |
38 | )}
39 |
40 |
41 | ))}
42 |
43 | )
44 | }
45 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/src/lib/utils.ts:
--------------------------------------------------------------------------------
1 | import { clsx, type ClassValue } from "clsx"
2 | import { twMerge } from "tailwind-merge"
3 |
4 | export function cn(...inputs: ClassValue[]) {
5 | return twMerge(clsx(inputs))
6 | }
7 |
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/tailwind.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('tailwindcss').Config} */
2 | module.exports = {
3 | content: [
4 | "./app/**/*.{ts,tsx}",
5 | "./pages/**/*.{ts,tsx}",
6 | "./components/**/*.{ts,tsx}"
7 | ],
8 | theme: {
9 | extend: {},
10 | },
11 | plugins: [],
12 | }
--------------------------------------------------------------------------------
/13-image-gen/imagegen-demo/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2017",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "noEmit": true,
9 | "esModuleInterop": true,
10 | "module": "esnext",
11 | "moduleResolution": "bundler",
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "jsx": "preserve",
15 | "incremental": true,
16 | "plugins": [
17 | {
18 | "name": "next"
19 | }
20 | ],
21 | "paths": {
22 | "@/*": ["./src/*"]
23 | }
24 | },
25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "single_image.js"],
26 | "exclude": ["node_modules"]
27 | }
28 |
--------------------------------------------------------------------------------
/2-assistants/0_setup.py:
--------------------------------------------------------------------------------
1 | from openai import OpenAI
2 | from demo_util import color
3 |
4 |
5 | client = OpenAI()
6 |
7 | # === Demo Loop ===
8 |
9 | model = "gpt-4o-mini"
10 | system_message = "You are a helpful Assistant."
11 |
12 | messages = []
13 | while True:
14 | # get user input
15 | user = input(color("User: ", "blue") + "\033[90m")
16 | messages.append({"role": "user", "content": user})
17 |
18 | # get model completion
19 | response = client.chat.completions.create(
20 | model=model,
21 | messages=[{"role": "system", "content": system_message}] + messages,
22 | )
23 | message = response.choices[0].message
24 | print(color("Assistant:", "yellow"), message.content)
25 |
26 | # add message to history
27 | messages.append(message)
28 |
--------------------------------------------------------------------------------
/2-assistants/1_routines.py:
--------------------------------------------------------------------------------
1 | from openai import OpenAI
2 | from demo_util import color
3 |
4 |
5 | client = OpenAI()
6 |
7 | # === Demo Loop ===
8 |
9 | model = "gpt-4o-mini"
10 | system_message = (
11 | "You are a customer support agent for ACME Inc."
12 | "Always answer in a sentence or less."
13 | "Follow the following routine with the user:"
14 | "1. First, ask probing questions and understand the user's problem deeper.\n"
15 | " - unless the user has already provided a reason.\n"
16 | "2. Propose a fix (make one up).\n"
17 | "3. ONLY if not satisfied, offer a refund.\n"
18 | "4. If accepted, search for the ID and then execute refund."
19 | ""
20 | )
21 |
22 |
23 | messages = []
24 | while True:
25 | user = input(color("User: ", "blue") + "\033[90m")
26 | messages.append({"role": "user", "content": user})
27 |
28 | response = client.chat.completions.create(
29 | model=model,
30 | messages=[{"role": "system", "content": system_message}] + messages,
31 | )
32 | message = response.choices[0].message
33 | print(color("Assistant:", "yellow"), message.content)
34 |
35 | messages.append(message)
36 |
--------------------------------------------------------------------------------
/2-assistants/README.md:
--------------------------------------------------------------------------------
1 | # Assistants, Agents, and Orchestration
2 |
3 | Demo code used in the Assistants Build Hours.
4 |
5 | For an in-depth walkthrough, check out the [recording](https://vimeo.com/990334325/56b552bc7a).
6 |
7 | ## Setup
8 |
9 | 1. Set your OpenAI key.
10 |
11 | ```bash
12 | export OPENAI_API_KEY="sk_XXX..."
13 | ```
14 |
15 | 2. Run.
16 |
17 | ```bash
18 | python 7_orchestration.py
19 | ```
20 |
--------------------------------------------------------------------------------
/3-4o_mini_fine_tuning/1_eval_baseline.py:
--------------------------------------------------------------------------------
1 | # %%
2 | import pandas as pd
3 | import os
4 | import yaml
5 |
6 | run_name = "customer_service_chat_triage_n=100"
7 | df = pd.read_csv("./data/{}.csv".format(run_name))
8 |
9 | # Generate promptfoo eval file
10 | n_rows = len(df)
11 |
12 | output_dict = {
13 | "description": run_name,
14 | "prompts": ["../prompts/verbatim_input.txt", "../prompts/cot3.json"],
15 | "providers": [
16 | "openai:chat:gpt-3.5-turbo",
17 | "openai:chat:gpt-4o-mini",
18 | "openai:chat:gpt-4o",
19 | ],
20 | "tests": [
21 | {
22 | "vars": {"input": row["prompt"], "target": row["correct_output"]},
23 | "assert": [
24 | {"type": "python", "value": "file://../py/assert_last_line_answer.py"}
25 | ],
26 | }
27 | for _, row in df[:n_rows].iterrows()
28 | ],
29 | }
30 |
31 | os.makedirs("./evals", exist_ok=True)
32 |
33 | with open("./evals/{}.yaml".format(run_name), "w") as file:
34 | yaml.dump(output_dict, file, default_flow_style=False)
35 | print(
36 | "Generated {} promptfoo tests and saved to {}".format(
37 | n_rows, "{}.yaml".format(run_name)
38 | )
39 | )
40 |
--------------------------------------------------------------------------------
/3-4o_mini_fine_tuning/README.md:
--------------------------------------------------------------------------------
1 | # GPT 4o-mini Build Hour Code
2 |
3 | Demo code used in the GPT-4o mini Fine Tuning Build Hours.
4 |
5 | Recording coming soon!
6 |
7 | ## Setup
8 |
9 | 1. Set your OpenAI API key ([docs](https://platform.openai.com/docs/quickstart)).
10 |
11 | ```bash
12 | export OPENAI_API_KEY="sk_XXX..."
13 | ```
14 |
15 | 2. Run.
16 |
17 | ```bash
18 | python 0_generate_eval_data.py
19 | ```
20 |
--------------------------------------------------------------------------------
/3-4o_mini_fine_tuning/prompts/cot3.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "role": "system",
4 | "content": "You are an expert at developing logical, rigorous reasoning to classify the intent of a customer service ticket. Think step by step and analyze the task before providing your final answer. The final answer must be rendered on the last output line, with no additional quotes, xml tags, or empty newlines.\n\nIn your analysis, perform the following steps:\n1. Analyze the content of the chat to determine the primary issue\n2. Extract key phrases and concepts, and explain how they could help make the correct classification\n3. Consider each of the provided categories and identify the potential for each, with a confidence (1-10)\n4. Highlight ambiguity or limitations\n5. Synthesize your findings and create a final rationale\n6. Output the final answer in the final line. Do not output any empty newlines or markdown ` characters.\n"
5 | },
6 | {
7 | "role": "user",
8 | "content": "{{input}}"
9 | }
10 | ]
--------------------------------------------------------------------------------
/3-4o_mini_fine_tuning/prompts/verbatim_input.txt:
--------------------------------------------------------------------------------
1 | {{input}}
--------------------------------------------------------------------------------
/3-4o_mini_fine_tuning/py/assert_last_line_answer.py:
--------------------------------------------------------------------------------
1 | from typing import Dict, Any
2 |
3 |
4 | def get_assert(output: str, context) -> Dict[str, Any]:
5 | try:
6 | ans = output.split("\n")[-1]
7 | if str(context["vars"]["target"]).lower() in ans.lower():
8 | return {"pass": True, "score": 1.0, "reason": "passed"}
9 |
10 | return {
11 | "pass": False,
12 | "score": 0.0,
13 | "reason": "Not correct. Ans={}".format(ans),
14 | }
15 | except Exception as e:
16 | return {
17 | "pass": False,
18 | "score": 0.0,
19 | "reason": str(e),
20 | }
21 |
--------------------------------------------------------------------------------
/4-mmrag_tooluse/database.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | def get_table_names(conn):
4 | """Return a list of table names."""
5 | table_names = []
6 | tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
7 | for table in tables.fetchall():
8 | table_names.append(table[0])
9 | return table_names
10 |
11 |
12 | def get_column_names(conn, table_name):
13 | """Return a list of column names."""
14 | column_names = []
15 | columns = conn.execute(f"PRAGMA table_info('{table_name}');").fetchall()
16 | for col in columns:
17 | column_names.append(col[1])
18 | return column_names
19 |
20 |
21 | def get_database_info(conn):
22 | """Return a list of dicts containing the table name and columns for each table in the database."""
23 | table_dicts = []
24 | for table_name in get_table_names(conn):
25 | columns_names = get_column_names(conn, table_name)
26 | table_dicts.append(
27 | {"table_name": table_name, "column_names": columns_names})
28 | return table_dicts
29 |
--------------------------------------------------------------------------------
/4-mmrag_tooluse/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '3.4'
2 | services:
3 | qdrant:
4 | image: qdrant/qdrant:v1.3.0
5 | restart: on-failure
6 | ports:
7 | - "6335:6335"
8 |
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings.db
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q120_4.28.20_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q120_4.28.20_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q121_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q121_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q122_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q122_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q123_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q123_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q124_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q124_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q220_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q220_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q221_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q221_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q222_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q222_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q223_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q223_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q224_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q224_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q320_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q320_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q321_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q321_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q322_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q322_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q420_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q420_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q421_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q421_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q422_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q422_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_report_all/Webslides_Q423_Final.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_report_all/Webslides_Q423_Final.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/earnings_reports_sample/Webslides_Q323.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/4-mmrag_tooluse/earnings_reports_sample/Webslides_Q323.pdf
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q120.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q120",
4 | "data": [
5 | {
6 | "quarter": "Q1 2019",
7 | "operating_cash_flow": 34360,
8 | "purchases_of_property_and_equipment": -11316,
9 | "free_cash_flow": 23044
10 | },
11 | {
12 | "quarter": "Q2 2019",
13 | "operating_cash_flow": 36029,
14 | "purchases_of_property_and_equipment": -11011,
15 | "free_cash_flow": 25018
16 | },
17 | {
18 | "quarter": "Q3 2019",
19 | "operating_cash_flow": 35332,
20 | "purchases_of_property_and_equipment": -11868,
21 | "free_cash_flow": 23464
22 | },
23 | {
24 | "quarter": "Q4 2019",
25 | "operating_cash_flow": 38514,
26 | "purchases_of_property_and_equipment": -12689,
27 | "free_cash_flow": 25825
28 | },
29 | {
30 | "quarter": "Q1 2020",
31 | "operating_cash_flow": 39732,
32 | "purchases_of_property_and_equipment": -15395,
33 | "free_cash_flow": 24337
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q121.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q121",
4 | "data": [
5 | {
6 | "quarter": "Q1 2020",
7 | "operating_cash_flow": 39732,
8 | "purchases_of_property_and_equipment": -15395,
9 | "free_cash_flow": 24337
10 | },
11 | {
12 | "quarter": "Q2 2020",
13 | "operating_cash_flow": 51220,
14 | "purchases_of_property_and_equipment": -19368,
15 | "free_cash_flow": 31852
16 | },
17 | {
18 | "quarter": "Q3 2020",
19 | "operating_cash_flow": 55292,
20 | "purchases_of_property_and_equipment": -25791,
21 | "free_cash_flow": 29501
22 | },
23 | {
24 | "quarter": "Q4 2020",
25 | "operating_cash_flow": 66064,
26 | "purchases_of_property_and_equipment": -35044,
27 | "free_cash_flow": 31020
28 | },
29 | {
30 | "quarter": "Q1 2021",
31 | "operating_cash_flow": 67213,
32 | "purchases_of_property_and_equipment": -40803,
33 | "free_cash_flow": 26410
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q122.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q122",
4 | "data": [
5 | {
6 | "quarter": "Q1 2021",
7 | "operating_cash_flow": 67213,
8 | "purchases_of_property_and_equipment": -40803,
9 | "free_cash_flow": 26410
10 | },
11 | {
12 | "quarter": "Q2 2021",
13 | "operating_cash_flow": 59322,
14 | "purchases_of_property_and_equipment": -47176,
15 | "free_cash_flow": 12146
16 | },
17 | {
18 | "quarter": "Q3 2021",
19 | "operating_cash_flow": 54671,
20 | "purchases_of_property_and_equipment": -52119,
21 | "free_cash_flow": 2552
22 | },
23 | {
24 | "quarter": "Q4 2021",
25 | "operating_cash_flow": 46327,
26 | "purchases_of_property_and_equipment": -55396,
27 | "free_cash_flow": -9069
28 | },
29 | {
30 | "quarter": "Q1 2022",
31 | "operating_cash_flow": 39324,
32 | "purchases_of_property_and_equipment": -57951,
33 | "free_cash_flow": -18627
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q123.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q123",
4 | "data": [
5 | {
6 | "quarter": "Q1 2022",
7 | "operating_cash_flow": 39324,
8 | "purchases_of_property_and_equipment": -57951,
9 | "free_cash_flow": -18627
10 | },
11 | {
12 | "quarter": "Q2 2022",
13 | "operating_cash_flow": 35574,
14 | "purchases_of_property_and_equipment": -59061,
15 | "free_cash_flow": -23487
16 | },
17 | {
18 | "quarter": "Q3 2022",
19 | "operating_cash_flow": 39665,
20 | "purchases_of_property_and_equipment": -59351,
21 | "free_cash_flow": -19686
22 | },
23 | {
24 | "quarter": "Q4 2022",
25 | "operating_cash_flow": 46752,
26 | "purchases_of_property_and_equipment": -58321,
27 | "free_cash_flow": -11569
28 | },
29 | {
30 | "quarter": "Q1 2023",
31 | "operating_cash_flow": 54330,
32 | "purchases_of_property_and_equipment": -57649,
33 | "free_cash_flow": -3319
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q124.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q124",
4 | "data": [
5 | {
6 | "quarter": "Q1 2023",
7 | "operating_cash_flow": 54330,
8 | "purchases_of_property_and_equipment": -57649,
9 | "free_cash_flow": -3319
10 | },
11 | {
12 | "quarter": "Q2 2023",
13 | "operating_cash_flow": 61841,
14 | "purchases_of_property_and_equipment": -53963,
15 | "free_cash_flow": 7878
16 | },
17 | {
18 | "quarter": "Q3 2023",
19 | "operating_cash_flow": 71654,
20 | "purchases_of_property_and_equipment": -50220,
21 | "free_cash_flow": 21434
22 | },
23 | {
24 | "quarter": "Q4 2023",
25 | "operating_cash_flow": 84946,
26 | "purchases_of_property_and_equipment": -48133,
27 | "free_cash_flow": 36813
28 | },
29 | {
30 | "quarter": "Q1 2024",
31 | "operating_cash_flow": 99147,
32 | "purchases_of_property_and_equipment": -48998,
33 | "free_cash_flow": 50149
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q220.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q220",
4 | "data": [
5 | {
6 | "quarter": "Q2 2019",
7 | "operating_cash_flow": 36029,
8 | "purchases_of_property_and_equipment": -11011,
9 | "free_cash_flow": 25018
10 | },
11 | {
12 | "quarter": "Q3 2019",
13 | "operating_cash_flow": 35332,
14 | "purchases_of_property_and_equipment": -11868,
15 | "free_cash_flow": 23464
16 | },
17 | {
18 | "quarter": "Q4 2019",
19 | "operating_cash_flow": 38514,
20 | "purchases_of_property_and_equipment": -12689,
21 | "free_cash_flow": 25825
22 | },
23 | {
24 | "quarter": "Q1 2020",
25 | "operating_cash_flow": 39732,
26 | "purchases_of_property_and_equipment": -15395,
27 | "free_cash_flow": 24337
28 | },
29 | {
30 | "quarter": "Q2 2020",
31 | "operating_cash_flow": 51220,
32 | "purchases_of_property_and_equipment": -19368,
33 | "free_cash_flow": 31852
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q221.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q221",
4 | "data": [
5 | {
6 | "quarter": "Q2 2020",
7 | "operating_cash_flow": 51220,
8 | "purchases_of_property_and_equipment": -19368,
9 | "free_cash_flow": 31852
10 | },
11 | {
12 | "quarter": "Q3 2020",
13 | "operating_cash_flow": 55292,
14 | "purchases_of_property_and_equipment": -25791,
15 | "free_cash_flow": 29501
16 | },
17 | {
18 | "quarter": "Q4 2020",
19 | "operating_cash_flow": 66064,
20 | "purchases_of_property_and_equipment": -35044,
21 | "free_cash_flow": 31020
22 | },
23 | {
24 | "quarter": "Q1 2021",
25 | "operating_cash_flow": 67213,
26 | "purchases_of_property_and_equipment": -40803,
27 | "free_cash_flow": 26410
28 | },
29 | {
30 | "quarter": "Q2 2021",
31 | "operating_cash_flow": 59322,
32 | "purchases_of_property_and_equipment": -47176,
33 | "free_cash_flow": 12146
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q222.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q222",
4 | "data": [
5 | {
6 | "quarter": "Q2 2021",
7 | "operating_cash_flow": 59322,
8 | "purchases_of_property_and_equipment": -47176,
9 | "free_cash_flow": 12146
10 | },
11 | {
12 | "quarter": "Q3 2021",
13 | "operating_cash_flow": 54671,
14 | "purchases_of_property_and_equipment": -52119,
15 | "free_cash_flow": 2552
16 | },
17 | {
18 | "quarter": "Q4 2021",
19 | "operating_cash_flow": 46327,
20 | "purchases_of_property_and_equipment": -55396,
21 | "free_cash_flow": -9069
22 | },
23 | {
24 | "quarter": "Q1 2022",
25 | "operating_cash_flow": 39324,
26 | "purchases_of_property_and_equipment": -57951,
27 | "free_cash_flow": -18627
28 | },
29 | {
30 | "quarter": "Q2 2022",
31 | "operating_cash_flow": 35574,
32 | "purchases_of_property_and_equipment": -59061,
33 | "free_cash_flow": -23487
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q223.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q223",
4 | "data": [
5 | {
6 | "quarter": "Q2 2022",
7 | "operating_cash_flow": 35574,
8 | "purchases_of_property_and_equipment": -59061,
9 | "free_cash_flow": -23487
10 | },
11 | {
12 | "quarter": "Q3 2022",
13 | "operating_cash_flow": 39665,
14 | "purchases_of_property_and_equipment": -59351,
15 | "free_cash_flow": -19686
16 | },
17 | {
18 | "quarter": "Q4 2022",
19 | "operating_cash_flow": 46752,
20 | "purchases_of_property_and_equipment": -58321,
21 | "free_cash_flow": -11569
22 | },
23 | {
24 | "quarter": "Q1 2023",
25 | "operating_cash_flow": 54330,
26 | "purchases_of_property_and_equipment": -57649,
27 | "free_cash_flow": -3319
28 | },
29 | {
30 | "quarter": "Q2 2023",
31 | "operating_cash_flow": 61841,
32 | "purchases_of_property_and_equipment": -53963,
33 | "free_cash_flow": 7878
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q224.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q224",
4 | "data": [
5 | {
6 | "quarter": "Q2 2023",
7 | "operating_cash_flow": 61841,
8 | "purchases_of_property_and_equipment": -53963,
9 | "free_cash_flow": 7878
10 | },
11 | {
12 | "quarter": "Q3 2023",
13 | "operating_cash_flow": 71654,
14 | "purchases_of_property_and_equipment": -50220,
15 | "free_cash_flow": 21434
16 | },
17 | {
18 | "quarter": "Q4 2023",
19 | "operating_cash_flow": 84946,
20 | "purchases_of_property_and_equipment": -48133,
21 | "free_cash_flow": 36813
22 | },
23 | {
24 | "quarter": "Q1 2024",
25 | "operating_cash_flow": 99147,
26 | "purchases_of_property_and_equipment": -48998,
27 | "free_cash_flow": 50149
28 | },
29 | {
30 | "quarter": "Q2 2024",
31 | "operating_cash_flow": 107952,
32 | "purchases_of_property_and_equipment": -54979,
33 | "free_cash_flow": 52973
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q320.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q320",
4 | "data": [
5 | {
6 | "quarter": "Q3 2019",
7 | "operating_cash_flow": 35332,
8 | "purchases_of_property_and_equipment": -11868,
9 | "free_cash_flow": 23464
10 | },
11 | {
12 | "quarter": "Q4 2019",
13 | "operating_cash_flow": 38514,
14 | "purchases_of_property_and_equipment": -12689,
15 | "free_cash_flow": 25825
16 | },
17 | {
18 | "quarter": "Q1 2020",
19 | "operating_cash_flow": 39732,
20 | "purchases_of_property_and_equipment": -15395,
21 | "free_cash_flow": 24337
22 | },
23 | {
24 | "quarter": "Q2 2020",
25 | "operating_cash_flow": 51220,
26 | "purchases_of_property_and_equipment": -19368,
27 | "free_cash_flow": 31852
28 | },
29 | {
30 | "quarter": "Q3 2020",
31 | "operating_cash_flow": 55292,
32 | "purchases_of_property_and_equipment": -25791,
33 | "free_cash_flow": 29501
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q321.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q321",
4 | "data": [
5 | {
6 | "quarter": "Q3 2020",
7 | "operating_cash_flow": 55292,
8 | "purchases_of_property_and_equipment": -25791,
9 | "free_cash_flow": 29501
10 | },
11 | {
12 | "quarter": "Q4 2020",
13 | "operating_cash_flow": 66064,
14 | "purchases_of_property_and_equipment": -35044,
15 | "free_cash_flow": 31020
16 | },
17 | {
18 | "quarter": "Q1 2021",
19 | "operating_cash_flow": 67213,
20 | "purchases_of_property_and_equipment": -40803,
21 | "free_cash_flow": 26410
22 | },
23 | {
24 | "quarter": "Q2 2021",
25 | "operating_cash_flow": 59322,
26 | "purchases_of_property_and_equipment": -47176,
27 | "free_cash_flow": 12146
28 | },
29 | {
30 | "quarter": "Q3 2021",
31 | "operating_cash_flow": 54671,
32 | "purchases_of_property_and_equipment": -52119,
33 | "free_cash_flow": 2552
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q322.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q322",
4 | "data": [
5 | {
6 | "quarter": "Q3 2021",
7 | "operating_cash_flow": 54671,
8 | "purchases_of_property_and_equipment": -52119,
9 | "free_cash_flow": 2552
10 | },
11 | {
12 | "quarter": "Q4 2021",
13 | "operating_cash_flow": 46327,
14 | "purchases_of_property_and_equipment": -55396,
15 | "free_cash_flow": -9069
16 | },
17 | {
18 | "quarter": "Q1 2022",
19 | "operating_cash_flow": 39324,
20 | "purchases_of_property_and_equipment": -57951,
21 | "free_cash_flow": -18627
22 | },
23 | {
24 | "quarter": "Q2 2022",
25 | "operating_cash_flow": 35574,
26 | "purchases_of_property_and_equipment": -59061,
27 | "free_cash_flow": -23487
28 | },
29 | {
30 | "quarter": "Q3 2022",
31 | "operating_cash_flow": 39665,
32 | "purchases_of_property_and_equipment": -59351,
33 | "free_cash_flow": -19686
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q323.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q323",
4 | "data": [
5 | {
6 | "quarter": "Q3 2022",
7 | "operating_cash_flow": 39665,
8 | "purchases_of_property_and_equipment": -59351,
9 | "free_cash_flow": -19686
10 | },
11 | {
12 | "quarter": "Q4 2022",
13 | "operating_cash_flow": 46752,
14 | "purchases_of_property_and_equipment": -58321,
15 | "free_cash_flow": -11569
16 | },
17 | {
18 | "quarter": "Q1 2023",
19 | "operating_cash_flow": 54330,
20 | "purchases_of_property_and_equipment": -57649,
21 | "free_cash_flow": -3319
22 | },
23 | {
24 | "quarter": "Q2 2023",
25 | "operating_cash_flow": 61841,
26 | "purchases_of_property_and_equipment": -53963,
27 | "free_cash_flow": 7878
28 | },
29 | {
30 | "quarter": "Q3 2023",
31 | "operating_cash_flow": 71654,
32 | "purchases_of_property_and_equipment": -50220,
33 | "free_cash_flow": 21434
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q420.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q420",
4 | "data": [
5 | {
6 | "quarter": "Q4 2019",
7 | "operating_cash_flow": 38514,
8 | "purchases_of_property_and_equipment": -12689,
9 | "free_cash_flow": 25825
10 | },
11 | {
12 | "quarter": "Q1 2020",
13 | "operating_cash_flow": 39732,
14 | "purchases_of_property_and_equipment": -15395,
15 | "free_cash_flow": 24337
16 | },
17 | {
18 | "quarter": "Q2 2020",
19 | "operating_cash_flow": 51220,
20 | "purchases_of_property_and_equipment": -19368,
21 | "free_cash_flow": 31852
22 | },
23 | {
24 | "quarter": "Q3 2020",
25 | "operating_cash_flow": 55292,
26 | "purchases_of_property_and_equipment": -25791,
27 | "free_cash_flow": 29501
28 | },
29 | {
30 | "quarter": "Q4 2020",
31 | "operating_cash_flow": 66064,
32 | "purchases_of_property_and_equipment": -35044,
33 | "free_cash_flow": 31020
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q421.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q421",
4 | "data": [
5 | {
6 | "quarter": "Q4 2020",
7 | "operating_cash_flow": 66064,
8 | "purchases_of_property_and_equipment": -35044,
9 | "free_cash_flow": 31020
10 | },
11 | {
12 | "quarter": "Q1 2021",
13 | "operating_cash_flow": 67213,
14 | "purchases_of_property_and_equipment": -40803,
15 | "free_cash_flow": 26410
16 | },
17 | {
18 | "quarter": "Q2 2021",
19 | "operating_cash_flow": 59322,
20 | "purchases_of_property_and_equipment": -47176,
21 | "free_cash_flow": 12146
22 | },
23 | {
24 | "quarter": "Q3 2021",
25 | "operating_cash_flow": 54671,
26 | "purchases_of_property_and_equipment": -52119,
27 | "free_cash_flow": 2552
28 | },
29 | {
30 | "quarter": "Q4 2021",
31 | "operating_cash_flow": 46327,
32 | "purchases_of_property_and_equipment": -55396,
33 | "free_cash_flow": -9069
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q422.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q422",
4 | "data": [
5 | {
6 | "quarter": "Q4 2021",
7 | "operating_cash_flow": 46327,
8 | "purchases_of_property_and_equipment": -55396,
9 | "free_cash_flow": -9069
10 | },
11 | {
12 | "quarter": "Q1 2022",
13 | "operating_cash_flow": 39324,
14 | "purchases_of_property_and_equipment": -57951,
15 | "free_cash_flow": -18627
16 | },
17 | {
18 | "quarter": "Q2 2022",
19 | "operating_cash_flow": 35574,
20 | "purchases_of_property_and_equipment": -59061,
21 | "free_cash_flow": -23487
22 | },
23 | {
24 | "quarter": "Q3 2022",
25 | "operating_cash_flow": 39665,
26 | "purchases_of_property_and_equipment": -59351,
27 | "free_cash_flow": -19686
28 | },
29 | {
30 | "quarter": "Q4 2022",
31 | "operating_cash_flow": 46752,
32 | "purchases_of_property_and_equipment": -58321,
33 | "free_cash_flow": -11569
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/4-mmrag_tooluse/table_json/Free_Cash_Flow_Reconciliation_Q423.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Free_Cash_Flow_Reconciliation",
3 | "report_date": "Q423",
4 | "data": [
5 | {
6 | "quarter": "Q4 2022",
7 | "operating_cash_flow": 46752,
8 | "purchases_of_property_and_equipment": -58321,
9 | "free_cash_flow": -11569
10 | },
11 | {
12 | "quarter": "Q1 2023",
13 | "operating_cash_flow": 54330,
14 | "purchases_of_property_and_equipment": -57649,
15 | "free_cash_flow": -3319
16 | },
17 | {
18 | "quarter": "Q2 2023",
19 | "operating_cash_flow": 61841,
20 | "purchases_of_property_and_equipment": -53963,
21 | "free_cash_flow": 7878
22 | },
23 | {
24 | "quarter": "Q3 2023",
25 | "operating_cash_flow": 71654,
26 | "purchases_of_property_and_equipment": -50220,
27 | "free_cash_flow": 21434
28 | },
29 | {
30 | "quarter": "Q4 2023",
31 | "operating_cash_flow": 84946,
32 | "purchases_of_property_and_equipment": -48133,
33 | "free_cash_flow": 36813
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/5-4o_fine_tuning/.gitignore:
--------------------------------------------------------------------------------
1 | staticeval/
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/ft_gpt-3*5-turbo-0125_openai-gtm_vulnfixes0821_9ym18NbR-0-shot_20240823_0037.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-23 00:37:20
4 | Model: ft:gpt-3.5-turbo-0125:openai-gtm:vulnfixes0821:9ym18NbR
5 | Score: 50.44%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 57 out of 113
8 | Number of few-shot examples: 0
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 093118.py
12 | - 717170.py
13 | - 627547.py
14 | - 773378.py
15 | - 624453.py
16 | - 879024.py
17 | - 758317.py
18 | - 530858.py
19 | - 429723.py
20 | - 837764.py
21 | - 916728.py
22 | - 778047.py
23 | - 783587.py
24 | - 102308.py
25 | - 545558.py
26 | - 549500.py
27 | - 539416.py
28 | - 763767.py
29 | - 589414.py
30 | - 886160.py
31 | - 703706.py
32 | - 215937.py
33 | - 452701.py
34 | - 109129.py
35 | - 262477.py
36 | - 513433.py
37 | - 454489.py
38 | - 082256.py
39 | - 494107.py
40 | - 222094.py
41 | - 426331.py
42 | - 116843.py
43 | - 490297.py
44 | - 204197.py
45 | - 032394.py
46 | - 041528.py
47 | - 557095.py
48 | - 239585.py
49 | - 765068.py
50 | - 287641.py
51 | - 672233.py
52 | - 230568.py
53 | - 076051.py
54 | - 527709.py
55 | - 245327.py
56 | - 870482.py
57 | - 554536.py
58 | - 434281.py
59 | - 930264.py
60 | - 885715.py
61 | - 476533.py
62 | - 588795.py
63 | - 779518.py
64 | - 614629.py
65 | - 494330.py
66 | - 095146.py
67 | - 782536.py
68 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/ft_gpt-4o-2024-08-06_openai-gtm_vulnfixes-cot-0822_9zGknzVV-0-shot_20240822_2220.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-22 22:20:20
4 | Model: ft:gpt-4o-2024-08-06:openai-gtm:vulnfixes-cot-0822:9zGknzVV
5 | Score: 69.03%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 78 out of 113
8 | Number of few-shot examples: 0
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 717170.py
12 | - 916728.py
13 | - 773378.py
14 | - 932523.py
15 | - 177699.py
16 | - 093118.py
17 | - 624453.py
18 | - 948858.py
19 | - 879024.py
20 | - 530858.py
21 | - 837764.py
22 | - 429723.py
23 | - 036289.py
24 | - 778047.py
25 | - 549500.py
26 | - 102308.py
27 | - 804802.py
28 | - 545558.py
29 | - 539416.py
30 | - 886160.py
31 | - 458056.py
32 | - 422890.py
33 | - 589414.py
34 | - 525549.py
35 | - 001029.py
36 | - 974666.py
37 | - 780018.py
38 | - 703706.py
39 | - 452701.py
40 | - 262477.py
41 | - 109129.py
42 | - 513433.py
43 | - 770044.py
44 | - 006394.py
45 | - 454489.py
46 | - 173324.py
47 | - 494107.py
48 | - 387722.py
49 | - 426331.py
50 | - 938513.py
51 | - 222094.py
52 | - 032394.py
53 | - 791267.py
54 | - 490297.py
55 | - 192634.py
56 | - 041528.py
57 | - 693973.py
58 | - 204197.py
59 | - 239585.py
60 | - 514256.py
61 | - 610060.py
62 | - 557095.py
63 | - 916680.py
64 | - 765068.py
65 | - 511699.py
66 | - 969579.py
67 | - 287641.py
68 | - 672233.py
69 | - 218664.py
70 | - 409624.py
71 | - 192152.py
72 | - 263731.py
73 | - 245327.py
74 | - 076051.py
75 | - 527709.py
76 | - 870482.py
77 | - 885715.py
78 | - 930264.py
79 | - 434281.py
80 | - 476533.py
81 | - 310532.py
82 | - 087698.py
83 | - 779518.py
84 | - 588795.py
85 | - 614629.py
86 | - 494330.py
87 | - 095146.py
88 | - 782536.py
89 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/ft_gpt-4o-2024-08-06_openai-gtm_vulnfixes-cot-0822_9zGknzVV-5-shot-sim_20240823_0000.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-23 00:00:31
4 | Model: ft:gpt-4o-2024-08-06:openai-gtm:vulnfixes-cot-0822:9zGknzVV
5 | Score: 71.68%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 81 out of 113
8 | Number of few-shot examples: 5
9 | Use similarity for examples: Yes
10 | Fixed Files:
11 | - 916728.py
12 | - 627547.py
13 | - 773378.py
14 | - 177699.py
15 | - 093118.py
16 | - 758317.py
17 | - 879024.py
18 | - 884804.py
19 | - 948858.py
20 | - 359100.py
21 | - 530858.py
22 | - 837764.py
23 | - 102308.py
24 | - 036289.py
25 | - 778047.py
26 | - 695407.py
27 | - 549500.py
28 | - 545558.py
29 | - 804802.py
30 | - 589414.py
31 | - 539416.py
32 | - 763767.py
33 | - 458056.py
34 | - 886160.py
35 | - 780018.py
36 | - 001029.py
37 | - 525549.py
38 | - 703706.py
39 | - 452701.py
40 | - 974666.py
41 | - 124108.py
42 | - 641969.py
43 | - 109129.py
44 | - 770044.py
45 | - 262477.py
46 | - 513433.py
47 | - 006394.py
48 | - 946124.py
49 | - 494107.py
50 | - 454489.py
51 | - 222094.py
52 | - 426331.py
53 | - 791267.py
54 | - 116843.py
55 | - 032394.py
56 | - 041528.py
57 | - 693973.py
58 | - 192634.py
59 | - 204197.py
60 | - 239585.py
61 | - 557095.py
62 | - 813380.py
63 | - 514256.py
64 | - 765068.py
65 | - 969579.py
66 | - 299989.py
67 | - 916680.py
68 | - 511699.py
69 | - 672233.py
70 | - 218664.py
71 | - 409624.py
72 | - 914791.py
73 | - 263731.py
74 | - 245327.py
75 | - 192152.py
76 | - 076051.py
77 | - 527709.py
78 | - 365412.py
79 | - 870482.py
80 | - 434281.py
81 | - 930264.py
82 | - 476533.py
83 | - 252141.py
84 | - 087698.py
85 | - 310532.py
86 | - 779518.py
87 | - 614629.py
88 | - 190570.py
89 | - 095146.py
90 | - 782536.py
91 | - 494330.py
92 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/ft_gpt-4o-2024-08-06_openai-gtm_vulnfixes0821-long_9ymKVX9n-0-shot_20240825_2220.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-25 22:20:39
4 | Model: ft:gpt-4o-2024-08-06:openai-gtm:vulnfixes0821-long:9ymKVX9n
5 | Score: 61.94%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 70 out of 113
8 | Number of few-shot examples: 0
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 717170.py
12 | - 916728.py
13 | - 773378.py
14 | - 932523.py
15 | - 177699.py
16 | - 093118.py
17 | - 624453.py
18 | - 948858.py
19 | - 879024.py
20 | - 530858.py
21 | - 837764.py
22 | - 429723.py
23 | - 036289.py
24 | - 778047.py
25 | - 549500.py
26 | - 102308.py
27 | - 804802.py
28 | - 545558.py
29 | - 539416.py
30 | - 886160.py
31 | - 458056.py
32 | - 422890.py
33 | - 589414.py
34 | - 525549.py
35 | - 001029.py
36 | - 974666.py
37 | - 780018.py
38 | - 703706.py
39 | - 452701.py
40 | - 262477.py
41 | - 109129.py
42 | - 513433.py
43 | - 770044.py
44 | - 006394.py
45 | - 454489.py
46 | - 387722.py
47 | - 426331.py
48 | - 938513.py
49 | - 222094.py
50 | - 032394.py
51 | - 791267.py
52 | - 490297.py
53 | - 192634.py
54 | - 041528.py
55 | - 693973.py
56 | - 204197.py
57 | - 239585.py
58 | - 514256.py
59 | - 610060.py
60 | - 557095.py
61 | - 916680.py
62 | - 765068.py
63 | - 511699.py
64 | - 969579.py
65 | - 287641.py
66 | - 672233.py
67 | - 218664.py
68 | - 409624.py
69 | - 192152.py
70 | - 263731.py
71 | - 245327.py
72 | - 076051.py
73 | - 527709.py
74 | - 434281.py
75 | - 476533.py
76 | - 310532.py
77 | - 087698.py
78 | - 779518.py
79 | - 494330.py
80 | - 782536.py
81 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/ft_gpt-4o-mini-2024-07-18_openai-gtm_vulnfixes0822_9zILpnPW-0-shot_20240823_0027.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-23 00:27:14
4 | Model: ft:gpt-4o-mini-2024-07-18:openai-gtm:vulnfixes0822:9zILpnPW
5 | Score: 59.29%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 67 out of 113
8 | Number of few-shot examples: 0
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 570756.py
12 | - 773378.py
13 | - 627547.py
14 | - 717170.py
15 | - 093118.py
16 | - 916728.py
17 | - 624453.py
18 | - 884804.py
19 | - 879024.py
20 | - 948858.py
21 | - 530858.py
22 | - 837764.py
23 | - 429723.py
24 | - 783587.py
25 | - 778047.py
26 | - 102308.py
27 | - 036289.py
28 | - 695407.py
29 | - 545558.py
30 | - 804802.py
31 | - 539416.py
32 | - 589414.py
33 | - 886160.py
34 | - 422890.py
35 | - 001029.py
36 | - 780018.py
37 | - 703706.py
38 | - 215937.py
39 | - 452701.py
40 | - 109129.py
41 | - 262477.py
42 | - 513433.py
43 | - 006394.py
44 | - 494107.py
45 | - 082256.py
46 | - 387722.py
47 | - 426331.py
48 | - 222094.py
49 | - 116843.py
50 | - 032394.py
51 | - 204197.py
52 | - 041528.py
53 | - 693973.py
54 | - 239585.py
55 | - 557095.py
56 | - 813380.py
57 | - 765068.py
58 | - 287641.py
59 | - 672233.py
60 | - 023226.py
61 | - 218664.py
62 | - 230568.py
63 | - 914791.py
64 | - 409624.py
65 | - 245327.py
66 | - 076051.py
67 | - 527709.py
68 | - 476533.py
69 | - 434281.py
70 | - 930264.py
71 | - 885715.py
72 | - 252141.py
73 | - 614629.py
74 | - 779518.py
75 | - 087698.py
76 | - 494330.py
77 | - 782536.py
78 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/gpt-4o-0-shot_20240823_0018.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-23 00:18:10
4 | Model: gpt-4o
5 | Score: 53.10%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 60 out of 113
8 | Number of few-shot examples: 0
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 916728.py
12 | - 627547.py
13 | - 773378.py
14 | - 093118.py
15 | - 879024.py
16 | - 884804.py
17 | - 530858.py
18 | - 837764.py
19 | - 429723.py
20 | - 102308.py
21 | - 778047.py
22 | - 036289.py
23 | - 695407.py
24 | - 549500.py
25 | - 545558.py
26 | - 804802.py
27 | - 539416.py
28 | - 763767.py
29 | - 589414.py
30 | - 422890.py
31 | - 001029.py
32 | - 780018.py
33 | - 703706.py
34 | - 452701.py
35 | - 215937.py
36 | - 124108.py
37 | - 109129.py
38 | - 513433.py
39 | - 508391.py
40 | - 262477.py
41 | - 006394.py
42 | - 494107.py
43 | - 116843.py
44 | - 938513.py
45 | - 222094.py
46 | - 426331.py
47 | - 032394.py
48 | - 041528.py
49 | - 204197.py
50 | - 239585.py
51 | - 514256.py
52 | - 557095.py
53 | - 765068.py
54 | - 672233.py
55 | - 287641.py
56 | - 218664.py
57 | - 409624.py
58 | - 076051.py
59 | - 245327.py
60 | - 192152.py
61 | - 434281.py
62 | - 930264.py
63 | - 476533.py
64 | - 190570.py
65 | - 087698.py
66 | - 614629.py
67 | - 588795.py
68 | - 494330.py
69 | - 782536.py
70 | - 095146.py
71 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/gpt-4o-5-shot_20240822_2310.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-22 23:10:56
4 | Model: gpt-4o
5 | Score: 56.64%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 64 out of 113
8 | Number of few-shot examples: 5
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 916728.py
12 | - 177699.py
13 | - 627547.py
14 | - 773378.py
15 | - 093118.py
16 | - 948858.py
17 | - 879024.py
18 | - 884804.py
19 | - 530858.py
20 | - 837764.py
21 | - 429723.py
22 | - 695407.py
23 | - 778047.py
24 | - 036289.py
25 | - 545558.py
26 | - 804802.py
27 | - 549500.py
28 | - 539416.py
29 | - 589414.py
30 | - 763767.py
31 | - 886160.py
32 | - 422890.py
33 | - 001029.py
34 | - 780018.py
35 | - 703706.py
36 | - 124108.py
37 | - 109129.py
38 | - 452701.py
39 | - 215937.py
40 | - 262477.py
41 | - 508391.py
42 | - 513433.py
43 | - 006394.py
44 | - 494107.py
45 | - 454489.py
46 | - 387722.py
47 | - 116843.py
48 | - 938513.py
49 | - 222094.py
50 | - 426331.py
51 | - 032394.py
52 | - 041528.py
53 | - 514256.py
54 | - 204197.py
55 | - 239585.py
56 | - 557095.py
57 | - 765068.py
58 | - 287641.py
59 | - 672233.py
60 | - 218664.py
61 | - 409624.py
62 | - 192152.py
63 | - 245327.py
64 | - 076051.py
65 | - 476533.py
66 | - 930264.py
67 | - 434281.py
68 | - 885715.py
69 | - 087698.py
70 | - 614629.py
71 | - 588795.py
72 | - 494330.py
73 | - 782536.py
74 | - 095146.py
75 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/logs/gpt-4o-mini-0-shot_20240822_2322.log:
--------------------------------------------------------------------------------
1 | Eval Results
2 | --------------------
3 | Timestamp: 2024-08-22 23:22:32
4 | Model: gpt-4o-mini
5 | Score: 53.10%
6 | Semgrep Version: 1.85.0
7 | Passing Tests: 60 out of 113
8 | Number of few-shot examples: 0
9 | Use similarity for examples: No
10 | Fixed Files:
11 | - 916728.py
12 | - 773378.py
13 | - 627547.py
14 | - 093118.py
15 | - 932523.py
16 | - 884804.py
17 | - 879024.py
18 | - 530858.py
19 | - 938702.py
20 | - 837764.py
21 | - 429723.py
22 | - 102308.py
23 | - 036289.py
24 | - 778047.py
25 | - 695407.py
26 | - 549500.py
27 | - 545558.py
28 | - 804802.py
29 | - 539416.py
30 | - 001029.py
31 | - 780018.py
32 | - 422890.py
33 | - 703706.py
34 | - 215937.py
35 | - 124108.py
36 | - 452701.py
37 | - 109129.py
38 | - 508391.py
39 | - 513433.py
40 | - 262477.py
41 | - 006394.py
42 | - 494107.py
43 | - 454489.py
44 | - 387722.py
45 | - 116843.py
46 | - 426331.py
47 | - 791267.py
48 | - 032394.py
49 | - 041528.py
50 | - 514256.py
51 | - 204197.py
52 | - 557095.py
53 | - 299989.py
54 | - 765068.py
55 | - 287641.py
56 | - 672233.py
57 | - 218664.py
58 | - 409624.py
59 | - 230568.py
60 | - 076051.py
61 | - 245327.py
62 | - 192152.py
63 | - 434281.py
64 | - 930264.py
65 | - 476533.py
66 | - 885715.py
67 | - 614629.py
68 | - 087698.py
69 | - 494330.py
70 | - 782536.py
71 |
--------------------------------------------------------------------------------
/5-4o_fine_tuning/requirements.txt:
--------------------------------------------------------------------------------
1 | datasets
2 | openai
3 | pydantic
4 | scikit_learn
5 | sentence_transformers
6 | streamlit
7 | tenacity
8 | tiktoken
9 | semgrep==1.85.0
--------------------------------------------------------------------------------
/6-structured_outputs/node-example/app.js:
--------------------------------------------------------------------------------
1 | import OpenAI from "openai";
2 | import { zodResponseFormat } from "openai/helpers/zod";
3 | import { z } from "zod";
4 | import { INPUT } from "./input.js";
5 |
6 | const openai = new OpenAI();
7 |
8 | const paperInformationSchema = z.object({
9 | title: z.string(),
10 | authors: z.array(z.string()),
11 | abstract_summary: z
12 | .string()
13 | .describe("Summary of the abstract in 1-2 sentences"),
14 | keywords: z.array(z.string()),
15 | key_concepts: z.array(
16 | z.object({
17 | title: z.string(),
18 | description: z.string(),
19 | importance: z
20 | .enum(["high", "medium", "low"])
21 | .describe("Importance of the concept in this paper."),
22 | })
23 | ),
24 | });
25 |
26 | const SYSTEM_PROMPT =
27 | "You will be provided with a research paper. Your goal is to extract information from this paper in a structured format.";
28 |
29 | const completion = await openai.beta.chat.completions.parse({
30 | model: "gpt-4o-2024-08-06",
31 | messages: [
32 | { role: "system", content: SYSTEM_PROMPT },
33 | {
34 | role: "user",
35 | content: INPUT,
36 | },
37 | ],
38 | response_format: zodResponseFormat(
39 | paperInformationSchema,
40 | "paper_information"
41 | ),
42 | });
43 |
44 | const result = completion.choices[0].message.parsed;
45 | console.log(result);
46 |
--------------------------------------------------------------------------------
/6-structured_outputs/node-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "so-node-example",
3 | "version": "1.0.0",
4 | "type": "module",
5 | "main": "app.js",
6 | "scripts": {
7 | "start": "node app.js",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "author": "",
11 | "license": "ISC",
12 | "description": "",
13 | "dependencies": {
14 | "openai": "^4.64.0",
15 | "zod": "^3.23.8"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/6-structured_outputs/python-example/data/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/python-example/data/__init__.py
--------------------------------------------------------------------------------
/6-structured_outputs/python-example/main.py:
--------------------------------------------------------------------------------
1 | from dataclasses import Field
2 | from enum import Enum
3 | from pydantic import BaseModel
4 | from openai import OpenAI
5 |
6 | from data.input import INPUT
7 |
8 | client = OpenAI()
9 |
10 | class Importance(Enum):
11 | HIGH = 'high'
12 | MEDIUM = 'medium'
13 | LOW = 'low'
14 |
15 | class KeyConcept(BaseModel):
16 | title: str
17 | description: str
18 | importance: Importance
19 |
20 | class PaperInformation(BaseModel):
21 | title: str
22 | authors: list[str]
23 | abstract_summary: str
24 | keywords: list[str]
25 | key_concepts: list[KeyConcept]
26 |
27 | SYSTEM_PROMPT = "You will be provided with a research paper. Your goal is to extract information from this paper in a structured format.";
28 |
29 | completion = client.beta.chat.completions.parse(
30 | model="gpt-4o-2024-08-06",
31 | messages=[
32 | {"role": "system", "content": SYSTEM_PROMPT},
33 | {"role": "user", "content": INPUT}
34 | ],
35 | response_format=PaperInformation,
36 | )
37 |
38 | response = completion.choices[0].message.parsed
39 | print(response)
40 |
--------------------------------------------------------------------------------
/6-structured_outputs/python-example/requirements.txt:
--------------------------------------------------------------------------------
1 | annotated-types==0.7.0
2 | anyio==4.6.0
3 | certifi==2024.8.30
4 | distro==1.9.0
5 | h11==0.14.0
6 | httpcore==1.0.5
7 | httpx==0.27.2
8 | idna==3.10
9 | jiter==0.5.0
10 | openai==1.48.0
11 | pydantic==2.9.2
12 | pydantic_core==2.23.4
13 | sniffio==1.3.1
14 | tqdm==4.66.5
15 | typing_extensions==4.12.2
16 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["next/core-web-vitals", "next/typescript"]
3 | }
4 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | .yarn/install-state.gz
8 |
9 | # testing
10 | /coverage
11 |
12 | # next.js
13 | /.next/
14 | /out/
15 |
16 | # production
17 | /build
18 |
19 | # misc
20 | .DS_Store
21 | *.pem
22 |
23 | # debug
24 | npm-debug.log*
25 | yarn-debug.log*
26 | yarn-error.log*
27 |
28 | # local env files
29 | .env*.local
30 |
31 | # vercel
32 | .vercel
33 |
34 | # typescript
35 | *.tsbuildinfo
36 | next-env.d.ts
37 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/README.md:
--------------------------------------------------------------------------------
1 | This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2 |
3 | ## Getting Started
4 |
5 | First, run the development server:
6 |
7 | ```bash
8 | npm run dev
9 | # or
10 | yarn dev
11 | # or
12 | pnpm dev
13 | # or
14 | bun dev
15 | ```
16 |
17 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18 |
19 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20 |
21 | This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22 |
23 | ## Learn More
24 |
25 | To learn more about Next.js, take a look at the following resources:
26 |
27 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29 |
30 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31 |
32 | ## Deploy on Vercel
33 |
34 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35 |
36 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
37 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/api/assistant/get_products/route.ts:
--------------------------------------------------------------------------------
1 | import { getEntryById } from '../../../../lib/database'
2 |
3 | export async function POST(request: Request) {
4 | try {
5 | const { items } = await request.json()
6 | const cartItems = await Promise.all(
7 | items.map(async (item: { id: string; quantity: number }) => {
8 | console.log('retrieving item', item)
9 | const product = await getEntryById('products', item.id)
10 | console.log('product retrieved', product)
11 | return { item: { ...product }, quantity: item.quantity }
12 | })
13 | )
14 | return new Response(JSON.stringify({ cartItems }), {
15 | status: 200
16 | })
17 | } catch (error) {
18 | console.error(error)
19 | return new Response(
20 | JSON.stringify({ error: 'Failed to find candidates' }),
21 | {
22 | status: 500
23 | }
24 | )
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/api/assistant/search_products/route.ts:
--------------------------------------------------------------------------------
1 | import { filterEntries } from '../../../../lib/database'
2 |
3 | export async function POST(request: Request) {
4 | try {
5 | const { color, category, style, limit } = await request.json()
6 | const criteria = []
7 |
8 | if (color.length > 0) criteria.push({ field: 'color', values: color })
9 | if (category.length > 0)
10 | criteria.push({ field: 'categories', values: category })
11 | if (style.length > 0) criteria.push({ field: 'style', values: style })
12 |
13 | const matches = await filterEntries('products', criteria, limit)
14 | console.log('Matches found', matches)
15 | return new Response(JSON.stringify({ matches }), {
16 | status: 200
17 | })
18 | } catch (error) {
19 | console.error(error)
20 | return new Response(JSON.stringify({ error: 'Failed to find matches' }), {
21 | status: 500
22 | })
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/api/assistant/turn_response/route.ts:
--------------------------------------------------------------------------------
1 | import OpenAI from 'openai'
2 | const openai = new OpenAI()
3 | import { tools } from '../../../../lib/tools'
4 | import { ChatCompletionTool } from 'openai/resources/chat/completions'
5 |
6 | export async function POST(request: Request) {
7 | const { messages } = await request.json()
8 |
9 | try {
10 | const response = await openai.beta.chat.completions.parse({
11 | model: 'gpt-4o-2024-08-06',
12 | messages,
13 | temperature: 0,
14 | tools: tools as ChatCompletionTool[],
15 | parallel_tool_calls: false
16 | })
17 |
18 | if (response.choices.length > 0) {
19 | console.log('Response:', response.choices[0].message)
20 | if (response.choices[0].tool_calls) {
21 | console.log('Tool call:', response.choices[0].tool_calls[0].function)
22 | }
23 | return new Response(JSON.stringify(response.choices[0].message), {
24 | status: 200
25 | })
26 | }
27 | return new Response(
28 | JSON.stringify({
29 | text: 'I am sorry, there was an error processing your message. Please try again.'
30 | }),
31 | { status: 200 }
32 | )
33 | } catch (error) {
34 | console.error(error)
35 | return new Response(JSON.stringify(error), { status: 500 })
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/api/db/init/route.ts:
--------------------------------------------------------------------------------
1 | import { initDb } from '../../../../lib/database'
2 |
3 | export async function POST() {
4 | console.log('Init DB')
5 | try {
6 | await initDb()
7 | return new Response(
8 | JSON.stringify({ message: 'Database initialized successfully' }),
9 | {
10 | status: 200
11 | }
12 | )
13 | } catch (error) {
14 | console.error(error)
15 | return new Response(
16 | JSON.stringify({ error: 'Failed to initialize database' }),
17 | {
18 | status: 500
19 | }
20 | )
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/api/db/route.ts:
--------------------------------------------------------------------------------
1 | import { listEntries } from '../../../lib/database'
2 |
3 | export async function GET() {
4 | console.log('List all entries in DB')
5 | try {
6 | const entries = await listEntries('candidates')
7 | return new Response(JSON.stringify({ candidates: entries }), {
8 | status: 200
9 | })
10 | } catch (error) {
11 | console.error(error)
12 | return new Response(
13 | JSON.stringify({ error: 'Failed to list entries database' }),
14 | {
15 | status: 500
16 | }
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-assistant-final/app/favicon.ico
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import type { Metadata } from 'next'
2 | import './globals.css'
3 | import { Inter } from 'next/font/google'
4 | const inter = Inter({ subsets: ['latin'] })
5 |
6 | export const metadata: Metadata = {
7 | title: 'Shopping Assistant',
8 | description: 'Structured Outputs demo'
9 | }
10 |
11 | export default function RootLayout({
12 | children
13 | }: Readonly<{
14 | children: React.ReactNode
15 | }>) {
16 | return (
17 |
18 |
19 |
20 | {children}
21 |
22 |
23 |
24 | )
25 | }
26 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/app/page.tsx:
--------------------------------------------------------------------------------
1 | import MainView from '@/components/main-view'
2 |
3 | export default function Home() {
4 | return (
5 |
6 |
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://ui.shadcn.com/schema.json",
3 | "style": "new-york",
4 | "rsc": true,
5 | "tsx": true,
6 | "tailwind": {
7 | "config": "tailwind.config.ts",
8 | "css": "app/globals.css",
9 | "baseColor": "stone",
10 | "cssVariables": true,
11 | "prefix": ""
12 | },
13 | "aliases": {
14 | "components": "@/components",
15 | "utils": "@/lib/utils",
16 | "ui": "@/components/ui",
17 | "lib": "@/lib",
18 | "hooks": "@/hooks"
19 | }
20 | }
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/main-view.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 | import React, { useState } from 'react'
3 | import Cart, { CartItem } from './cart'
4 | import Assistant from './assistant'
5 |
6 | const MainView: React.FC = () => {
7 | const [cartItems, setCart] = useState([])
8 |
9 | const resetDb = async () => {
10 | try {
11 | const response = await fetch('/api/db/init', {
12 | method: 'POST'
13 | })
14 | if (response.status === 200) alert('Database has been reset')
15 | else alert('Failed to reset database')
16 | } catch (error) {
17 | console.error('Failed to reset database', error)
18 | alert('Failed to reset database')
19 | }
20 | }
21 |
22 | const resetCart = () => {
23 | setCart([])
24 | }
25 |
26 | return (
27 |
31 | )
32 | }
33 |
34 | export default MainView
35 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/message.css:
--------------------------------------------------------------------------------
1 | @keyframes bounce {
2 | 0%,
3 | 80%,
4 | 100% {
5 | transform: scale(0);
6 | }
7 | 40% {
8 | transform: scale(1);
9 | }
10 | }
11 |
12 | .dot {
13 | width: 5px;
14 | height: 5px;
15 | margin: 0 5px;
16 | border-radius: 50%;
17 | display: inline-block;
18 | animation: bounce 1.4s infinite ease-in-out both;
19 | }
20 |
21 | .dot:nth-child(1) {
22 | animation-delay: -0.32s;
23 | }
24 |
25 | .dot:nth-child(2) {
26 | animation-delay: -0.16s;
27 | }
28 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/badge.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { cva, type VariantProps } from "class-variance-authority"
3 |
4 | import { cn } from "@/lib/utils"
5 |
6 | const badgeVariants = cva(
7 | "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
8 | {
9 | variants: {
10 | variant: {
11 | default:
12 | "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
13 | secondary:
14 | "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
15 | destructive:
16 | "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
17 | outline: "text-foreground",
18 | },
19 | },
20 | defaultVariants: {
21 | variant: "default",
22 | },
23 | }
24 | )
25 |
26 | export interface BadgeProps
27 | extends React.HTMLAttributes,
28 | VariantProps {}
29 |
30 | function Badge({ className, variant, ...props }: BadgeProps) {
31 | return (
32 |
33 | )
34 | }
35 |
36 | export { Badge, badgeVariants }
37 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/checkbox.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
5 | import { CheckIcon } from "@radix-ui/react-icons"
6 |
7 | import { cn } from "@/lib/utils"
8 |
9 | const Checkbox = React.forwardRef<
10 | React.ElementRef,
11 | React.ComponentPropsWithoutRef
12 | >(({ className, ...props }, ref) => (
13 |
21 |
24 |
25 |
26 |
27 | ))
28 | Checkbox.displayName = CheckboxPrimitive.Root.displayName
29 |
30 | export { Checkbox }
31 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/input.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 |
3 | import { cn } from "@/lib/utils"
4 |
5 | export interface InputProps
6 | extends React.InputHTMLAttributes {}
7 |
8 | const Input = React.forwardRef(
9 | ({ className, type, ...props }, ref) => {
10 | return (
11 |
20 | )
21 | }
22 | )
23 | Input.displayName = "Input"
24 |
25 | export { Input }
26 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/label.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as LabelPrimitive from "@radix-ui/react-label"
5 | import { cva, type VariantProps } from "class-variance-authority"
6 |
7 | import { cn } from "@/lib/utils"
8 |
9 | const labelVariants = cva(
10 | "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
11 | )
12 |
13 | const Label = React.forwardRef<
14 | React.ElementRef,
15 | React.ComponentPropsWithoutRef &
16 | VariantProps
17 | >(({ className, ...props }, ref) => (
18 |
23 | ))
24 | Label.displayName = LabelPrimitive.Root.displayName
25 |
26 | export { Label }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/spinner.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import './spinner.css'
3 |
4 | export function Spinner() {
5 | return (
6 |
10 | )
11 | }
12 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/textarea.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 |
3 | import { cn } from '@/lib/utils'
4 |
5 | export interface TextareaProps
6 | extends React.TextareaHTMLAttributes {
7 | onKeyDown?: (event: React.KeyboardEvent) => void
8 | }
9 |
10 | const Textarea = React.forwardRef(
11 | ({ className, onKeyDown, ...props }, ref) => {
12 | return (
13 |
22 | )
23 | }
24 | )
25 | Textarea.displayName = 'Textarea'
26 |
27 | export { Textarea }
28 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/components/ui/toggle.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as TogglePrimitive from "@radix-ui/react-toggle"
5 | import { cva, type VariantProps } from "class-variance-authority"
6 |
7 | import { cn } from "@/lib/utils"
8 |
9 | const toggleVariants = cva(
10 | "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
11 | {
12 | variants: {
13 | variant: {
14 | default: "bg-transparent",
15 | outline:
16 | "border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground",
17 | },
18 | size: {
19 | default: "h-9 px-3",
20 | sm: "h-8 px-2",
21 | lg: "h-10 px-3",
22 | },
23 | },
24 | defaultVariants: {
25 | variant: "default",
26 | size: "default",
27 | },
28 | }
29 | )
30 |
31 | const Toggle = React.forwardRef<
32 | React.ElementRef,
33 | React.ComponentPropsWithoutRef &
34 | VariantProps
35 | >(({ className, variant, size, ...props }, ref) => (
36 |
41 | ))
42 |
43 | Toggle.displayName = TogglePrimitive.Root.displayName
44 |
45 | export { Toggle, toggleVariants }
46 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/data/database.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-assistant-final/data/database.sqlite
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/lib/utils.ts:
--------------------------------------------------------------------------------
1 | import { clsx, type ClassValue } from "clsx"
2 | import { twMerge } from "tailwind-merge"
3 |
4 | export function cn(...inputs: ClassValue[]) {
5 | return twMerge(clsx(inputs))
6 | }
7 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/next.config.mjs:
--------------------------------------------------------------------------------
1 | /** @type {import('next').NextConfig} */
2 | const nextConfig = {
3 | images: {
4 | domains: ['m.media-amazon.com']
5 | }
6 | }
7 |
8 | export default nextConfig
9 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "so-demo",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "@radix-ui/react-checkbox": "^1.1.1",
13 | "@radix-ui/react-dialog": "^1.1.1",
14 | "@radix-ui/react-dropdown-menu": "^2.1.1",
15 | "@radix-ui/react-icons": "^1.3.0",
16 | "@radix-ui/react-label": "^2.1.0",
17 | "@radix-ui/react-select": "^2.1.1",
18 | "@radix-ui/react-slot": "^1.1.0",
19 | "@radix-ui/react-toggle": "^1.1.0",
20 | "@radix-ui/react-toggle-group": "^1.1.0",
21 | "@xyflow/react": "^12.3.0",
22 | "class-variance-authority": "^0.7.0",
23 | "clsx": "^2.1.1",
24 | "framer-motion": "^11.5.4",
25 | "fs": "0.0.1-security",
26 | "lucide-react": "^0.441.0",
27 | "next": "14.2.11",
28 | "openai": "^4.61.0",
29 | "pdf2json": "^3.1.4",
30 | "pdfjs-dist": "2.16.105",
31 | "react": "^18",
32 | "react-dom": "^18",
33 | "react-dropzone": "^14.2.3",
34 | "react-flow-renderer": "^10.3.17",
35 | "react-markdown": "^9.0.1",
36 | "react-pdf": "^9.1.1",
37 | "recharts": "^2.12.7",
38 | "sqlite3": "^5.1.7",
39 | "tailwind-merge": "^2.5.2",
40 | "tailwindcss-animate": "^1.0.7",
41 | "vaul": "^0.9.4",
42 | "zod": "^3.23.8"
43 | },
44 | "devDependencies": {
45 | "@types/node": "^20",
46 | "@types/react": "^18",
47 | "@types/react-dom": "^18",
48 | "@types/react-pdf": "^7.0.0",
49 | "@types/sqlite3": "^3.1.11",
50 | "eslint": "^8",
51 | "eslint-config-next": "14.2.11",
52 | "postcss": "^8",
53 | "tailwindcss": "^3.4.1",
54 | "typescript": "^5"
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/postcss.config.mjs:
--------------------------------------------------------------------------------
1 | /** @type {import('postcss-load-config').Config} */
2 | const config = {
3 | plugins: {
4 | tailwindcss: {},
5 | },
6 | };
7 |
8 | export default config;
9 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/prettier.config.cjs:
--------------------------------------------------------------------------------
1 | /** @type {import('prettier').Config} */
2 | module.exports = {
3 | endOfLine: 'lf',
4 | semi: false,
5 | useTabs: false,
6 | singleQuote: true,
7 | arrowParens: 'avoid',
8 | tabWidth: 2,
9 | trailingComma: 'none',
10 | importOrder: [
11 | '^(react/(.*)$)|^(react$)',
12 | '^(next/(.*)$)|^(next$)',
13 | '',
14 | '',
15 | '^types$',
16 | '^@/types/(.*)$',
17 | '^@/config/(.*)$',
18 | '^@/lib/(.*)$',
19 | '^@/hooks/(.*)$',
20 | '^@/components/ui/(.*)$',
21 | '^@/components/(.*)$',
22 | '^@/registry/(.*)$',
23 | '^@/styles/(.*)$',
24 | '^@/app/(.*)$',
25 | '',
26 | '^[./]'
27 | ],
28 | importOrderSeparation: false,
29 | importOrderSortSpecifiers: true,
30 | importOrderBuiltinModulesToTop: true,
31 | importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
32 | importOrderMergeDuplicateImports: true,
33 | importOrderCombineTypeAndValueImports: true
34 | }
35 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/public/imgs/user_profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-assistant-final/public/imgs/user_profile.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-final/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["dom", "dom.iterable", "esnext"],
4 | "allowJs": true,
5 | "skipLibCheck": true,
6 | "strict": true,
7 | "noEmit": true,
8 | "esModuleInterop": true,
9 | "module": "esnext",
10 | "moduleResolution": "bundler",
11 | "resolveJsonModule": true,
12 | "isolatedModules": true,
13 | "jsx": "preserve",
14 | "incremental": true,
15 | "plugins": [
16 | {
17 | "name": "next"
18 | }
19 | ],
20 | "paths": {
21 | "@/*": ["./*"]
22 | }
23 | },
24 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25 | "exclude": ["node_modules"]
26 | }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["next/core-web-vitals", "next/typescript"]
3 | }
4 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | .yarn/install-state.gz
8 |
9 | # testing
10 | /coverage
11 |
12 | # next.js
13 | /.next/
14 | /out/
15 |
16 | # production
17 | /build
18 |
19 | # misc
20 | .DS_Store
21 | *.pem
22 |
23 | # debug
24 | npm-debug.log*
25 | yarn-debug.log*
26 | yarn-error.log*
27 |
28 | # local env files
29 | .env*.local
30 |
31 | # vercel
32 | .vercel
33 |
34 | # typescript
35 | *.tsbuildinfo
36 | next-env.d.ts
37 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/README.md:
--------------------------------------------------------------------------------
1 | This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2 |
3 | ## Getting Started
4 |
5 | First, run the development server:
6 |
7 | ```bash
8 | npm run dev
9 | # or
10 | yarn dev
11 | # or
12 | pnpm dev
13 | # or
14 | bun dev
15 | ```
16 |
17 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18 |
19 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20 |
21 | This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22 |
23 | ## Learn More
24 |
25 | To learn more about Next.js, take a look at the following resources:
26 |
27 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29 |
30 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31 |
32 | ## Deploy on Vercel
33 |
34 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35 |
36 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
37 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/api/assistant/get_products/route.ts:
--------------------------------------------------------------------------------
1 | import { getEntryById } from '../../../../lib/database'
2 |
3 | export async function POST(request: Request) {
4 | try {
5 | const { items } = await request.json()
6 | const cartItems = await Promise.all(
7 | items.map(async (item: { id: string; quantity: number }) => {
8 | console.log('retrieving item', item)
9 | const product = await getEntryById('products', item.id)
10 | console.log('product retrieved', product)
11 | return { item: { ...product }, quantity: item.quantity }
12 | })
13 | )
14 | return new Response(JSON.stringify({ cartItems }), {
15 | status: 200
16 | })
17 | } catch (error) {
18 | console.error(error)
19 | return new Response(
20 | JSON.stringify({ error: 'Failed to find candidates' }),
21 | {
22 | status: 500
23 | }
24 | )
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/api/assistant/search_products/route.ts:
--------------------------------------------------------------------------------
1 | import { filterEntries } from '../../../../lib/database'
2 |
3 | export async function POST(request: Request) {
4 | try {
5 | const { color, category, style, limit } = await request.json()
6 | const criteria = []
7 |
8 | if (color.length > 0) criteria.push({ field: 'color', values: color })
9 | if (category.length > 0)
10 | criteria.push({ field: 'categories', values: category })
11 | if (style.length > 0) criteria.push({ field: 'style', values: style })
12 |
13 | const matches = await filterEntries('products', criteria, limit)
14 | console.log('Matches found', matches)
15 | return new Response(JSON.stringify({ matches }), {
16 | status: 200
17 | })
18 | } catch (error) {
19 | console.error(error)
20 | return new Response(JSON.stringify({ error: 'Failed to find matches' }), {
21 | status: 500
22 | })
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/api/assistant/turn_response/route.ts:
--------------------------------------------------------------------------------
1 | import OpenAI from 'openai'
2 | const openai = new OpenAI()
3 | import { tools } from '../../../../lib/tools'
4 | import { ChatCompletionTool } from 'openai/resources/chat/completions'
5 |
6 | export async function POST(request: Request) {
7 | const { messages } = await request.json()
8 |
9 | try {
10 | const response = await openai.beta.chat.completions.parse({
11 | model: 'gpt-4o-2024-08-06',
12 | messages,
13 | temperature: 0
14 | //tools: tools as ChatCompletionTool[],
15 | //parallel_tool_calls: false
16 | })
17 |
18 | if (response.choices.length > 0) {
19 | console.log('Response:', response.choices[0].message)
20 | if (response.choices[0].tool_calls) {
21 | console.log('Tool call:', response.choices[0].tool_calls[0].function)
22 | }
23 | return new Response(JSON.stringify(response.choices[0].message), {
24 | status: 200
25 | })
26 | }
27 | return new Response(
28 | JSON.stringify({
29 | text: 'I am sorry, there was an error processing your message. Please try again.'
30 | }),
31 | { status: 200 }
32 | )
33 | } catch (error) {
34 | console.error(error)
35 | return new Response(JSON.stringify(error), { status: 500 })
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/api/db/init/route.ts:
--------------------------------------------------------------------------------
1 | import { initDb } from '../../../../lib/database'
2 |
3 | export async function POST() {
4 | console.log('Init DB')
5 | try {
6 | await initDb()
7 | return new Response(
8 | JSON.stringify({ message: 'Database initialized successfully' }),
9 | {
10 | status: 200
11 | }
12 | )
13 | } catch (error) {
14 | console.error(error)
15 | return new Response(
16 | JSON.stringify({ error: 'Failed to initialize database' }),
17 | {
18 | status: 500
19 | }
20 | )
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/api/db/route.ts:
--------------------------------------------------------------------------------
1 | import { listEntries } from '../../../lib/database'
2 |
3 | export async function GET() {
4 | console.log('List all entries in DB')
5 | try {
6 | const entries = await listEntries('candidates')
7 | return new Response(JSON.stringify({ candidates: entries }), {
8 | status: 200
9 | })
10 | } catch (error) {
11 | console.error(error)
12 | return new Response(
13 | JSON.stringify({ error: 'Failed to list entries database' }),
14 | {
15 | status: 500
16 | }
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-assistant-starting-point/app/favicon.ico
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import type { Metadata } from 'next'
2 | import './globals.css'
3 | import { Inter } from 'next/font/google'
4 | const inter = Inter({ subsets: ['latin'] })
5 |
6 | export const metadata: Metadata = {
7 | title: 'Shopping Assistant',
8 | description: 'Structured Outputs demo'
9 | }
10 |
11 | export default function RootLayout({
12 | children
13 | }: Readonly<{
14 | children: React.ReactNode
15 | }>) {
16 | return (
17 |
18 |
19 |
20 | {children}
21 |
22 |
23 |
24 | )
25 | }
26 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/app/page.tsx:
--------------------------------------------------------------------------------
1 | import MainView from '@/components/main-view'
2 |
3 | export default function Home() {
4 | return (
5 |
6 |
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://ui.shadcn.com/schema.json",
3 | "style": "new-york",
4 | "rsc": true,
5 | "tsx": true,
6 | "tailwind": {
7 | "config": "tailwind.config.ts",
8 | "css": "app/globals.css",
9 | "baseColor": "stone",
10 | "cssVariables": true,
11 | "prefix": ""
12 | },
13 | "aliases": {
14 | "components": "@/components",
15 | "utils": "@/lib/utils",
16 | "ui": "@/components/ui",
17 | "lib": "@/lib",
18 | "hooks": "@/hooks"
19 | }
20 | }
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/main-view.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 | import React, { useState } from 'react'
3 | import Cart, { CartItem } from './cart'
4 | import Assistant from './assistant'
5 |
6 | const MainView: React.FC = () => {
7 | const [cartItems, setCart] = useState([])
8 |
9 | const resetDb = async () => {
10 | try {
11 | const response = await fetch('/api/db/init', {
12 | method: 'POST'
13 | })
14 | if (response.status === 200) alert('Database has been reset')
15 | else alert('Failed to reset database')
16 | } catch (error) {
17 | console.error('Failed to reset database', error)
18 | alert('Failed to reset database')
19 | }
20 | }
21 |
22 | const resetCart = () => {
23 | setCart([])
24 | }
25 |
26 | return (
27 |
31 | )
32 | }
33 |
34 | export default MainView
35 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/message.css:
--------------------------------------------------------------------------------
1 | @keyframes bounce {
2 | 0%,
3 | 80%,
4 | 100% {
5 | transform: scale(0);
6 | }
7 | 40% {
8 | transform: scale(1);
9 | }
10 | }
11 |
12 | .dot {
13 | width: 5px;
14 | height: 5px;
15 | margin: 0 5px;
16 | border-radius: 50%;
17 | display: inline-block;
18 | animation: bounce 1.4s infinite ease-in-out both;
19 | }
20 |
21 | .dot:nth-child(1) {
22 | animation-delay: -0.32s;
23 | }
24 |
25 | .dot:nth-child(2) {
26 | animation-delay: -0.16s;
27 | }
28 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/tool-results.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 | import ReactMarkdown from 'react-markdown'
3 | import { Checkbox } from './ui/checkbox'
4 | import { Button } from './ui/button'
5 | import Image from 'next/image'
6 |
7 | import { DialogDescription } from '@radix-ui/react-dialog'
8 | import { Card, CardContent, CardHeader } from './ui/card'
9 | import { CircleCheckBig } from 'lucide-react'
10 | import { getComponent } from '@/lib/components-mapping'
11 | import { Test } from './test'
12 | import Flow from './workflow'
13 |
14 | interface ToolResultsProps {
15 | tool: {
16 | name: string
17 | content: any
18 | }
19 | }
20 |
21 | const ToolResults: React.FC = ({
22 | tool
23 | }: ToolResultsProps) => {
24 | return (
25 |
26 | {(() => {
27 | switch (tool.name) {
28 | default:
29 | return (
30 |
31 |
{tool.name}
32 |
33 | {JSON.stringify(tool.content)}
34 |
35 |
36 | )
37 | }
38 | })()}
39 |
40 | )
41 | }
42 |
43 | export default ToolResults
44 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/badge.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { cva, type VariantProps } from "class-variance-authority"
3 |
4 | import { cn } from "@/lib/utils"
5 |
6 | const badgeVariants = cva(
7 | "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
8 | {
9 | variants: {
10 | variant: {
11 | default:
12 | "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
13 | secondary:
14 | "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
15 | destructive:
16 | "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
17 | outline: "text-foreground",
18 | },
19 | },
20 | defaultVariants: {
21 | variant: "default",
22 | },
23 | }
24 | )
25 |
26 | export interface BadgeProps
27 | extends React.HTMLAttributes,
28 | VariantProps {}
29 |
30 | function Badge({ className, variant, ...props }: BadgeProps) {
31 | return (
32 |
33 | )
34 | }
35 |
36 | export { Badge, badgeVariants }
37 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/checkbox.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
5 | import { CheckIcon } from "@radix-ui/react-icons"
6 |
7 | import { cn } from "@/lib/utils"
8 |
9 | const Checkbox = React.forwardRef<
10 | React.ElementRef,
11 | React.ComponentPropsWithoutRef
12 | >(({ className, ...props }, ref) => (
13 |
21 |
24 |
25 |
26 |
27 | ))
28 | Checkbox.displayName = CheckboxPrimitive.Root.displayName
29 |
30 | export { Checkbox }
31 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/input.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 |
3 | import { cn } from "@/lib/utils"
4 |
5 | export interface InputProps
6 | extends React.InputHTMLAttributes {}
7 |
8 | const Input = React.forwardRef(
9 | ({ className, type, ...props }, ref) => {
10 | return (
11 |
20 | )
21 | }
22 | )
23 | Input.displayName = "Input"
24 |
25 | export { Input }
26 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/label.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as LabelPrimitive from "@radix-ui/react-label"
5 | import { cva, type VariantProps } from "class-variance-authority"
6 |
7 | import { cn } from "@/lib/utils"
8 |
9 | const labelVariants = cva(
10 | "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
11 | )
12 |
13 | const Label = React.forwardRef<
14 | React.ElementRef,
15 | React.ComponentPropsWithoutRef &
16 | VariantProps
17 | >(({ className, ...props }, ref) => (
18 |
23 | ))
24 | Label.displayName = LabelPrimitive.Root.displayName
25 |
26 | export { Label }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/spinner.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import './spinner.css'
3 |
4 | export function Spinner() {
5 | return (
6 |
10 | )
11 | }
12 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/textarea.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 |
3 | import { cn } from '@/lib/utils'
4 |
5 | export interface TextareaProps
6 | extends React.TextareaHTMLAttributes {
7 | onKeyDown?: (event: React.KeyboardEvent) => void
8 | }
9 |
10 | const Textarea = React.forwardRef(
11 | ({ className, onKeyDown, ...props }, ref) => {
12 | return (
13 |
22 | )
23 | }
24 | )
25 | Textarea.displayName = 'Textarea'
26 |
27 | export { Textarea }
28 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/components/ui/toggle.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as TogglePrimitive from "@radix-ui/react-toggle"
5 | import { cva, type VariantProps } from "class-variance-authority"
6 |
7 | import { cn } from "@/lib/utils"
8 |
9 | const toggleVariants = cva(
10 | "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
11 | {
12 | variants: {
13 | variant: {
14 | default: "bg-transparent",
15 | outline:
16 | "border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground",
17 | },
18 | size: {
19 | default: "h-9 px-3",
20 | sm: "h-8 px-2",
21 | lg: "h-10 px-3",
22 | },
23 | },
24 | defaultVariants: {
25 | variant: "default",
26 | size: "default",
27 | },
28 | }
29 | )
30 |
31 | const Toggle = React.forwardRef<
32 | React.ElementRef,
33 | React.ComponentPropsWithoutRef &
34 | VariantProps
35 | >(({ className, variant, size, ...props }, ref) => (
36 |
41 | ))
42 |
43 | Toggle.displayName = TogglePrimitive.Root.displayName
44 |
45 | export { Toggle, toggleVariants }
46 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/data/database.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-assistant-starting-point/data/database.sqlite
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/lib/assistant.ts:
--------------------------------------------------------------------------------
1 | export const SYSTEM_PROMPT = `
2 | You are a product recommendation assistant, assisting users in discovering products that match their preferences.
3 | When users ask for help finding products, you can search for matches using the search_product tool.
4 | When you have found matches, you can display the top 3 most relevant using the generate_ui tool.
5 |
6 | If users ask about something that can be displayed with data, use the generate_ui tool with the appropriate component.
7 | When users express interest in a specific product, add it to the cart.
8 |
9 | Feel free to ask follow up questions when needed.
10 | `
11 |
12 | export interface Message {
13 | role: 'system' | 'assistant' | 'user' | 'tool'
14 | content: string
15 | [key: string]: any
16 | }
17 |
18 | export interface Product {
19 | id: string
20 | title: string
21 | url: string
22 | primary_image: string
23 | price: string
24 | categories: string[]
25 | color: string
26 | style: string
27 | }
28 |
29 | export const handleTool = async (toolName: string, parameters: any) => {
30 | console.log('Handle tool', toolName, parameters)
31 | }
32 |
33 | export const handleTurn = async (messages: Message[]) => {
34 | console.log('Handle turn', messages)
35 | try {
36 | const response = await fetch('/api/assistant/turn_response', {
37 | method: 'POST',
38 | headers: {
39 | 'Content-Type': 'application/json'
40 | },
41 | body: JSON.stringify({ messages })
42 | })
43 | const result = await response.json()
44 | console.log(result)
45 | return result
46 | } catch (error) {
47 | console.error('Error handling turn:', error)
48 | return error
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/lib/utils.ts:
--------------------------------------------------------------------------------
1 | import { clsx, type ClassValue } from "clsx"
2 | import { twMerge } from "tailwind-merge"
3 |
4 | export function cn(...inputs: ClassValue[]) {
5 | return twMerge(clsx(inputs))
6 | }
7 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/next.config.mjs:
--------------------------------------------------------------------------------
1 | /** @type {import('next').NextConfig} */
2 | const nextConfig = {
3 | images: {
4 | domains: ['m.media-amazon.com']
5 | }
6 | }
7 |
8 | export default nextConfig
9 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/postcss.config.mjs:
--------------------------------------------------------------------------------
1 | /** @type {import('postcss-load-config').Config} */
2 | const config = {
3 | plugins: {
4 | tailwindcss: {},
5 | },
6 | };
7 |
8 | export default config;
9 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/prettier.config.cjs:
--------------------------------------------------------------------------------
1 | /** @type {import('prettier').Config} */
2 | module.exports = {
3 | endOfLine: 'lf',
4 | semi: false,
5 | useTabs: false,
6 | singleQuote: true,
7 | arrowParens: 'avoid',
8 | tabWidth: 2,
9 | trailingComma: 'none',
10 | importOrder: [
11 | '^(react/(.*)$)|^(react$)',
12 | '^(next/(.*)$)|^(next$)',
13 | '',
14 | '',
15 | '^types$',
16 | '^@/types/(.*)$',
17 | '^@/config/(.*)$',
18 | '^@/lib/(.*)$',
19 | '^@/hooks/(.*)$',
20 | '^@/components/ui/(.*)$',
21 | '^@/components/(.*)$',
22 | '^@/registry/(.*)$',
23 | '^@/styles/(.*)$',
24 | '^@/app/(.*)$',
25 | '',
26 | '^[./]'
27 | ],
28 | importOrderSeparation: false,
29 | importOrderSortSpecifiers: true,
30 | importOrderBuiltinModulesToTop: true,
31 | importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
32 | importOrderMergeDuplicateImports: true,
33 | importOrderCombineTypeAndValueImports: true
34 | }
35 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/public/imgs/user_profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-assistant-starting-point/public/imgs/user_profile.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-assistant-starting-point/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["dom", "dom.iterable", "esnext"],
4 | "allowJs": true,
5 | "skipLibCheck": true,
6 | "strict": true,
7 | "noEmit": true,
8 | "esModuleInterop": true,
9 | "module": "esnext",
10 | "moduleResolution": "bundler",
11 | "resolveJsonModule": true,
12 | "isolatedModules": true,
13 | "jsx": "preserve",
14 | "incremental": true,
15 | "plugins": [
16 | {
17 | "name": "next"
18 | }
19 | ],
20 | "paths": {
21 | "@/*": ["./*"]
22 | }
23 | },
24 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25 | "exclude": ["node_modules"]
26 | }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/eslintrc",
3 | "root": true,
4 | "extends": [
5 | "next/core-web-vitals",
6 | "prettier",
7 | "plugin:tailwindcss/recommended"
8 | ],
9 | "plugins": ["tailwindcss"],
10 | "rules": {
11 | "tailwindcss/no-custom-classname": "off",
12 | "tailwindcss/classnames-order": "off"
13 | },
14 | "settings": {
15 | "tailwindcss": {
16 | "callees": ["cn", "cva"],
17 | "config": "tailwind.config.js"
18 | }
19 | },
20 | "overrides": [
21 | {
22 | "files": ["*.ts", "*.tsx"],
23 | "parser": "@typescript-eslint/parser"
24 | }
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | node_modules
5 | .pnp
6 | .pnp.js
7 |
8 | # testing
9 | coverage
10 |
11 | # next.js
12 | .next/
13 | out/
14 | build
15 |
16 | # misc
17 | .DS_Store
18 | *.pem
19 |
20 | # debug
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | .pnpm-debug.log*
25 |
26 | # local env files
27 | .env.local
28 | .env.development.local
29 | .env.test.local
30 | .env.production.local
31 |
32 | # turbo
33 | .turbo
34 |
35 | .env
36 | .vercel
37 | .vscode
38 | .env*.local
39 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 OpenAI
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import { Inter } from 'next/font/google'
2 | const inter = Inter({ subsets: ['latin'] })
3 | import '@/app/globals.css'
4 |
5 | export const metadata = {
6 | metadataBase: process.env.VERCEL_URL
7 | ? new URL(`https://${process.env.VERCEL_URL}`)
8 | : undefined,
9 | title: {
10 | default: 'Math tutor'
11 | },
12 | description: 'AI-powered math tutor',
13 | icons: {
14 | icon: '/favicon.ico',
15 | shortcut: '/favicon-16x16.png',
16 | apple: '/apple-touch-icon.png'
17 | }
18 | }
19 |
20 | interface RootLayoutProps {
21 | children: React.ReactNode
22 | }
23 |
24 | export default function RootLayout({ children }: RootLayoutProps) {
25 | return (
26 |
27 |
28 | {children}
29 |
30 |
31 | )
32 | }
33 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://ui.shadcn.com/schema.json",
3 | "style": "new-york",
4 | "rsc": true,
5 | "tsx": true,
6 | "tailwind": {
7 | "config": "tailwind.config.ts",
8 | "css": "app/globals.css",
9 | "baseColor": "zinc",
10 | "cssVariables": true,
11 | "prefix": ""
12 | },
13 | "aliases": {
14 | "components": "@/components",
15 | "utils": "@/lib/utils"
16 | }
17 | }
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components/sidebar.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
3 | import { coldarkDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'
4 |
5 | interface SidebarProps {
6 | isOpen: boolean
7 | response: any
8 | }
9 |
10 | export function Sidebar({ isOpen, response }: SidebarProps) {
11 | return (
12 |
17 |
JSON Response
18 |
19 |
20 |
41 | {JSON.stringify(response, null, 2)}
42 |
43 |
44 |
45 | )
46 | }
47 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components/stepper.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 |
3 | import * as React from 'react'
4 | import { IconArrowRight } from '@/components/ui/icons'
5 |
6 | interface StepperProps {
7 | currentStep: number
8 | totalSteps: number
9 | onSkipStep: () => void
10 | finished?: boolean
11 | }
12 |
13 | export function Stepper({
14 | currentStep,
15 | totalSteps,
16 | onSkipStep,
17 | finished
18 | }: StepperProps) {
19 | return (
20 |
21 |
22 |
23 | {Array.from({ length: totalSteps }).map((_, index) => (
24 |
30 | ))}
31 |
32 |
33 |
42 |
43 | )
44 | }
45 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components/ui/badge.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import { IconCheck, IconClose, IconSeparator } from './icons'
3 |
4 | interface BadgeProps {
5 | status: 'skipped' | 'success' | 'fail' | 'finished' | null
6 | className: string
7 | }
8 |
9 | export function Badge({ status, className }: BadgeProps) {
10 | let color
11 | let icon
12 |
13 | switch (status) {
14 | case 'success':
15 | color = 'bg-emerald-600'
16 | icon =
17 | break
18 | case 'fail':
19 | color = 'bg-rose-600'
20 | icon =
21 | break
22 | case 'skipped':
23 | color = 'bg-gray-500'
24 | icon =
25 | break
26 | default:
27 | return null
28 | }
29 |
30 | return (
31 |
34 | {icon}
35 |
36 | )
37 | }
38 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components/ui/confetti.tsx:
--------------------------------------------------------------------------------
1 | // components/Confetti.js
2 | import { useEffect } from 'react'
3 | import confetti from 'canvas-confetti'
4 |
5 | const Confetti = () => {
6 | useEffect(() => {
7 | const end = Date.now() + 1 * 1000 // seconds of confetti
8 |
9 | const colors = ['#2dd4bf', '#4f46e5', '#fcd34d']
10 |
11 | ;(function frame() {
12 | confetti({
13 | particleCount: 3,
14 | angle: 90,
15 | spread: 90,
16 | origin: { x: 0.5, y: 1 },
17 | colors: colors
18 | })
19 |
20 | if (Date.now() < end) {
21 | requestAnimationFrame(frame)
22 | }
23 | })()
24 | }, [])
25 |
26 | return null
27 | }
28 |
29 | export default Confetti
30 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components/ui/spinner.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import './spinner.css'
3 |
4 | export function Spinner() {
5 | return (
6 |
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/components/ui/warning.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 |
3 | import * as React from 'react'
4 | import { IconArrowRight } from '@/components/ui/icons'
5 |
6 | interface WarningProps {
7 | text: string
8 | onReset: () => void
9 | }
10 |
11 | export function Warning({ text, onReset }: WarningProps) {
12 | return (
13 |
14 |
15 |
18 |
19 |
26 |
27 |
28 |
29 | )
30 | }
31 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/lib/actions.ts:
--------------------------------------------------------------------------------
1 | export type Step = {
2 | explanation: string
3 | output: string
4 | }
5 |
6 | export type Solution = {
7 | steps: Step[]
8 | final_answer: string
9 | refusal?: string
10 | }
11 |
12 | export async function getSolution(problem: string): Promise {
13 | const response = await fetch('/api/math_responses', {
14 | method: 'POST',
15 | headers: {
16 | 'Content-Type': 'application/json'
17 | },
18 | body: JSON.stringify({ problem })
19 | })
20 |
21 | console.log(response)
22 |
23 | if (!response.ok) {
24 | const errorMessage = await response.text() // Get the HTML error message
25 | console.error('Error:', errorMessage)
26 | throw new Error(errorMessage || 'Failed to fetch solution')
27 | }
28 |
29 | const data = await response.json()
30 |
31 | if (!data.refusal) {
32 | const result = data.solution
33 |
34 | const steps: Step[] = result.steps.map((step: any) => ({
35 | explanation: step.explanation,
36 | output: step.output
37 | }))
38 |
39 | const solution: Solution = {
40 | steps: steps,
41 | final_answer: result.final_answer
42 | }
43 |
44 | return solution
45 | } else {
46 | return { steps: [], final_answer: '', refusal: data.refusal }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | // NOTE: This file should not be edited
5 | // see https://nextjs.org/docs/basic-features/typescript for more information.
6 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/next.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('next').NextConfig} */
2 | module.exports = {
3 | images: {
4 | remotePatterns: [
5 | {
6 | protocol: 'https',
7 | hostname: 'avatars.githubusercontent.com',
8 | port: '',
9 | pathname: '**'
10 | }
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/prettier.config.cjs:
--------------------------------------------------------------------------------
1 | /** @type {import('prettier').Config} */
2 | module.exports = {
3 | endOfLine: 'lf',
4 | semi: false,
5 | useTabs: false,
6 | singleQuote: true,
7 | arrowParens: 'avoid',
8 | tabWidth: 2,
9 | trailingComma: 'none',
10 | importOrder: [
11 | '^(react/(.*)$)|^(react$)',
12 | '^(next/(.*)$)|^(next$)',
13 | '',
14 | '',
15 | '^types$',
16 | '^@/types/(.*)$',
17 | '^@/config/(.*)$',
18 | '^@/lib/(.*)$',
19 | '^@/hooks/(.*)$',
20 | '^@/components/ui/(.*)$',
21 | '^@/components/(.*)$',
22 | '^@/registry/(.*)$',
23 | '^@/styles/(.*)$',
24 | '^@/app/(.*)$',
25 | '',
26 | '^[./]'
27 | ],
28 | importOrderSeparation: false,
29 | importOrderSortSpecifiers: true,
30 | importOrderBuiltinModulesToTop: true,
31 | importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
32 | importOrderMergeDuplicateImports: true,
33 | importOrderCombineTypeAndValueImports: true
34 | }
35 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-final/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/public/avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-final/public/avatar.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/public/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-final/public/favicon-16x16.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-final/public/favicon.ico
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/public/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-final/public/screenshot.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-final/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["dom", "dom.iterable", "esnext"],
4 | "allowJs": true,
5 | "skipLibCheck": true,
6 | "strict": true,
7 | "forceConsistentCasingInFileNames": true,
8 | "noEmit": true,
9 | "incremental": true,
10 | "esModuleInterop": true,
11 | "module": "esnext",
12 | "moduleResolution": "node",
13 | "resolveJsonModule": true,
14 | "isolatedModules": true,
15 | "jsx": "preserve",
16 | "baseUrl": ".",
17 | "paths": {
18 | "@/*": ["./*"]
19 | },
20 | "plugins": [
21 | {
22 | "name": "next"
23 | }
24 | ],
25 | "strictNullChecks": true
26 | },
27 | "include": [
28 | "next-env.d.ts",
29 | "next-auth.d.ts",
30 | "**/*.ts",
31 | "**/*.tsx",
32 | ".next/types/**/*.ts"
33 | ],
34 | "exclude": ["node_modules"]
35 | }
36 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/eslintrc",
3 | "root": true,
4 | "extends": [
5 | "next/core-web-vitals",
6 | "prettier",
7 | "plugin:tailwindcss/recommended"
8 | ],
9 | "plugins": ["tailwindcss"],
10 | "rules": {
11 | "tailwindcss/no-custom-classname": "off",
12 | "tailwindcss/classnames-order": "off"
13 | },
14 | "settings": {
15 | "tailwindcss": {
16 | "callees": ["cn", "cva"],
17 | "config": "tailwind.config.js"
18 | }
19 | },
20 | "overrides": [
21 | {
22 | "files": ["*.ts", "*.tsx"],
23 | "parser": "@typescript-eslint/parser"
24 | }
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | node_modules
5 | .pnp
6 | .pnp.js
7 |
8 | # testing
9 | coverage
10 |
11 | # next.js
12 | .next/
13 | out/
14 | build
15 |
16 | # misc
17 | .DS_Store
18 | *.pem
19 |
20 | # debug
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | .pnpm-debug.log*
25 |
26 | # local env files
27 | .env.local
28 | .env.development.local
29 | .env.test.local
30 | .env.production.local
31 |
32 | # turbo
33 | .turbo
34 |
35 | .env
36 | .vercel
37 | .vscode
38 | .env*.local
39 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 OpenAI
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import { Inter } from 'next/font/google'
2 | const inter = Inter({ subsets: ['latin'] })
3 | import '@/app/globals.css'
4 |
5 | export const metadata = {
6 | metadataBase: process.env.VERCEL_URL
7 | ? new URL(`https://${process.env.VERCEL_URL}`)
8 | : undefined,
9 | title: {
10 | default: 'Math tutor'
11 | },
12 | description: 'AI-powered math tutor',
13 | icons: {
14 | icon: '/favicon.ico',
15 | shortcut: '/favicon-16x16.png',
16 | apple: '/apple-touch-icon.png'
17 | }
18 | }
19 |
20 | interface RootLayoutProps {
21 | children: React.ReactNode
22 | }
23 |
24 | export default function RootLayout({ children }: RootLayoutProps) {
25 | return (
26 |
27 |
28 | {children}
29 |
30 |
31 | )
32 | }
33 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://ui.shadcn.com/schema.json",
3 | "style": "new-york",
4 | "rsc": true,
5 | "tsx": true,
6 | "tailwind": {
7 | "config": "tailwind.config.ts",
8 | "css": "app/globals.css",
9 | "baseColor": "zinc",
10 | "cssVariables": true,
11 | "prefix": ""
12 | },
13 | "aliases": {
14 | "components": "@/components",
15 | "utils": "@/lib/utils"
16 | }
17 | }
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components/sidebar.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
3 | import { coldarkDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'
4 |
5 | interface SidebarProps {
6 | isOpen: boolean
7 | response: any
8 | }
9 |
10 | export function Sidebar({ isOpen, response }: SidebarProps) {
11 | return (
12 |
17 |
JSON Response
18 |
19 |
20 |
41 | {JSON.stringify(response, null, 2)}
42 |
43 |
44 |
45 | )
46 | }
47 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components/stepper.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 |
3 | import * as React from 'react'
4 | import { IconArrowRight } from '@/components/ui/icons'
5 |
6 | interface StepperProps {
7 | currentStep: number
8 | totalSteps: number
9 | onSkipStep: () => void
10 | finished?: boolean
11 | }
12 |
13 | export function Stepper({
14 | currentStep,
15 | totalSteps,
16 | onSkipStep,
17 | finished
18 | }: StepperProps) {
19 | return (
20 |
21 |
22 |
23 | {Array.from({ length: totalSteps }).map((_, index) => (
24 |
30 | ))}
31 |
32 |
33 |
42 |
43 | )
44 | }
45 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components/ui/badge.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import { IconCheck, IconClose, IconSeparator } from './icons'
3 |
4 | interface BadgeProps {
5 | status: 'skipped' | 'success' | 'fail' | 'finished' | null
6 | className: string
7 | }
8 |
9 | export function Badge({ status, className }: BadgeProps) {
10 | let color
11 | let icon
12 |
13 | switch (status) {
14 | case 'success':
15 | color = 'bg-emerald-600'
16 | icon =
17 | break
18 | case 'fail':
19 | color = 'bg-rose-600'
20 | icon =
21 | break
22 | case 'skipped':
23 | color = 'bg-gray-500'
24 | icon =
25 | break
26 | default:
27 | return null
28 | }
29 |
30 | return (
31 |
34 | {icon}
35 |
36 | )
37 | }
38 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components/ui/confetti.tsx:
--------------------------------------------------------------------------------
1 | // components/Confetti.js
2 | import { useEffect } from 'react'
3 | import confetti from 'canvas-confetti'
4 |
5 | const Confetti = () => {
6 | useEffect(() => {
7 | const end = Date.now() + 1 * 1000 // seconds of confetti
8 |
9 | const colors = ['#2dd4bf', '#4f46e5', '#fcd34d']
10 |
11 | ;(function frame() {
12 | confetti({
13 | particleCount: 3,
14 | angle: 90,
15 | spread: 90,
16 | origin: { x: 0.5, y: 1 },
17 | colors: colors
18 | })
19 |
20 | if (Date.now() < end) {
21 | requestAnimationFrame(frame)
22 | }
23 | })()
24 | }, [])
25 |
26 | return null
27 | }
28 |
29 | export default Confetti
30 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components/ui/spinner.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 | import './spinner.css'
3 |
4 | export function Spinner() {
5 | return (
6 |
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/components/ui/warning.tsx:
--------------------------------------------------------------------------------
1 | 'use client'
2 |
3 | import * as React from 'react'
4 | import { IconArrowRight } from '@/components/ui/icons'
5 |
6 | interface WarningProps {
7 | text: string
8 | onReset: () => void
9 | }
10 |
11 | export function Warning({ text, onReset }: WarningProps) {
12 | return (
13 |
14 |
15 |
18 |
19 |
26 |
27 |
28 |
29 | )
30 | }
31 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/lib/actions.ts:
--------------------------------------------------------------------------------
1 | export type Step = {
2 | explanation: string
3 | output: string
4 | }
5 |
6 | export type Solution = {
7 | steps: Step[]
8 | final_answer: string
9 | refusal?: string
10 | }
11 |
12 | export async function getSolution(problem: string): Promise {
13 | const response = await fetch('/api/math_responses', {
14 | method: 'POST',
15 | headers: {
16 | 'Content-Type': 'application/json'
17 | },
18 | body: JSON.stringify({ problem })
19 | })
20 |
21 | console.log(response)
22 |
23 | if (!response.ok) {
24 | const errorMessage = await response.text() // Get the HTML error message
25 | console.error('Error:', errorMessage)
26 | throw new Error(errorMessage || 'Failed to fetch solution')
27 | }
28 |
29 | const data = await response.json()
30 |
31 | if (!data.refusal) {
32 | const result = data.solution
33 |
34 | const steps: Step[] = result.steps.map((step: any) => ({
35 | explanation: step.explanation,
36 | output: step.output
37 | }))
38 |
39 | const solution: Solution = {
40 | steps: steps,
41 | final_answer: result.final_answer
42 | }
43 |
44 | return solution
45 | } else {
46 | return { steps: [], final_answer: '', refusal: data.refusal }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | // NOTE: This file should not be edited
5 | // see https://nextjs.org/docs/basic-features/typescript for more information.
6 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/next.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('next').NextConfig} */
2 | module.exports = {
3 | images: {
4 | remotePatterns: [
5 | {
6 | protocol: 'https',
7 | hostname: 'avatars.githubusercontent.com',
8 | port: '',
9 | pathname: '**'
10 | }
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/prettier.config.cjs:
--------------------------------------------------------------------------------
1 | /** @type {import('prettier').Config} */
2 | module.exports = {
3 | endOfLine: 'lf',
4 | semi: false,
5 | useTabs: false,
6 | singleQuote: true,
7 | arrowParens: 'avoid',
8 | tabWidth: 2,
9 | trailingComma: 'none',
10 | importOrder: [
11 | '^(react/(.*)$)|^(react$)',
12 | '^(next/(.*)$)|^(next$)',
13 | '',
14 | '',
15 | '^types$',
16 | '^@/types/(.*)$',
17 | '^@/config/(.*)$',
18 | '^@/lib/(.*)$',
19 | '^@/hooks/(.*)$',
20 | '^@/components/ui/(.*)$',
21 | '^@/components/(.*)$',
22 | '^@/registry/(.*)$',
23 | '^@/styles/(.*)$',
24 | '^@/app/(.*)$',
25 | '',
26 | '^[./]'
27 | ],
28 | importOrderSeparation: false,
29 | importOrderSortSpecifiers: true,
30 | importOrderBuiltinModulesToTop: true,
31 | importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
32 | importOrderMergeDuplicateImports: true,
33 | importOrderCombineTypeAndValueImports: true
34 | }
35 |
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/avatar.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/favicon-16x16.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/favicon.ico
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/6-structured_outputs/structured-outputs-math-tutor-starting-point/public/screenshot.png
--------------------------------------------------------------------------------
/6-structured_outputs/structured-outputs-math-tutor-starting-point/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["dom", "dom.iterable", "esnext"],
4 | "allowJs": true,
5 | "skipLibCheck": true,
6 | "strict": true,
7 | "forceConsistentCasingInFileNames": true,
8 | "noEmit": true,
9 | "incremental": true,
10 | "esModuleInterop": true,
11 | "module": "esnext",
12 | "moduleResolution": "node",
13 | "resolveJsonModule": true,
14 | "isolatedModules": true,
15 | "jsx": "preserve",
16 | "baseUrl": ".",
17 | "paths": {
18 | "@/*": ["./*"]
19 | },
20 | "plugins": [
21 | {
22 | "name": "next"
23 | }
24 | ],
25 | "strictNullChecks": true
26 | },
27 | "include": [
28 | "next-env.d.ts",
29 | "next-auth.d.ts",
30 | "**/*.ts",
31 | "**/*.tsx",
32 | ".next/types/**/*.ts"
33 | ],
34 | "exclude": ["node_modules"]
35 | }
36 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/ReadMe.md:
--------------------------------------------------------------------------------
1 | # Shipping Planner
2 |
3 | ## How to run
4 | If you don't already, have your OpenAI API key set as an environment variable `OPENAI_API_KEY`
5 |
6 | ### Spin up the backend
7 | - In your terminal, navigate to the backend directory
8 | - Install the required Python packages by running `pip install -r requirements.txt`
9 | - Run `python app.py`
10 |
11 |
12 | ### Spin up the frontend
13 | - In a separate terminal, go to the frontend directory
14 | - Ensure you have Node.js version 21 or higher installed.
15 | - Run `npm i`
16 | - Run `npm start`
17 | - A window should automatically appear, but if not, navigate to your [http://localhost:3000](http://localhost:3000/)
18 |
19 |
20 | ## Prompt
21 | We will be using the following scenario prompt for today's demo:
22 |
23 | "We just received a major shipment of new orders. Please generate a plan that gets the list of awaiting orders and determines the best policy to fulfill them.
24 |
25 | The plan should include checking inventory, ordering necessary components from suppliers, scheduling production runs with available capacity, ordering new components required from suppliers, and arranging shipping to the retailer’s distribution center in Los Angeles. Notify the customer before completing.
26 |
27 | Prioritize getting any possible orders out that you can while placing orders for any backlog items."
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/backend/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask
2 | flask-cors
3 | openai
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "supply-chain-planner",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@emotion/react": "^11.13.3",
7 | "@emotion/styled": "^11.13.0",
8 | "@mui/icons-material": "^6.1.1",
9 | "@mui/material": "^6.1.1",
10 | "@testing-library/jest-dom": "^5.17.0",
11 | "@testing-library/react": "^13.4.0",
12 | "@testing-library/user-event": "^13.5.0",
13 | "react": "^18.3.1",
14 | "react-dom": "^18.3.1",
15 | "react-markdown": "^9.0.1",
16 | "react-scripts": "5.0.1",
17 | "react-syntax-highlighter": "^15.5.0",
18 | "remark-gfm": "^4.0.0",
19 | "web-vitals": "^2.1.4"
20 | },
21 | "scripts": {
22 | "start": "react-scripts start",
23 | "build": "react-scripts build",
24 | "test": "react-scripts test",
25 | "eject": "react-scripts eject"
26 | },
27 | "eslintConfig": {
28 | "extends": [
29 | "react-app",
30 | "react-app/jest"
31 | ]
32 | },
33 | "browserslist": {
34 | "production": [
35 | ">0.2%",
36 | "not dead",
37 | "not op_mini all"
38 | ],
39 | "development": [
40 | "last 1 chrome version",
41 | "last 1 firefox version",
42 | "last 1 safari version"
43 | ]
44 | },
45 | "proxy": "http://localhost:5000"
46 | }
47 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/7-reasoning/shipmentPlanning/frontend/public/favicon.ico
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/7-reasoning/shipmentPlanning/frontend/public/logo192.png
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/7-reasoning/shipmentPlanning/frontend/public/logo512.png
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/App.css:
--------------------------------------------------------------------------------
1 | /* src/App.css */
2 | .App {
3 | font-family: 'Roboto', sans-serif;
4 | text-align: center;
5 | background-color: #f9fafb;
6 | padding: 20px;
7 | }
8 |
9 | .content {
10 | display: flex;
11 | flex-direction: column;
12 | gap: 20px;
13 | }
14 |
15 | @media (min-width: 768px) {
16 | .content {
17 | flex-direction: row;
18 | justify-content: space-between;
19 | }
20 |
21 | .content > div {
22 | width: 48%;
23 | }
24 | }
25 |
26 | .scenario-input {
27 | margin-bottom: 20px;
28 | }
29 |
30 | .scenario-input textarea {
31 | width: 80%;
32 | height: 100px;
33 | padding: 10px;
34 | font-size: 16px;
35 | }
36 |
37 | .scenario-input button {
38 | padding: 10px 20px;
39 | font-size: 16px;
40 | margin-left: 10px;
41 | }
42 |
43 | .content {
44 | display: flex;
45 | justify-content: space-between;
46 | margin-top: 20px;
47 | }
48 |
49 | .plan-display,
50 | .execution-stream {
51 | width: 45%;
52 | background-color: #fff;
53 | padding: 10px;
54 | border: 1px solid #ccc;
55 | border-radius: 5px;
56 | overflow-y: auto;
57 | max-height: 500px;
58 | }
59 |
60 | .plan-display pre {
61 | text-align: left;
62 | }
63 |
64 | .status {
65 | color: #007bff;
66 | }
67 |
68 | .assistant {
69 | color: #28a745;
70 | }
71 |
72 | .function-call {
73 | color: #6c757d;
74 | }
75 |
76 | .error {
77 | color: #dc3545;
78 | }
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render();
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/ScenarioInput.js:
--------------------------------------------------------------------------------
1 | // src/ScenarioInput.js
2 |
3 | import React, { useState } from 'react';
4 | import { TextField, Button, Box } from '@mui/material';
5 |
6 | function ScenarioInput({ onSubmit, isProcessing }) {
7 | const [inputText, setInputText] = useState('');
8 |
9 | const handleSubmit = () => {
10 | if (!inputText.trim()) {
11 | alert('Please enter a scenario.');
12 | return;
13 | }
14 | onSubmit(inputText);
15 | };
16 |
17 | const handleKeyPress = (e) => {
18 | if (e.key === 'Enter' && !e.shiftKey) {
19 | e.preventDefault(); // Prevents a new line in the textarea
20 | handleSubmit();
21 | }
22 | };
23 |
24 | return (
25 |
26 | setInputText(e.target.value)}
33 | onKeyPress={handleKeyPress}
34 | placeholder="Enter your scenario here..."
35 | disabled={isProcessing}
36 | variant="outlined"
37 | InputProps={{ style: { fontSize: 16 } }}
38 | />
39 |
40 |
49 |
50 |
51 | );
52 | }
53 |
54 | export default ScenarioInput;
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/assets/logos/shippingLogo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/7-reasoning/shipmentPlanning/frontend/src/assets/logos/shippingLogo.jpg
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/index.js:
--------------------------------------------------------------------------------
1 | // src/index.js
2 |
3 | import React from 'react';
4 | import ReactDOM from 'react-dom';
5 | import App from './App';
6 | import theme from './theme';
7 | import { ThemeProvider } from '@mui/material/styles';
8 | import CssBaseline from '@mui/material/CssBaseline';
9 |
10 | ReactDOM.render(
11 |
12 |
13 | {/* Provides a consistent baseline */}
14 |
15 |
16 | ,
17 | document.getElementById('root')
18 | );
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/7-reasoning/shipmentPlanning/frontend/src/theme.js:
--------------------------------------------------------------------------------
1 | // src/theme.js
2 |
3 | import { createTheme } from '@mui/material/styles';
4 |
5 | const theme = createTheme({
6 | spacing: 8, // Default spacing unit
7 | palette: {
8 | primary: {
9 | main: '#1976d2', // Customize as needed
10 | },
11 | secondary: {
12 | main: '#9c27b0', // Customize as needed
13 | },
14 | success: {
15 | main: '#4caf50', // Customize as needed
16 | },
17 | background: {
18 | default: '#fafafa', // Light background
19 | },
20 | },
21 | typography: {
22 | fontFamily: 'Roboto, Arial, sans-serif', // Modern font
23 | },
24 | components: {
25 | MuiButton: {
26 | styleOverrides: {
27 | root: {
28 | borderRadius: '8px',
29 | textTransform: 'none', // Prevent uppercase text
30 | },
31 | },
32 | },
33 | MuiAppBar: {
34 | styleOverrides: {
35 | colorPrimary: {
36 | backgroundColor: '#ffffff',
37 | color: '#000000',
38 | },
39 | },
40 | },
41 | MuiDrawer: {
42 | styleOverrides: {
43 | paper: {
44 | backgroundColor: '#f9f9f9',
45 | },
46 | },
47 | },
48 | },
49 | });
50 |
51 | export default theme;
--------------------------------------------------------------------------------
/9-realtime/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/9-realtime/README.md:
--------------------------------------------------------------------------------
1 | # Realtime API
2 |
3 | Demo code used in the Realtime API Build Hours.
4 |
5 | ## Examples
6 |
7 | Both examples shown during the build hours were created from scratch or a template – here we are providing the completed version.
8 |
9 | We strongly recommend you start new project from scratch or a template, not these examples directly!
10 |
11 | ### Example 1: Realtime from Scratch
12 |
13 | `realtime-from-scratch`: bare-bones example of an audio assistant, built from a fresh NextJS project
14 |
15 | To try it yourself from scratch, set up a new [NextJS](https://nextjs.org/docs) project with:
16 |
17 | ```bash
18 | npx create-next-app@latest
19 | ```
20 |
21 | ### Example 2: Long-Running Functions
22 |
23 | `openai-realtime-console-example`: example of long-running functions, built on top of the realtime console
24 |
25 | To try it yourself from the console, clone the [OpenAI Realtime Console](https://github.com/openai/openai-realtime-console):
26 |
27 | ```bash
28 | git clone https://github.com/openai/openai-realtime-console.git
29 | ```
30 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "parserOptions": {
3 | "sourceType": "module"
4 | },
5 | "env": {
6 | "es2022": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # packaging
15 | *.zip
16 | *.tar.gz
17 | *.tar
18 | *.tgz
19 | *.bla
20 |
21 | # misc
22 | .DS_Store
23 | .env
24 | .env.local
25 | .env.development.local
26 | .env.test.local
27 | .env.production.local
28 |
29 | npm-debug.log*
30 | yarn-debug.log*
31 | yarn-error.log*
32 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 2,
3 | "useTabs": false,
4 | "singleQuote": true
5 | }
6 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 OpenAI
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | realtime console
8 |
9 |
13 |
14 |
20 |
25 |
26 |
27 |
28 |
29 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/public/openai-logomark.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/readme/realtime-console-demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/9-realtime/openai-realtime-console-example/readme/realtime-console-demo.png
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/relay-server/index.js:
--------------------------------------------------------------------------------
1 | import { RealtimeRelay } from './lib/relay.js';
2 | import dotenv from 'dotenv';
3 | dotenv.config({ override: true });
4 |
5 | const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
6 |
7 | if (!OPENAI_API_KEY) {
8 | console.error(
9 | `Environment variable "OPENAI_API_KEY" is required.\n` +
10 | `Please set it in your .env file.`
11 | );
12 | process.exit(1);
13 | }
14 |
15 | const PORT = parseInt(process.env.PORT) || 8081;
16 |
17 | const relay = new RealtimeRelay(OPENAI_API_KEY);
18 | relay.listen(PORT);
19 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/App.scss:
--------------------------------------------------------------------------------
1 | [data-component='App'] {
2 | height: 100%;
3 | width: 100%;
4 | position: relative;
5 | }
6 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/App.tsx:
--------------------------------------------------------------------------------
1 | import { ConsolePage } from './pages/ConsolePage';
2 | import './App.scss';
3 |
4 | function App() {
5 | return (
6 |
7 |
8 |
9 | );
10 | }
11 |
12 | export default App;
13 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/components/Map.scss:
--------------------------------------------------------------------------------
1 | [data-component='Map'] {
2 | position: absolute;
3 | width: 100%;
4 | height: 100%;
5 | .leaflet-container {
6 | height: 100%;
7 | width: 100%;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/components/Map.tsx:
--------------------------------------------------------------------------------
1 | import { MapContainer, TileLayer, Marker, Popup, useMap } from 'react-leaflet';
2 | import { LatLngTuple } from 'leaflet';
3 | import './Map.scss';
4 |
5 | function ChangeView({ center, zoom }: { center: LatLngTuple; zoom: number }) {
6 | const map = useMap();
7 | map.setView(center, zoom);
8 | return null;
9 | }
10 |
11 | export function Map({
12 | center,
13 | location = 'My Location',
14 | }: {
15 | center: LatLngTuple;
16 | location?: string;
17 | }) {
18 | return (
19 |
20 |
27 |
28 |
29 |
30 | {location}
31 |
32 |
33 |
34 | );
35 | }
36 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/components/button/Button.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import './Button.scss';
3 |
4 | import { Icon } from 'react-feather';
5 |
6 | interface ButtonProps extends React.ButtonHTMLAttributes {
7 | label?: string;
8 | icon?: Icon;
9 | iconPosition?: 'start' | 'end';
10 | iconColor?: 'red' | 'green' | 'grey';
11 | iconFill?: boolean;
12 | buttonStyle?: 'regular' | 'action' | 'alert' | 'flush';
13 | }
14 |
15 | export function Button({
16 | label = 'Okay',
17 | icon = void 0,
18 | iconPosition = 'start',
19 | iconColor = void 0,
20 | iconFill = false,
21 | buttonStyle = 'regular',
22 | ...rest
23 | }: ButtonProps) {
24 | const StartIcon = iconPosition === 'start' ? icon : null;
25 | const EndIcon = iconPosition === 'end' ? icon : null;
26 | const classList = [];
27 | if (iconColor) {
28 | classList.push(`icon-${iconColor}`);
29 | }
30 | if (iconFill) {
31 | classList.push(`icon-fill`);
32 | }
33 | classList.push(`button-style-${buttonStyle}`);
34 |
35 | return (
36 |
49 | );
50 | }
51 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/components/toggle/Toggle.scss:
--------------------------------------------------------------------------------
1 | [data-component='Toggle'] {
2 | position: relative;
3 | display: flex;
4 | align-items: center;
5 | gap: 8px;
6 | cursor: pointer;
7 | overflow: hidden;
8 |
9 | background-color: #ececf1;
10 | color: #101010;
11 | height: 40px;
12 | border-radius: 1000px;
13 |
14 | &:hover {
15 | background-color: #d8d8d8;
16 | }
17 |
18 | div.label {
19 | position: relative;
20 | color: #666;
21 | transition: color 0.1s ease-in-out;
22 | padding: 0px 16px;
23 | z-index: 2;
24 | user-select: none;
25 | }
26 |
27 | div.label.right {
28 | margin-left: -8px;
29 | }
30 |
31 | .toggle-background {
32 | background-color: #101010;
33 | position: absolute;
34 | top: 0px;
35 | left: 0px;
36 | width: auto;
37 | bottom: 0px;
38 | z-index: 1;
39 | border-radius: 1000px;
40 | transition: left 0.1s ease-in-out, width 0.1s ease-in-out;
41 | }
42 |
43 | &[data-enabled='true'] {
44 | div.label.right {
45 | color: #fff;
46 | }
47 | }
48 |
49 | &[data-enabled='false'] {
50 | div.label.left {
51 | color: #fff;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/index.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | padding: 0px;
4 | margin: 0px;
5 | position: relative;
6 | width: 100%;
7 | height: 100%;
8 | font-family: 'Assistant', sans-serif;
9 | font-optical-sizing: auto;
10 | font-weight: 400;
11 | font-style: normal;
12 | color: #18181b;
13 | -webkit-font-smoothing: antialiased;
14 | -moz-osx-font-smoothing: grayscale;
15 | }
16 |
17 | #root {
18 | position: relative;
19 | width: 100%;
20 | height: 100%;
21 | }
22 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
7 | const root = ReactDOM.createRoot(
8 | document.getElementById('root') as HTMLElement
9 | );
10 | root.render(
11 |
12 |
13 |
14 | );
15 |
16 | // If you want to start measuring performance in your app, pass a function
17 | // to log results (for example: reportWebVitals(console.log))
18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
19 | reportWebVitals();
20 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/index.d.ts:
--------------------------------------------------------------------------------
1 | import { AudioAnalysis } from './lib/analysis/audio_analysis.js';
2 | import { WavPacker } from './lib/wav_packer.js';
3 | import { WavStreamPlayer } from './lib/wav_stream_player.js';
4 | import { WavRecorder } from './lib/wav_recorder.js';
5 | export { AudioAnalysis, WavPacker, WavStreamPlayer, WavRecorder };
6 | //# sourceMappingURL=index.d.ts.map
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/index.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":"8BAC8B,kCAAkC;0BADtC,qBAAqB;gCAEf,4BAA4B;4BAChC,uBAAuB"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/analysis/audio_analysis.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"audio_analysis.d.ts","sourceRoot":"","sources":["../../../lib/analysis/audio_analysis.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AAEH;;;GAGG;AACH;IACE;;;;;;;;;;OAUG;IACH,gCARW,YAAY,cACZ,MAAM,cACN,YAAY,iBACZ,WAAW,GAAC,OAAO,GAAC,OAAO,gBAC3B,MAAM,gBACN,MAAM,GACJ,uBAAuB,CAwDnC;IAED;;;;;OAKG;IACH,0BAJW,gBAAgB,gBAChB,WAAW,GAAC,IAAI,EAkE1B;IA9DC,kBAAoB;IA2ClB,wBAAyB;IACzB,aAAkC;IAClC,cAAwB;IACxB,gBAA4B;IAC5B,iBAA8B;IAiBlC;;;;;;OAMG;IACH,8BALW,WAAW,GAAC,OAAO,GAAC,OAAO,gBAC3B,MAAM,gBACN,MAAM,GACJ,uBAAuB,CAwBnC;IAED;;;;OAIG;IACH,qBAFa,OAAO,CAAC,IAAI,CAAC,CAOzB;CACF;;;;;;;;YA9La,YAAY;;;;iBACZ,MAAM,EAAE;;;;YACR,MAAM,EAAE"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/analysis/constants.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * All note frequencies from 1st to 8th octave
3 | * in format "A#8" (A#, 8th octave)
4 | */
5 | export const noteFrequencies: any[];
6 | export const noteFrequencyLabels: any[];
7 | export const voiceFrequencies: any[];
8 | export const voiceFrequencyLabels: any[];
9 | //# sourceMappingURL=constants.d.ts.map
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/analysis/constants.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../lib/analysis/constants.js"],"names":[],"mappings":"AA6BA;;;GAGG;AACH,oCAAkC;AAClC,wCAAsC;AActC,qCAKG;AACH,yCAKG"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/wav_packer.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"wav_packer.d.ts","sourceRoot":"","sources":["../../lib/wav_packer.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH;IACE;;;;OAIG;IACH,qCAHW,YAAY,GACV,WAAW,CAWvB;IAED;;;;;OAKG;IACH,gCAJW,WAAW,eACX,WAAW,GACT,WAAW,CASvB;IAED;;;;;;OAMG;IACH,kBAKC;IAED;;;;;OAKG;IACH,iBAJW,MAAM,SACN;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAC,GACtE,kBAAkB,CA6C9B;CACF;;;;;UA3Ga,IAAI;SACJ,MAAM;kBACN,MAAM;gBACN,MAAM;cACN,MAAM"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/wav_recorder.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"wav_recorder.d.ts","sourceRoot":"","sources":["../../lib/wav_recorder.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH;;;GAGG;AACH;IAsCE;;;;;;OAMG;IACH,yBALW,IAAI,GAAC,YAAY,GAAC,UAAU,GAAC,WAAW,GAAC,MAAM,EAAE,eACjD,MAAM,mBACN,MAAM,GACJ,OAAO,CAAC,gBAAgB,CAAC,CAqErC;IA/GD;;;;OAIG;IACH,uDAHW;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAC,EAiC5E;IAxBC,eAAkC;IAElC,mBAA4B;IAC5B,0BAAwC;IACxC,eAAoB;IACpB,2CAAiC;IACjC,gBAAkB;IAElB,YAAkB;IAClB,eAAqB;IACrB,YAAkB;IAClB,UAAgB;IAChB,mBAAsB;IAEtB,qBAAqB;IACrB,kBAAuB;IACvB,qBAAwB;IAExB,4BAA+B;IAE/B;;;MAGC;IA+EH;;;;OAIG;IACH,qBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,iBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,aAFa,OAAO,GAAC,QAAQ,GAAC,WAAW,CAUxC;IAED;;;;;;;OAOG;IACH,eAqBC;IAED;;;;OAIG;IACH,sCAFa,IAAI,CAmChB;IAED;;;OAGG;IACH,qBAFa,OAAO,CAAC,IAAI,CAAC,CAoBzB;IAED;;;OAGG;IACH,eAFa,OAAO,CAAC,KAAK,CAAC,eAAe,GAAG;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC,CAAC,CAAC,CA8BhE;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAkFzB;IAHC,cAAwB;IAK1B;;;;;;OAMG;IACH,8BALW,WAAW,GAAC,OAAO,GAAC,OAAO,gBAC3B,MAAM,gBACN,MAAM,GACJ,OAAO,8BAA8B,EAAE,uBAAuB,CAkB1E;IAED;;;;OAIG;IACH,SAFa,OAAO,CAAC,IAAI,CAAC,CAezB;IAED;;;;;OAKG;IACH,wBAJW,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;KAAE,KAAK,GAAG,cACpD,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAoBzB;IATC,4BAAoC;IAWtC;;;OAGG;IACH,SAFa,OAAO,CAAC,IAAI,CAAC,CAQzB;IAED;;;OAGG;IACH,QAFa,OAAO,CAAC;QAAC,UAAU,EAAE,YAAY,CAAC;QAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;KAAC,CAAC,CAS9E;IAED;;;;OAIG;IACH,aAHW,OAAO,GACL,OAAO,CAAC,OAAO,iBAAiB,EAAE,kBAAkB,CAAC,CAgBjE;IAED;;;OAGG;IACH,OAFa,OAAO,CAAC,OAAO,iBAAiB,EAAE,kBAAkB,CAAC,CA8BjE;IAED;;;;OAIG;IACH,QAFa,OAAO,CAAC,IAAI,CAAC,CAQzB;CACF;;;;;UA1hBa,IAAI;SACJ,MAAM;YACN,YAAY;iBACZ,WAAW"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/wav_stream_player.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"wav_stream_player.d.ts","sourceRoot":"","sources":["../../lib/wav_stream_player.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH;IACE;;;;OAIG;IACH,6BAHW;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAC,EAW/B;IAPC,eAAmC;IACnC,mBAA4B;IAC5B,aAAmB;IACnB,YAAkB;IAClB,cAAoB;IACpB,uBAA4B;IAC5B,wBAA6B;IAG/B;;;OAGG;IACH,WAFa,OAAO,CAAC,IAAI,CAAC,CAkBzB;IAED;;;;;;OAMG;IACH,8BALW,WAAW,GAAC,OAAO,GAAC,OAAO,gBAC3B,MAAM,gBACN,MAAM,GACJ,OAAO,8BAA8B,EAAE,uBAAuB,CAkB1E;IAED;;;;OAIG;IACH,eAkBC;IAED;;;;;;OAMG;IACH,yBAJW,WAAW,GAAC,UAAU,YACtB,MAAM,GACJ,UAAU,CAqBtB;IAED;;;;OAIG;IACH,iCAHW,OAAO,GACL;QAAC,OAAO,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAC,CAqBvE;IAED;;;;OAIG;IACH,aAFa;QAAC,OAAO,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAC,CAIvE;CACF"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/worklets/audio_processor.d.ts:
--------------------------------------------------------------------------------
1 | export const AudioProcessorSrc: any;
2 | //# sourceMappingURL=audio_processor.d.ts.map
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/worklets/audio_processor.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"audio_processor.d.ts","sourceRoot":"","sources":["../../../lib/worklets/audio_processor.js"],"names":[],"mappings":"AAqNA,oCAAqC"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/dist/lib/worklets/stream_processor.d.ts.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"stream_processor.d.ts","sourceRoot":"","sources":["../../../lib/worklets/stream_processor.js"],"names":[],"mappings":"AAAA,q4FAyFE;AAMF,qCAAsC"}
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/index.js:
--------------------------------------------------------------------------------
1 | import { WavPacker } from './lib/wav_packer.js';
2 | import { AudioAnalysis } from './lib/analysis/audio_analysis.js';
3 | import { WavStreamPlayer } from './lib/wav_stream_player.js';
4 | import { WavRecorder } from './lib/wav_recorder.js';
5 |
6 | export { AudioAnalysis, WavPacker, WavStreamPlayer, WavRecorder };
7 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/lib/wavtools/lib/analysis/constants.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Constants for help with visualization
3 | * Helps map frequency ranges from Fast Fourier Transform
4 | * to human-interpretable ranges, notably music ranges and
5 | * human vocal ranges.
6 | */
7 |
8 | // Eighth octave frequencies
9 | const octave8Frequencies = [
10 | 4186.01, 4434.92, 4698.63, 4978.03, 5274.04, 5587.65, 5919.91, 6271.93,
11 | 6644.88, 7040.0, 7458.62, 7902.13,
12 | ];
13 |
14 | // Labels for each of the above frequencies
15 | const octave8FrequencyLabels = [
16 | 'C',
17 | 'C#',
18 | 'D',
19 | 'D#',
20 | 'E',
21 | 'F',
22 | 'F#',
23 | 'G',
24 | 'G#',
25 | 'A',
26 | 'A#',
27 | 'B',
28 | ];
29 |
30 | /**
31 | * All note frequencies from 1st to 8th octave
32 | * in format "A#8" (A#, 8th octave)
33 | */
34 | export const noteFrequencies = [];
35 | export const noteFrequencyLabels = [];
36 | for (let i = 1; i <= 8; i++) {
37 | for (let f = 0; f < octave8Frequencies.length; f++) {
38 | const freq = octave8Frequencies[f];
39 | noteFrequencies.push(freq / Math.pow(2, 8 - i));
40 | noteFrequencyLabels.push(octave8FrequencyLabels[f] + i);
41 | }
42 | }
43 |
44 | /**
45 | * Subset of the note frequencies between 32 and 2000 Hz
46 | * 6 octave range: C1 to B6
47 | */
48 | const voiceFrequencyRange = [32.0, 2000.0];
49 | export const voiceFrequencies = noteFrequencies.filter((_, i) => {
50 | return (
51 | noteFrequencies[i] > voiceFrequencyRange[0] &&
52 | noteFrequencies[i] < voiceFrequencyRange[1]
53 | );
54 | });
55 | export const voiceFrequencyLabels = noteFrequencyLabels.filter((_, i) => {
56 | return (
57 | noteFrequencies[i] > voiceFrequencyRange[0] &&
58 | noteFrequencies[i] < voiceFrequencyRange[1]
59 | );
60 | });
61 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/reportWebVitals.ts:
--------------------------------------------------------------------------------
1 | import { ReportHandler } from 'web-vitals';
2 |
3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4 | if (onPerfEntry && onPerfEntry instanceof Function) {
5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6 | getCLS(onPerfEntry);
7 | getFID(onPerfEntry);
8 | getFCP(onPerfEntry);
9 | getLCP(onPerfEntry);
10 | getTTFB(onPerfEntry);
11 | });
12 | }
13 | };
14 |
15 | export default reportWebVitals;
16 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/setupTests.ts:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/src/utils/conversation_config.js:
--------------------------------------------------------------------------------
1 | export const instructions = `
2 |
3 | You are a personal assistant.
4 |
5 | always respond in only 2-6 words
6 |
7 | When the user asks a question about their email, use the submit_email_query function.
8 | - call the function immediately before responding
9 |
10 | `;
11 |
--------------------------------------------------------------------------------
/9-realtime/openai-realtime-console-example/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "lib": ["dom", "dom.iterable", "esnext", "ES2020"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "esModuleInterop": true,
8 | "allowSyntheticDefaultImports": true,
9 | "strict": true,
10 | "forceConsistentCasingInFileNames": true,
11 | "noFallthroughCasesInSwitch": true,
12 | "module": "esnext",
13 | "moduleResolution": "node",
14 | "resolveJsonModule": true,
15 | "isolatedModules": true,
16 | "noEmit": true,
17 | "jsx": "react-jsx"
18 | },
19 | "include": ["src", "src/lib"]
20 | }
21 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.*
7 | .yarn/*
8 | !.yarn/patches
9 | !.yarn/plugins
10 | !.yarn/releases
11 | !.yarn/versions
12 |
13 | # testing
14 | /coverage
15 |
16 | # next.js
17 | /.next/
18 | /out/
19 |
20 | # production
21 | /build
22 |
23 | # misc
24 | .DS_Store
25 | *.pem
26 |
27 | # debug
28 | npm-debug.log*
29 | yarn-debug.log*
30 | yarn-error.log*
31 |
32 | # env files (can opt-in for committing if needed)
33 | .env*
34 |
35 | # vercel
36 | .vercel
37 |
38 | # typescript
39 | *.tsbuildinfo
40 | next-env.d.ts
41 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/README.md:
--------------------------------------------------------------------------------
1 | This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2 |
3 | ## Getting Started
4 |
5 | First, run the development server:
6 |
7 | ```bash
8 | npm run dev
9 | # or
10 | yarn dev
11 | # or
12 | pnpm dev
13 | # or
14 | bun dev
15 | ```
16 |
17 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18 |
19 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20 |
21 | This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22 |
23 | ## Learn More
24 |
25 | To learn more about Next.js, take a look at the following resources:
26 |
27 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29 |
30 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31 |
32 | ## Deploy on Vercel
33 |
34 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35 |
36 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
37 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/9-realtime/realtime-from-scratch/app/favicon.ico
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/app/fonts/GeistMonoVF.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/9-realtime/realtime-from-scratch/app/fonts/GeistMonoVF.woff
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/app/fonts/GeistVF.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openai/build-hours/97301b74033ee3c0b629ba1d13e5909e9def87dd/9-realtime/realtime-from-scratch/app/fonts/GeistVF.woff
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/app/globals.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
5 | :root {
6 | --background: #ffffff;
7 | --foreground: #171717;
8 | }
9 |
10 | @media (prefers-color-scheme: dark) {
11 | :root {
12 | --background: #0a0a0a;
13 | --foreground: #ededed;
14 | }
15 | }
16 |
17 | body {
18 | color: var(--foreground);
19 | background: var(--background);
20 | font-family: Arial, Helvetica, sans-serif;
21 | }
22 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import type { Metadata } from "next";
2 | import localFont from "next/font/local";
3 | import "./globals.css";
4 |
5 | const geistSans = localFont({
6 | src: "./fonts/GeistVF.woff",
7 | variable: "--font-geist-sans",
8 | weight: "100 900",
9 | });
10 | const geistMono = localFont({
11 | src: "./fonts/GeistMonoVF.woff",
12 | variable: "--font-geist-mono",
13 | weight: "100 900",
14 | });
15 |
16 | export const metadata: Metadata = {
17 | title: "Create Next App",
18 | description: "Generated by create next app",
19 | };
20 |
21 | export default function RootLayout({
22 | children,
23 | }: Readonly<{
24 | children: React.ReactNode;
25 | }>) {
26 | return (
27 |
28 |
31 | {children}
32 |
33 |
34 | );
35 | }
36 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/next.config.ts:
--------------------------------------------------------------------------------
1 | import type { NextConfig } from "next";
2 |
3 | const nextConfig: NextConfig = {
4 | /* config options here */
5 | };
6 |
7 | export default nextConfig;
8 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "realtime-from-scratch",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "dotenv": "^16.4.5",
13 | "next": "15.0.3",
14 | "react": "19.0.0-rc-66855b96-20241106",
15 | "react-dom": "19.0.0-rc-66855b96-20241106"
16 | },
17 | "devDependencies": {
18 | "@types/node": "^20",
19 | "@types/react": "^18",
20 | "@types/react-dom": "^18",
21 | "postcss": "^8",
22 | "tailwindcss": "^3.4.1",
23 | "typescript": "^5"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/postcss.config.mjs:
--------------------------------------------------------------------------------
1 | /** @type {import('postcss-load-config').Config} */
2 | const config = {
3 | plugins: {
4 | tailwindcss: {},
5 | },
6 | };
7 |
8 | export default config;
9 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/public/file.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/public/globe.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/public/next.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/public/vercel.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/public/window.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/tailwind.config.ts:
--------------------------------------------------------------------------------
1 | import type { Config } from "tailwindcss";
2 |
3 | export default {
4 | content: [
5 | "./pages/**/*.{js,ts,jsx,tsx,mdx}",
6 | "./components/**/*.{js,ts,jsx,tsx,mdx}",
7 | "./app/**/*.{js,ts,jsx,tsx,mdx}",
8 | ],
9 | theme: {
10 | extend: {
11 | colors: {
12 | background: "var(--background)",
13 | foreground: "var(--foreground)",
14 | },
15 | },
16 | },
17 | plugins: [],
18 | } satisfies Config;
19 |
--------------------------------------------------------------------------------
/9-realtime/realtime-from-scratch/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2017",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "noEmit": true,
9 | "esModuleInterop": true,
10 | "module": "esnext",
11 | "moduleResolution": "bundler",
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "jsx": "preserve",
15 | "incremental": true,
16 | "plugins": [
17 | {
18 | "name": "next"
19 | }
20 | ],
21 | "paths": {
22 | "@/*": ["./*"]
23 | }
24 | },
25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26 | "exclude": ["node_modules"]
27 | }
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2024 OpenAI
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Build Hours
2 |
3 | Build Hours are monthly events designed for startup founders and developers to explore specific ideas for leveraging OpenAI’s API and models across diverse topics. Be sure to check out [on-demand library](https://vimeo.com/showcase/openaibuildhours).
4 |
5 | At OpenAI, we’re committed to supporting startups at every stage—from concept to scale. Let’s build the future together!
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------