|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "# PLATFORM ROLLOUT\n", |
| 10 | + "import os\n", |
| 11 | + "import time\n", |
| 12 | + "import json\n", |
| 13 | + "from futurehouse_client import FutureHouseClient\n", |
| 14 | + "from futurehouse_client.models import Stage, TaskRequest, RuntimeConfig\n", |
| 15 | + "from futurehouse_client.models.app import AuthType\n", |
| 16 | + "import fhda.prompts as prompts\n", |
| 17 | + "from ldp.agent import AgentConfig\n", |
| 18 | + "\n", |
| 19 | + "# CONFIGURATION\n", |
| 20 | + "CROW_STAGE = Stage.PROD # Don't change this\n", |
| 21 | + "API_KEY = \"\" # Add your API key here\n", |
| 22 | + "JOB_NAME = \"job-futurehouse-data-analysis-crow-high\" # Don't change this\n", |
| 23 | + "MAX_STEPS = 30 # You can change this to impose a limit on the number of steps\n", |
| 24 | + "LANGUAGE = \"R\" # Choose between \"R\" and \"PYTHON\"\n", |
| 25 | + "DATA_GCS_LOCATION = \"eda/flow0\" # This is the location of the dataset on GCS – ask someone from FutureHouse to upload new datasets\n", |
| 26 | + "MODEL_NAME = \"claude-3-7-sonnet-latest\" # Feel free to use any Litellm supported model\n", |
| 27 | + "TEMPERATURE = 1.0 # Feel free to try different model temperatures\n", |
| 28 | + "\n", |
| 29 | + "# Here is where you can update the prompt. As shown below, by default we use CoT prompting,\n", |
| 30 | + "# but it is not necessary and we encourage users to experiment with different prompting strategies.\n", |
| 31 | + "query = \"\"\"\n", |
| 32 | + "Make a discovery using this dataset\n", |
| 33 | + "\"\"\"\n", |
| 34 | + "\n", |
| 35 | + "task = f\"\"\"\\\n", |
| 36 | + "Here is the user query to address:\n", |
| 37 | + "\n", |
| 38 | + "<query>\n", |
| 39 | + "{query}\n", |
| 40 | + "</query>\n", |
| 41 | + "{prompts.CHAIN_OF_THOUGHT_AGNOSTIC.format(language=LANGUAGE)}\n", |
| 42 | + "{prompts.GENERAL_NOTEBOOK_GUIDELINES.format(language=LANGUAGE)}\"\"\"\n", |
| 43 | + "\n", |
| 44 | + "# This is extra R prompting to avoid long R output blocks\n", |
| 45 | + "if LANGUAGE == \"R\":\n", |
| 46 | + " task += f\"\\n{prompts.R_OUTPUT_RECOMMENDATION_PROMPT}\"\n", |
| 47 | + "\n", |
| 48 | + "\n", |
| 49 | + "# You shouldn't have to change anything below here\n", |
| 50 | + "client = FutureHouseClient(\n", |
| 51 | + " stage=CROW_STAGE,\n", |
| 52 | + " auth_type=AuthType.API_KEY,\n", |
| 53 | + " api_key=API_KEY,\n", |
| 54 | + ")\n", |
| 55 | + "\n", |
| 56 | + "job_data = TaskRequest(\n", |
| 57 | + " name=JOB_NAME,\n", |
| 58 | + " query=task,\n", |
| 59 | + " runtime_config=RuntimeConfig(\n", |
| 60 | + " max_steps=MAX_STEPS,\n", |
| 61 | + " upload_id=DATA_GCS_LOCATION, # This is just an example dataset\n", |
| 62 | + " environment_config={\n", |
| 63 | + " \"run_notebook_on_edit\": False,\n", |
| 64 | + " \"eval\": True, # DO NOT CHANGE THIS\n", |
| 65 | + " \"language\": LANGUAGE,\n", |
| 66 | + " },\n", |
| 67 | + " agent=AgentConfig(\n", |
| 68 | + " agent_type=\"ReActAgent\",\n", |
| 69 | + " agent_kwargs={\n", |
| 70 | + " \"llm_model\": {\"name\": MODEL_NAME, \"temperature\": TEMPERATURE},\n", |
| 71 | + " },\n", |
| 72 | + " ),\n", |
| 73 | + " ),\n", |
| 74 | + ")\n", |
| 75 | + "job_id = client.create_task(job_data)\n", |
| 76 | + "status = \"in progress\"\n", |
| 77 | + "while status in [\"in progress\", \"queued\"]:\n", |
| 78 | + " print(\"Waiting for task to complete... checking again in 30 seconds\")\n", |
| 79 | + " time.sleep(15)\n", |
| 80 | + " status = client.get_task(job_id).status\n", |
| 81 | + "\n", |
| 82 | + "if status == \"failed\":\n", |
| 83 | + " raise Exception(\"Task failed\")\n", |
| 84 | + "\n", |
| 85 | + "job_result = client.get_task(job_id, verbose=True)\n", |
| 86 | + "answer = job_result.environment_frame[\"state\"][\"state\"][\"answer\"]\n", |
| 87 | + "print(\n", |
| 88 | + " f\"Task completed, the full analysis is available at:https://platform.futurehouse.org/trajectories/{job_id}\\n Agent answer: {answer}\"\n", |
| 89 | + ")" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [], |
| 97 | + "source": [ |
| 98 | + "# You can also view the notebook locally by saving it to a directory of your choice\n", |
| 99 | + "# Define the path where you want to save the notebook\n", |
| 100 | + "notebook_path = \"output/analysis_notebook.ipynb\"\n", |
| 101 | + "\n", |
| 102 | + "os.makedirs(os.path.dirname(notebook_path), exist_ok=True)\n", |
| 103 | + "notebook_content = job_result.environment_frame[\"state\"][\"state\"][\"nb_state\"]\n", |
| 104 | + "with open(notebook_path, \"w\") as f:\n", |
| 105 | + " json.dump(notebook_content, f, indent=2)\n", |
| 106 | + "\n", |
| 107 | + "print(f\"Notebook saved to {os.path.abspath(notebook_path)}\")" |
| 108 | + ] |
| 109 | + } |
| 110 | + ], |
| 111 | + "metadata": { |
| 112 | + "kernelspec": { |
| 113 | + "display_name": ".venv", |
| 114 | + "language": "python", |
| 115 | + "name": "python3" |
| 116 | + }, |
| 117 | + "language_info": { |
| 118 | + "codemirror_mode": { |
| 119 | + "name": "ipython", |
| 120 | + "version": 3 |
| 121 | + }, |
| 122 | + "file_extension": ".py", |
| 123 | + "mimetype": "text/x-python", |
| 124 | + "name": "python", |
| 125 | + "nbconvert_exporter": "python", |
| 126 | + "pygments_lexer": "ipython3" |
| 127 | + } |
| 128 | + }, |
| 129 | + "nbformat": 4, |
| 130 | + "nbformat_minor": 2 |
| 131 | +} |
0 commit comments