Skip to content

Commit

Permalink
docs: fireworks fixes (langchain-ai#18056)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored and Hayden Wolff committed Feb 27, 2024
1 parent d3e0dfb commit 3e34c34
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 70 deletions.
42 changes: 14 additions & 28 deletions docs/docs/integrations/chat/fireworks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"id": "4a7c795e",
"metadata": {},
"source": [
"%pip install langchain\n",
"%pip install langchain-fireworks"
]
},
Expand All @@ -44,9 +43,7 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"from langchain.schema import HumanMessage, SystemMessage\n",
"from langchain_core.messages import HumanMessage, SystemMessage\n",
"from langchain_fireworks import ChatFireworks"
]
},
Expand All @@ -57,7 +54,7 @@
"source": [
"# Setup\n",
"\n",
"1. Make sure the `fireworks-ai` package is installed in your environment.\n",
"1. Make sure the `langchain-fireworks` package is installed in your environment.\n",
"2. Sign in to [Fireworks AI](http://fireworks.ai) for the an API Key to access our models, and make sure it is set as the `FIREWORKS_API_KEY` environment variable.\n",
"3. Set up your model using a model id. If the model is not set, the default model is fireworks-llama-v2-7b-chat. See the full, most up-to-date model list on [app.fireworks.ai](https://app.fireworks.ai)."
]
Expand Down Expand Up @@ -95,14 +92,6 @@
"id": "72340871-ae2f-415f-b399-0777d32dc379",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/mnt/disks/data/langchain/.venv/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.7 and will be removed in 0.2.0. Use invoke instead.\n",
" warn_deprecated(\n"
]
},
{
"data": {
"text/plain": [
Expand All @@ -119,7 +108,7 @@
"system_message = SystemMessage(content=\"You are to chat with the user.\")\n",
"human_message = HumanMessage(content=\"Who are you?\")\n",
"\n",
"chat([system_message, human_message])"
"chat.invoke([system_message, human_message])"
]
},
{
Expand All @@ -128,20 +117,10 @@
"id": "68c6b1fa-2ff7-4a63-8d88-3cec302180b8",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/mnt/disks/data/langchain/.venv/lib/python3.10/site-packages/langchain_core/utils/utils.py:159: UserWarning: WARNING! top_p is not default parameter.\n",
" top_p was transferred to model_kwargs.\n",
" Please confirm that top_p is what you intended.\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/plain": [
"AIMessage(content=\"I'm glad to chat with you! I'm an artificial intelligence and don't have\")"
"AIMessage(content=\"I'm an AI and do not have the ability to experience the weather firsthand. However,\")"
]
},
"execution_count": 5,
Expand All @@ -155,12 +134,19 @@
" model=\"accounts/fireworks/models/mixtral-8x7b-instruct\",\n",
" temperature=1,\n",
" max_tokens=20,\n",
" top_p=1,\n",
")\n",
"system_message = SystemMessage(content=\"You are to chat with the user.\")\n",
"human_message = HumanMessage(content=\"How's the weather today?\")\n",
"chat([system_message, human_message])"
"chat.invoke([system_message, human_message])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c44cb36",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -179,7 +165,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
64 changes: 24 additions & 40 deletions docs/docs/integrations/llms/fireworks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,16 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install langchain\n",
"%pip install langchain-fireworks"
"%pip install -qU langchain-fireworks"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6b9bcdac",
"metadata": {},
"outputs": [],
"source": [
"import fireworks\n",
"import fireworks.client"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"id": "60b6dbb2",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain_fireworks import Fireworks"
]
},
Expand All @@ -54,14 +39,14 @@
"source": [
"# Setup\n",
"\n",
"1. Make sure the `fireworks-ai` package is installed in your environment.\n",
"1. Make sure the `langchain-fireworks` package is installed in your environment.\n",
"2. Sign in to [Fireworks AI](http://fireworks.ai) for the an API Key to access our models, and make sure it is set as the `FIREWORKS_API_KEY` environment variable.\n",
"3. Set up your model using a model id. If the model is not set, the default model is fireworks-llama-v2-7b-chat. See the full, most up-to-date model list on [fireworks.ai](https://fireworks.ai)."
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"id": "9ca87a2e",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -91,43 +76,36 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"id": "bf0a425c",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/mnt/disks/data/langchain/.venv/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.7 and will be removed in 0.2.0. Use invoke instead.\n",
" warn_deprecated(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" With Tom Brady at a season-best 9-0, he'\n"
"\n",
"Even if Tom Brady wins today, he'd still have the same\n"
]
}
],
"source": [
"# Single prompt\n",
"output = llm(\"Who's the best quarterback in the NFL?\")\n",
"output = llm.invoke(\"Who's the best quarterback in the NFL?\")\n",
"print(output)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"id": "afc7de6f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[Generation(text=' In 2016, the best cricket player award should go to a')], [Generation(text=\"\\n\\nThere's a good argument that it's Kawhi Leonard\")]]\n"
"[[Generation(text='\\n\\nR Ashwin is currently the best. He is an all rounder')], [Generation(text='\\nIn your opinion, who has the best overall statistics between Michael Jordan and Le')]]\n"
]
}
],
Expand All @@ -144,17 +122,15 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"id": "b801c20d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"December in Kansas City is typically cold. The average high temperature\n"
" The weather in Kansas City in December is generally cold and snowy. The\n"
]
}
],
Expand All @@ -166,7 +142,7 @@
" max_tokens=15,\n",
" top_p=1.0,\n",
")\n",
"print(llm(\"What's the weather like in Kansas City in December?\"))"
"print(llm.invoke(\"What's the weather like in Kansas City in December?\"))"
]
},
{
Expand All @@ -187,7 +163,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 8,
"id": "fd2c6bc1",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -227,7 +203,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"id": "f644ff28",
"metadata": {},
"outputs": [
Expand All @@ -247,6 +223,14 @@
"for token in chain.stream({\"topic\": \"bears\"}):\n",
" print(token, end=\"\", flush=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fcc0eecb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -265,7 +249,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/providers/fireworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Langchain.

## Installation and setup

- Install the Fireworks client library.
- Install the Fireworks integration package.

```
pip install fireworks-ai
pip install langchain-fireworks
```

- Get a Fireworks API key by signing up at [fireworks.ai](https://fireworks.ai).
Expand Down

0 comments on commit 3e34c34

Please sign in to comment.