Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
allenanie committed Dec 10, 2024
1 parent f21de5f commit aa485ba
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 8 deletions.
53 changes: 53 additions & 0 deletions _sources/examples/game/battleship.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,59 @@
"from autogen import config_list_from_json"
]
},
{
"metadata": {"tags": ["hide-input"]},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import os\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"# Function to save the environment variable and API key\n",
"def save_env_variable(env_name, api_key):\n",
" # Validate inputs\n",
" if not env_name.strip():\n",
" print(\"⚠️ Environment variable name cannot be empty.\")\n",
" return\n",
" if not api_key.strip():\n",
" print(\"⚠️ API key cannot be empty.\")\n",
" return\n",
" \n",
" # Store the API key as an environment variable\n",
" os.environ[env_name] = api_key\n",
" globals()[env_name] = api_key # Set it as a global variable\n",
" print(f\"✅ API key has been set for environment variable: {env_name}\")\n",
"\n",
"# Create the input widgets\n",
"env_name_input = widgets.Text(\n",
" value=\"OPENAI_API_KEY\", # Default value\n",
" description=\"Env Name:\",\n",
" placeholder=\"Enter env variable name (e.g., MY_API_KEY)\",\n",
")\n",
"\n",
"api_key_input = widgets.Password(\n",
" description=\"API Key:\",\n",
" placeholder=\"Enter your API key\",\n",
")\n",
"\n",
"# Create the button to submit the inputs\n",
"submit_button = widgets.Button(description=\"Set API Key\")\n",
"\n",
"# Display the widgets\n",
"display(env_name_input, api_key_input, submit_button)\n",
"\n",
"# Callback function for the button click\n",
"def on_button_click(b):\n",
" env_name = env_name_input.value\n",
" api_key = api_key_input.value\n",
" save_env_variable(env_name, api_key)\n",
"\n",
"# Attach the callback to the button\n",
"submit_button.on_click(on_button_click)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
53 changes: 53 additions & 0 deletions _sources/examples/nlp/bigbench_hard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,59 @@
"import re"
]
},
{
"metadata": {"tags": ["hide-input"]},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import os\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"# Function to save the environment variable and API key\n",
"def save_env_variable(env_name, api_key):\n",
" # Validate inputs\n",
" if not env_name.strip():\n",
" print(\"⚠️ Environment variable name cannot be empty.\")\n",
" return\n",
" if not api_key.strip():\n",
" print(\"⚠️ API key cannot be empty.\")\n",
" return\n",
" \n",
" # Store the API key as an environment variable\n",
" os.environ[env_name] = api_key\n",
" globals()[env_name] = api_key # Set it as a global variable\n",
" print(f\"✅ API key has been set for environment variable: {env_name}\")\n",
"\n",
"# Create the input widgets\n",
"env_name_input = widgets.Text(\n",
" value=\"OPENAI_API_KEY\", # Default value\n",
" description=\"Env Name:\",\n",
" placeholder=\"Enter env variable name (e.g., MY_API_KEY)\",\n",
")\n",
"\n",
"api_key_input = widgets.Password(\n",
" description=\"API Key:\",\n",
" placeholder=\"Enter your API key\",\n",
")\n",
"\n",
"# Create the button to submit the inputs\n",
"submit_button = widgets.Button(description=\"Set API Key\")\n",
"\n",
"# Display the widgets\n",
"display(env_name_input, api_key_input, submit_button)\n",
"\n",
"# Callback function for the button click\n",
"def on_button_click(b):\n",
" env_name = env_name_input.value\n",
" api_key = api_key_input.value\n",
" save_env_variable(env_name, api_key)\n",
"\n",
"# Attach the callback to the button\n",
"submit_button.on_click(on_button_click)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
67 changes: 60 additions & 7 deletions _sources/examples/robotics/metaworld.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,59 @@
"from opto.trace.errors import ExecutionError\n"
]
},
{
"metadata": {"tags": ["hide-input"]},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import os\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"# Function to save the environment variable and API key\n",
"def save_env_variable(env_name, api_key):\n",
" # Validate inputs\n",
" if not env_name.strip():\n",
" print(\"⚠️ Environment variable name cannot be empty.\")\n",
" return\n",
" if not api_key.strip():\n",
" print(\"⚠️ API key cannot be empty.\")\n",
" return\n",
" \n",
" # Store the API key as an environment variable\n",
" os.environ[env_name] = api_key\n",
" globals()[env_name] = api_key # Set it as a global variable\n",
" print(f\"✅ API key has been set for environment variable: {env_name}\")\n",
"\n",
"# Create the input widgets\n",
"env_name_input = widgets.Text(\n",
" value=\"OPENAI_API_KEY\", # Default value\n",
" description=\"Env Name:\",\n",
" placeholder=\"Enter env variable name (e.g., MY_API_KEY)\",\n",
")\n",
"\n",
"api_key_input = widgets.Password(\n",
" description=\"API Key:\",\n",
" placeholder=\"Enter your API key\",\n",
")\n",
"\n",
"# Create the button to submit the inputs\n",
"submit_button = widgets.Button(description=\"Set API Key\")\n",
"\n",
"# Display the widgets\n",
"display(env_name_input, api_key_input, submit_button)\n",
"\n",
"# Callback function for the button click\n",
"def on_button_click(b):\n",
" env_name = env_name_input.value\n",
" api_key = api_key_input.value\n",
" save_env_variable(env_name, api_key)\n",
"\n",
"# Attach the callback to the button\n",
"submit_button.on_click(on_button_click)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -279,15 +332,15 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:32: UserWarning: \u001b[33mWARN: A Box observation space maximum and minimum values are equal. Actual equal coordinates: [(36,), (37,), (38,)]\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:32: UserWarning: \u001B[33mWARN: A Box observation space maximum and minimum values are equal. Actual equal coordinates: [(36,), (37,), (38,)]\u001B[0m\n",
" logger.warn(\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:159: UserWarning: \u001b[33mWARN: The obs returned by the `reset()` method is not within the observation space.\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:159: UserWarning: \u001B[33mWARN: The obs returned by the `reset()` method is not within the observation space.\u001B[0m\n",
" logger.warn(f\"{pre} is not within the observation space.\")\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:131: UserWarning: \u001b[33mWARN: The obs returned by the `reset()` method was expecting a numpy array, actual type: <class 'str'>\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:131: UserWarning: \u001B[33mWARN: The obs returned by the `reset()` method was expecting a numpy array, actual type: <class 'str'>\u001B[0m\n",
" logger.warn(\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/spaces/box.py:240: UserWarning: \u001b[33mWARN: Casting input x to numpy array.\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/spaces/box.py:240: UserWarning: \u001B[33mWARN: Casting input x to numpy array.\u001B[0m\n",
" gym.logger.warn(\"Casting input x to numpy array.\")\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/core.py:311: UserWarning: \u001b[33mWARN: env.control_mode to get variables from other wrappers is deprecated and will be removed in v1.0, to get this variable you can do `env.unwrapped.control_mode` for environment variables or `env.get_wrapper_attr('control_mode')` that will search the reminding wrappers.\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/core.py:311: UserWarning: \u001B[33mWARN: env.control_mode to get variables from other wrappers is deprecated and will be removed in v1.0, to get this variable you can do `env.unwrapped.control_mode` for environment variables or `env.get_wrapper_attr('control_mode')` that will search the reminding wrappers.\u001B[0m\n",
" logger.warn(\n"
]
},
Expand All @@ -302,9 +355,9 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:159: UserWarning: \u001b[33mWARN: The obs returned by the `step()` method is not within the observation space.\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:159: UserWarning: \u001B[33mWARN: The obs returned by the `step()` method is not within the observation space.\u001B[0m\n",
" logger.warn(f\"{pre} is not within the observation space.\")\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:131: UserWarning: \u001b[33mWARN: The obs returned by the `step()` method was expecting a numpy array, actual type: <class 'str'>\u001b[0m\n",
"/home/chinganc/miniconda3/envs/trace/lib/python3.8/site-packages/gymnasium/utils/passive_env_checker.py:131: UserWarning: \u001B[33mWARN: The obs returned by the `step()` method was expecting a numpy array, actual type: <class 'str'>\u001B[0m\n",
" logger.warn(\n"
]
},
Expand Down
54 changes: 54 additions & 0 deletions _sources/quickstart/quick_start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,60 @@
"%pip install trace-opt"
]
},
{
"metadata": {"tags": ["hide-input"]},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import os\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"# Function to save the environment variable and API key\n",
"def save_env_variable(env_name, api_key):\n",
" # Validate inputs\n",
" if not env_name.strip():\n",
" print(\"⚠️ Environment variable name cannot be empty.\")\n",
" return\n",
" if not api_key.strip():\n",
" print(\"⚠️ API key cannot be empty.\")\n",
" return\n",
" \n",
" # Store the API key as an environment variable\n",
" os.environ[env_name] = api_key\n",
" globals()[env_name] = api_key # Set it as a global variable\n",
" print(f\"✅ API key has been set for environment variable: {env_name}\")\n",
"\n",
"# Create the input widgets\n",
"env_name_input = widgets.Text(\n",
" value=\"OPENAI_API_KEY\", # Default value\n",
" description=\"Env Name:\",\n",
" placeholder=\"Enter env variable name (e.g., MY_API_KEY)\",\n",
")\n",
"\n",
"api_key_input = widgets.Password(\n",
" description=\"API Key:\",\n",
" placeholder=\"Enter your API key\",\n",
")\n",
"\n",
"# Create the button to submit the inputs\n",
"submit_button = widgets.Button(description=\"Set API Key\")\n",
"\n",
"# Display the widgets\n",
"display(env_name_input, api_key_input, submit_button)\n",
"\n",
"# Callback function for the button click\n",
"def on_button_click(b):\n",
" env_name = env_name_input.value\n",
" api_key = api_key_input.value\n",
" save_env_variable(env_name, api_key)\n",
"\n",
"# Attach the callback to the button\n",
"submit_button.on_click(on_button_click)"
],
"id": "150ebe0c019eb767"
},
{
"cell_type": "markdown",
"id": "1c6eec8b500e7966",
Expand Down
54 changes: 54 additions & 0 deletions _sources/quickstart/quick_start_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,60 @@
"from opto.optimizers import OptoPrime"
]
},
{
"metadata": {"tags": ["hide-input"]},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import os\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"# Function to save the environment variable and API key\n",
"def save_env_variable(env_name, api_key):\n",
" # Validate inputs\n",
" if not env_name.strip():\n",
" print(\"⚠️ Environment variable name cannot be empty.\")\n",
" return\n",
" if not api_key.strip():\n",
" print(\"⚠️ API key cannot be empty.\")\n",
" return\n",
" \n",
" # Store the API key as an environment variable\n",
" os.environ[env_name] = api_key\n",
" globals()[env_name] = api_key # Set it as a global variable\n",
" print(f\"✅ API key has been set for environment variable: {env_name}\")\n",
"\n",
"# Create the input widgets\n",
"env_name_input = widgets.Text(\n",
" value=\"OPENAI_API_KEY\", # Default value\n",
" description=\"Env Name:\",\n",
" placeholder=\"Enter env variable name (e.g., MY_API_KEY)\",\n",
")\n",
"\n",
"api_key_input = widgets.Password(\n",
" description=\"API Key:\",\n",
" placeholder=\"Enter your API key\",\n",
")\n",
"\n",
"# Create the button to submit the inputs\n",
"submit_button = widgets.Button(description=\"Set API Key\")\n",
"\n",
"# Display the widgets\n",
"display(env_name_input, api_key_input, submit_button)\n",
"\n",
"# Callback function for the button click\n",
"def on_button_click(b):\n",
" env_name = env_name_input.value\n",
" api_key = api_key_input.value\n",
" save_env_variable(env_name, api_key)\n",
"\n",
"# Attach the callback to the button\n",
"submit_button.on_click(on_button_click)"
],
"id": "dea338357fc76304"
},
{
"cell_type": "markdown",
"id": "fa000905-9028-4f6b-b42a-5a421ebf31c6",
Expand Down
Loading

0 comments on commit aa485ba

Please sign in to comment.