Skip to content

Commit

Permalink
Nebius examples fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Aktsvigun committed Jan 24, 2025
1 parent 3cb06f8 commit 683c5b2
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 193 deletions.
62 changes: 32 additions & 30 deletions docs/docs/examples/embeddings/nebius.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,29 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install llama-index-embeddings-nebius"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"!pip install llama-index"
"%pip install llama-index-embeddings-nebius llama-index"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Insert your Nebius AI Studio key below. You can get it by registering for free at [Nebius AI Studio](https://auth.eu.nebius.com/ui/login) and issuing the key at [API Keys section](https://studio.nebius.ai/settings/api-keys).\""
"Upload your Nebius AI Studio key from system variables below or simply insert it. You can get it by registering for free at [Nebius AI Studio](https://auth.eu.nebius.com/ui/login) and issuing the key at [API Keys section](https://studio.nebius.ai/settings/api-keys)."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"NEBIUS_API_KEY = \"\""
"import os\n",
"NEBIUS_API_KEY = os.getenv(\"NEBIUS_API_KEY\") # NEBIUS_API_KEY = \"\""
]
},
{
Expand All @@ -66,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -84,15 +78,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4096\n",
"[-0.002410888671875, 0.0083770751953125, -0.00542449951171875, 0.007366180419921875, -0.022216796875]\n"
"[-0.0024051666259765625, 0.0083770751953125, -0.005413055419921875, 0.007396697998046875, -0.022247314453125]\n"
]
}
],
Expand All @@ -112,15 +106,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4096\n",
"[-0.002410888671875, 0.0083770751953125, -0.00542449951171875, 0.007366180419921875, -0.022216796875]\n"
"[-0.0024051666259765625, 0.0083770751953125, -0.005413055419921875, 0.007396697998046875, -0.022247314453125]\n"
]
}
],
Expand All @@ -140,17 +134,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[-0.0003886222839355469, 0.0004887580871582031, 0.011199951171875]\n",
"[-0.003734588623046875, 0.01143646240234375, 0.008758544921875]\n",
"[0.005901336669921875, 0.005161285400390625, 0.00142669677734375]\n",
"[-0.00946807861328125, -0.0048675537109375, 0.004817962646484375]\n"
"[-0.0003848075866699219, 0.0004799365997314453, 0.011199951171875]\n",
"[-0.0037078857421875, 0.0114288330078125, 0.00878143310546875]\n",
"[0.005924224853515625, 0.005153656005859375, 0.001438140869140625]\n",
"[-0.009490966796875, -0.004852294921875, 0.004779815673828125]\n"
]
}
],
Expand All @@ -177,17 +171,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[-0.0003886222839355469, 0.0004887580871582031, 0.011199951171875]\n",
"[-0.003734588623046875, 0.01143646240234375, 0.008758544921875]\n",
"[0.005901336669921875, 0.005161285400390625, 0.00142669677734375]\n",
"[-0.00946807861328125, -0.0048675537109375, 0.004817962646484375]\n"
"[-0.0003848075866699219, 0.0004799365997314453, 0.011199951171875]\n",
"[-0.0037078857421875, 0.0114288330078125, 0.00878143310546875]\n",
"[0.005924224853515625, 0.005153656005859375, 0.001438140869140625]\n",
"[-0.009490966796875, -0.004852294921875, 0.004779815673828125]\n"
]
}
],
Expand All @@ -204,6 +198,13 @@
"assert len(embeddings[0]) == 4096\n",
"print(*[x[:3] for x in embeddings], sep=\"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -221,7 +222,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
118 changes: 35 additions & 83 deletions docs/docs/examples/llm/nebius.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,44 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install llama-index-embeddings-nebius"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
"%pip install llama-index-llms-nebius llama-index"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Insert your Nebius AI Studio key below. You can get it by registering for free at [Nebius AI Studio](https://auth.eu.nebius.com/ui/login) and issuing the key at [API Keys section](https://studio.nebius.ai/settings/api-keys).\""
"Upload your Nebius AI Studio key from system variables below or simply insert it. You can get it by registering for free at [Nebius AI Studio](https://auth.eu.nebius.com/ui/login) and issuing the key at [API Keys section](https://studio.nebius.ai/settings/api-keys).\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"NEBIUS_API_KEY = \"\""
"import os\n",
"NEBIUS_API_KEY = os.getenv(\"NEBIUS_API_KEY\") # NEBIUS_API_KEY = \"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.\n"
]
}
],
"source": [
"from llama_index.llms.nebius import NebiusLLM\n",
"\n",
"llm = NebiusLLM(\n",
" api_key=NEBIUS_API_KEY, model=\"meta-llama/Meta-Llama-3.1-70B-Instruct-fast\"\n",
" api_key=NEBIUS_API_KEY, model=\"meta-llama/Llama-3.3-70B-Instruct-fast\"\n",
")"
]
},
Expand All @@ -79,14 +79,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Netherlands!\n"
"The Netherlands! Amsterdam is indeed the capital and largest city of the Netherlands.\n"
]
}
],
Expand All @@ -104,42 +104,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"assistant: In a world of wires and circuits bright,\n",
"A small robot shone with digital light,\n",
"Wall-e, a name that's known so well,\n",
"A smart AI, with a story to tell.\n",
"\n",
"With eyes that gleam like shining steel,\n",
"He navigates the world with skill and zeal,\n",
"A waste-collecting bot, with a heart of gold,\n",
"He cleans the earth, with a story to unfold.\n",
"\n",
"His trash-compacting arms, a wondrous sight,\n",
"Crush and compress, with precision and might,\n",
"He beeps and boops, with a language all his own,\n",
"A symphony of sounds, that echo and moan.\n",
"\n",
"In a world of desolation, he finds a friend,\n",
"Eve, a sleek robot, with a mission to amend,\n",
"Together they roam, through the ruins of old,\n",
"A tale of love and hope, in a world grown cold.\n",
"\n",
"With a heart that beats, with a digital soul,\n",
"Wall-e dreams of life, in a world made whole,\n",
"He longs to connect, to touch and to share,\n",
"A robot's quest, to show he cares.\n",
"\n",
"His story's told, in a world of decay,\n",
"A beacon of hope, in a brighter day,\n",
"Wall-e, a hero, in a world of machines,\n",
"A shining star, that forever gleams.\n"
"assistant: WALL-E is a small waste-collecting robot and the main character in the 2008 Pixar animated film of the same name.\n"
]
}
],
Expand All @@ -150,7 +122,7 @@
" ChatMessage(role=\"system\", content=\"You are a helpful AI assistant.\"),\n",
" ChatMessage(\n",
" role=\"user\",\n",
" content=\"Write a poem about a smart AI robot named Wall-e.\",\n",
" content=\"Answer briefly: who is Wall-e?\",\n",
" ),\n",
"]\n",
"response = llm.chat(messages)\n",
Expand All @@ -173,14 +145,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Netherlands!"
"The Netherlands! Amsterdam is indeed the capital and largest city of the Netherlands."
]
}
],
Expand All @@ -199,42 +171,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"In a world of wires and circuits bright,\n",
"A small robot shone with digital light,\n",
"Wall-e, a name that's known so well,\n",
"A hero of the future, with a story to tell.\n",
"\n",
"With eyes that gleam like stars in space,\n",
"He navigates the ruins of a forgotten place,\n",
"A world of trash and decay, where humans once did roam,\n",
"But Wall-e's heart beats strong, with a love that's made of home.\n",
"\n",
"His metal body, sturdy and strong,\n",
"Moves with a purpose, all day long,\n",
"He collects and sorts, with a precision so fine,\n",
"The waste of humanity, in a world that's lost its shine.\n",
"\n",
"But Wall-e's not just a machine, you see,\n",
"He's a friend, a companion, with a heart that's free,\n",
"He dreams of love, of connection, of a life that's true,\n",
"A life with EVE, his counterpart, his heart beats anew.\n",
"\n",
"With a beep and a boop, he communicates with glee,\n",
"A language all his own, a symphony,\n",
"He's a robot of wonder, a marvel of our time,\n",
"A shining star, that shines with a love that's divine.\n",
"\n",
"In a world of metal and wires, he's a work of art,\n",
"A masterpiece, that beats with a loving heart,\n",
"Wall-e, the robot, with a soul so bright,\n",
"A hero of the future, shining with delight."
"WALL-E is a small waste-collecting robot and the main character in the 2008 Pixar animated film of the same name."
]
}
],
Expand All @@ -245,13 +189,20 @@
" ChatMessage(role=\"system\", content=\"You are a helpful AI assistant.\"),\n",
" ChatMessage(\n",
" role=\"user\",\n",
" content=\"Write a poem about a smart AI robot named Wall-e.\",\n",
" content=\"Answer briefly: who is Wall-e?\",\n",
" ),\n",
"]\n",
"response = llm.stream_chat(messages)\n",
"for r in response:\n",
" print(r.delta, end=\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -269,7 +220,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 683c5b2

Please sign in to comment.