Skip to content

Improved code cell formatting in fireworks_firefunction_openai_qa.ipynb #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@
"To run this notebook locally, follow these steps:\n",
"\n",
"### Step 1: Create a Virtual Environment\n",
"In your terminal, navigate to the directory where this notebook is located and run:\n",
"```bash\n",
"In your terminal, navigate to the directory where this notebook is located and run:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4786d368",
"metadata": {},
"outputs": [],
"source": [
"python3 -m venv venv\n",
"source venv/bin/activate # On macOS/Linux\n",
".\u000benv\\Scripts\u0007ctivate # On Windows"
"venv\\Scripts\\activate # On Windows"
]
},
{
Expand All @@ -64,38 +72,96 @@
"metadata": {},
"source": [
"### Step 2: Install Required Libraries\n",
"Install the necessary packages:\n",
"```bash\n",
"pip install jupyter openai python-dotenv\n",
"```"
"Install the necessary packages:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad371e1e",
"metadata": {},
"outputs": [],
"source": [
"\n",
"pip install jupyter openai python-dotenv"
]
},
{
"cell_type": "markdown",
"id": "903bce74",
"id": "f9d0cd75",
"metadata": {},
"source": [
"### Step 3: Set Up Your API Key\n",
"You can set your API key in the terminal:\n",
"- **On macOS/Linux**:\n",
" ```bash\n",
" export FIREWORKS_API_KEY=<YOUR_FIREWORKS_API_KEY>\n",
" ```\n",
"- **On Windows**:\n",
" ```bash\n",
" set FIREWORKS_API_KEY=<YOUR_FIREWORKS_API_KEY>\n",
" ```\n",
"\n",
"- **On macOS/Linux**:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ca97097c",
"metadata": {},
"outputs": [],
"source": [
"export FIREWORKS_API_KEY=<YOUR_FIREWORKS_API_KEY>"
]
},
{
"cell_type": "markdown",
"id": "bcd598e0",
"metadata": {},
"source": [
"- **On Windows**:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8abba863",
"metadata": {},
"outputs": [],
"source": [
"set FIREWORKS_API_KEY=<YOUR_FIREWORKS_API_KEY>"
]
},
{
"cell_type": "markdown",
"id": "903bce74",
"metadata": {},
"source": [
"Alternatively, create a `.env` file in the project directory with:\n",
"```\n",
"FIREWORKS_API_KEY=<YOUR_FIREWORKS_API_KEY>\n",
"```\n",
"\n",
"Load the `.env` file in your Python code with:\n",
"```python\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ea921da",
"metadata": {},
"outputs": [],
"source": [
"FIREWORKS_API_KEY=<YOUR_FIREWORKS_API_KEY>"
]
},
{
"cell_type": "markdown",
"id": "880125c5",
"metadata": {},
"source": [
"Load the `.env` file in your Python code with:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9548c910",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"```\n"
"load_dotenv()"
]
},
{
Expand All @@ -104,10 +170,24 @@
"metadata": {},
"source": [
"### Step 4: Launch Jupyter Notebook\n",
"Start the Jupyter Notebook server:\n",
"```bash\n",
"jupyter notebook\n",
"```\n",
"Start the Jupyter Notebook server:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fdc8c243",
"metadata": {},
"outputs": [],
"source": [
"jupyter notebook"
]
},
{
"cell_type": "markdown",
"id": "12e95aa5",
"metadata": {},
"source": [
"Open this notebook file (`fireworks_demo.ipynb`) and proceed to run the cells."
]
},
Expand Down Expand Up @@ -358,7 +438,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"id": "0WzRJ5PgFAXc",
"metadata": {
"colab": {
Expand All @@ -367,35 +447,37 @@
"id": "0WzRJ5PgFAXc",
"outputId": "ee5a8472-167e-4167-f716-94378d8bd333"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"content\": null,\n",
" \"refusal\": null,\n",
" \"role\": \"assistant\",\n",
" \"function_call\": null,\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_kIpcwu7koMRkUtkhVvxuuQQu\",\n",
" \"function\": {\n",
" \"arguments\": \"{\\\"answer\\\": \\\"The President mentioned Ketanji Brown Jackson as the first Black woman to serve on the Supreme Court.\\\", \\\"sources\\\": [\\\"2022 State of the Union speech\\\"]}\",\n",
" \"name\": \"get_answer_with_sources\"\n",
" },\n",
" \"type\": \"function\",\n",
" \"index\": 0\n",
" }\n",
" ]\n",
"}\n"
]
}
],
"outputs": [],
"source": [
"print(chat_completion.choices[0].message.model_dump_json(indent=4))"
]
},
{
"cell_type": "markdown",
"id": "a0006d7a",
"metadata": {},
"source": [
"Expected output:\n",
"```\n",
"{\n",
" \"content\": null,\n",
" \"refusal\": null,\n",
" \"role\": \"assistant\",\n",
" \"function_call\": null,\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_kIpcwu7koMRkUtkhVvxuuQQu\",\n",
" \"function\": {\n",
" \"arguments\": \"{\\\"answer\\\": \\\"The President mentioned Ketanji Brown Jackson as the first Black woman to serve on the Supreme Court.\\\", \\\"sources\\\": [\\\"2022 State of the Union speech\\\"]}\",\n",
" \"name\": \"get_answer_with_sources\"\n",
" },\n",
" \"type\": \"function\",\n",
" \"index\": 0\n",
" }\n",
" ]\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 18,
Expand Down Expand Up @@ -457,7 +539,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"id": "UkWhQ4hPFMc_",
"metadata": {
"colab": {
Expand All @@ -466,35 +548,37 @@
"id": "UkWhQ4hPFMc_",
"outputId": "dcce465f-8d89-4937-f17c-4906dc142dcd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"content\": null,\n",
" \"refusal\": null,\n",
" \"role\": \"assistant\",\n",
" \"function_call\": null,\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_tdAos9CIlEKaq1ym4y6WvlL0\",\n",
" \"function\": {\n",
" \"arguments\": \"{\\\"answer\\\": \\\"The President mentioned Justice Stephen Breyer, who retired from the Supreme Court, making way for Ketanji Brown Jackson to take his seat.\\\", \\\"sources\\\": [\\\"2022 State of the Union speech\\\"]}\",\n",
" \"name\": \"get_answer_with_sources\"\n",
" },\n",
" \"type\": \"function\",\n",
" \"index\": 0\n",
" }\n",
" ]\n",
"}\n"
]
}
],
"outputs": [],
"source": [
"print(next_chat_completion.choices[0].message.model_dump_json(indent=4))"
]
},
{
"cell_type": "markdown",
"id": "8e0ea2c9",
"metadata": {},
"source": [
"Expected output:\n",
"```\n",
"{\n",
" \"content\": null,\n",
" \"refusal\": null,\n",
" \"role\": \"assistant\",\n",
" \"function_call\": null,\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_tdAos9CIlEKaq1ym4y6WvlL0\",\n",
" \"function\": {\n",
" \"arguments\": \"{\\\"answer\\\": \\\"The President mentioned Justice Stephen Breyer, who retired from the Supreme Court, making way for Ketanji Brown Jackson to take his seat.\\\", \\\"sources\\\": [\\\"2022 State of the Union speech\\\"]}\",\n",
" \"name\": \"get_answer_with_sources\"\n",
" },\n",
" \"type\": \"function\",\n",
" \"index\": 0\n",
" }\n",
" ]\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "EU_U5Bm9GJNa",
Expand Down Expand Up @@ -596,7 +680,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"id": "qi_gNf-qI-CG",
"metadata": {
"colab": {
Expand All @@ -605,34 +689,36 @@
"id": "qi_gNf-qI-CG",
"outputId": "d3018c86-21dd-4b40-9a38-7f14bbec05cd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"content\": null,\n",
" \"refusal\": null,\n",
" \"role\": \"assistant\",\n",
" \"function_call\": null,\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_Meyq8T6lEcoLTHmteAJvhRp2\",\n",
" \"function\": {\n",
" \"arguments\": \"{\\\"answer\\\": \\\"The President mentioned that human traffickers are being brought to justice and that the US is working with other countries to combat human trafficking.\\\", \\\"countries\\\": [\\\"United States\\\"]}\",\n",
" \"name\": \"get_answer_with_countries\"\n",
" },\n",
" \"type\": \"function\",\n",
" \"index\": 0\n",
" }\n",
" ]\n",
"}\n"
]
}
],
"outputs": [],
"source": [
"print(chat_completion.choices[0].message.model_dump_json(indent=4))"
]
},
{
"cell_type": "markdown",
"id": "44e06919",
"metadata": {},
"source": [
"Expected output:\n",
"```\n",
"{\n",
" \"content\": null,\n",
" \"refusal\": null,\n",
" \"role\": \"assistant\",\n",
" \"function_call\": null,\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_Meyq8T6lEcoLTHmteAJvhRp2\",\n",
" \"function\": {\n",
" \"arguments\": \"{\\\"answer\\\": \\\"The President mentioned that human traffickers are being brought to justice and that the US is working with other countries to combat human trafficking.\\\", \\\"countries\\\": [\\\"United States\\\"]}\",\n",
" \"name\": \"get_answer_with_countries\"\n",
" },\n",
" \"type\": \"function\",\n",
" \"index\": 0\n",
" }\n",
" ]\n",
"}"
]
}
],
"metadata": {
Expand Down