diff --git a/docs/docs/examples/llm/octoai.ipynb b/docs/docs/examples/llm/octoai.ipynb index bb84b5a823b687dc4da3b3c5a1b4a295fbd1cf4b..5087ef9f4f870767febd73fc734cf603376e3c41 100644 --- a/docs/docs/examples/llm/octoai.ipynb +++ b/docs/docs/examples/llm/octoai.ipynb @@ -6,7 +6,7 @@ "id": "6453d3d5", "metadata": {}, "source": [ - "<a href=\"https://colab.research.google.com/github/jerryjliu/llama_index/blob/main/docs/examples/llm/octoai.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" + "<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/llm/octoai.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" ] }, { @@ -33,35 +33,29 @@ "metadata": {}, "outputs": [], "source": [ - "%pip install llama-index-llms-octoai" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "50fc1a30", - "metadata": {}, - "outputs": [], - "source": [ - "!pip install llama-index" + "%pip install llama-index-llms-octoai\n", + "%pip install llama-index\n", + "%pip install octoai-sdk" ] }, { "cell_type": "markdown", - "id": "81cf396f", + "id": "3f8ec3ad", "metadata": {}, "source": [ - "You'll also want to install the OctoAI SDK" + "Include your OctoAI API key below. You can get yours at [OctoAI](https://octo.ai). \n", + "\n", + "[Here](https://octo.ai/docs/getting-started/how-to-create-an-octoai-access-token) are some instructions in case you need more guidance." ] }, { "cell_type": "code", "execution_count": null, - "id": "b75dae79", + "id": "e8249662", "metadata": {}, "outputs": [], "source": [ - "!pip install octoai-sdk" + "OCTOAI_API_KEY = \"\"" ] }, { @@ -79,16 +73,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Be sure to run this first; the 'octoai' variable is referenced in\n", - "# the chat and completion examples in this notebook\n", - "\n", "from llama_index.llms.octoai import OctoAI\n", "\n", - "# To customize your OctoAI API token, do this\n", - "# otherwise it will lookup OCTOAI_TOKEN from your env variable\n", - "# octoai = OctoAI(token=\"<token>\")\n", - "\n", - "octoai = OctoAI()" + "octoai = OctoAI(token=OCTOAI_API_KEY)" ] }, { @@ -104,15 +91,7 @@ "execution_count": null, "id": "910b50ad-c55e-487e-8808-5905dfaa78b4", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Paul Graham is a British computer scientist, entrepreneur, and venture capitalist. He is known for his role in co-founding several companies including Viaweb (which was later acquired by Yahoo and became Yahoo Store), and the startup accelerator, Y Combinator. He is also known for writing essays on topics such as startups, programming, and entrepreneurship, which have been published on his website, PaulGraham.com.\n" - ] - } - ], + "outputs": [], "source": [ "response = octoai.complete(\"Paul Graham is \")\n", "print(response)" @@ -131,54 +110,7 @@ "execution_count": null, "id": "5fd3137b-05ce-40a5-bdb0-5ce048f5ca25", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "assistant: Title: Discovering Seattle: A City of Innovation and Natural Beauty\n", - "\n", - "Seattle, often referred to as the “Emerald City,†is a vibrant and dynamic destination that offers a unique blend of urban sophistication and breathtaking natural beauty. Nestled in the Pacific Northwest, this city has something for everyone, from iconic landmarks and world-class museums to bustling markets and delicious seafood. In this blog, we will explore the best that Seattle has to offer.\n", - "\n", - "Getting to Know Seattle\n", - "\n", - "Seattle is the largest city in the Pacific Northwest and the cultural hub of the region. It is home to a diverse population of over 750,000 people, with a metropolitan area of nearly 4 million. The city is known for its rainy climate, with an average annual rainfall of 38 inches, but don't let that deter you. Seattle also boasts an impressive number of sunny days, especially during the summer months.\n", - "\n", - "The city's rich history dates back to the early 19th century when European settlers arrived in the area. The city's growth was fueled by the Klondike Gold Rush of the late 1890s, which brought a flood of new residents seeking their fortunes. Today, Seattle is a thriving center of innovation, with a strong economy driven by the technology, healthcare, and maritime industries.\n", - "\n", - "Iconic Landmarks and Attractions\n", - "\n", - "No visit to Seattle would be complete without experiencing some of its most iconic landmarks and attractions. Here are a few must-see destinations:\n", - "\n", - "1. Space Needle: The Space Needle is an iconic symbol of Seattle and a must-visit attraction. Completed in 1962 for the World's Fair, this 605-foot-tall tower offers stunning 360-degree views of the city and its surroundings.\n", - "2. Pike Place Market: Pike Place Market is a bustling public market overlooking Elliott Bay. Established in 1907, it is one of the oldest continuously operated public farmers' markets in the United States. Visitors can enjoy fresh produce, seafood, and artisanal goods, as well as street performers and live music.\n", - "3. Gum Wall: Located in an alleyway under Pike Place Market, the Gum Wall is a unique and quirky attraction. Since the early 1990s, visitors have been sticking their chewed gum to the brick walls, creating a colorful and ever-evolving work of art.\n", - "4. Chihuly Garden and Glass: This stunning museum showcases the breathtaking glass artwork of renowned artist Dale Chihuly. The exhibits include a variety of installations, both indoors and outdoors, that showcase the artist's mastery of color, form, and light.\n", - "5. Seattle Art Museum: The Seattle Art Museum (SAM) is a world-class institution that features an impressive collection of modern and contemporary art, as well as rotating exhibitions from around the globe.\n", - "\n", - "Natural Beauty and Outdoor Activities\n", - "\n", - "Seattle's stunning natural beauty is one of its most appealing features. The city is surrounded by water, mountains, and forests, providing ample opportunities for outdoor enthusiasts to explore and enjoy the great outdoors. Here are a few must-do activities:\n", - "\n", - "1. Visit the Olympic Sculpture Park: This nine-acre park, operated by the Seattle Art Museum, features a variety of sculptures and installations set amidst stunning natural landscapes. The park offers panoramic views of Puget Sound and the Olympic Mountains.\n", - "2. Explore Discovery Park: Discovery Park is a 534-acre urban wilderness located in the heart of Seattle. The park offers miles of hiking trails, stunning views of Puget Sound, and a historic lighthouse.\n", - "3. Take a Ferry Ride: Seattle's waterfront is home to several ferry terminals, offering daily service to nearby islands and communities. A ferry ride is a great way to experience the city's maritime heritage and enjoy stunning views of the Olympic Mountains and Puget Sound.\n", - "4. Hike Mount Si: Located just 30 miles east of Seattle, Mount Si is a popular hiking destination that offers stunning views of the Snoqualmie Valley and the surrounding mountains. The hike to the summit is 4 miles one-way, with an elevation gain of 3,100 feet.\n", - "\n", - "Culinary Delights\n", - "\n", - "Seattle is a food lover's paradise, with a diverse and vibrant culinary scene that reflects the city's multicultural population. Here are a few must-try dishes:\n", - "\n", - "1. Seafood: Seattle is renowned for its fresh and delicious seafood, with an abundance of options ranging from fish and chips to Dungeness crab and geoduck.\n", - "2. Coffee: Seattle is the birthplace of Starbucks, and the city takes its coffee seriously. There are countless independent coffee shops and roasteries throughout the city, each with its unique style and atmosphere.\n", - "3. Asian Cuisine: Seattle has a large Asian population, and the city's culinary scene reflects this diversity. From Vietnamese pho and Japanese sushi to Chinese dumplings and Korean BBQ, there is no shortage of delicious Asian cuisine to explore.\n", - "\n", - "In Conclusion\n", - "\n", - "Seattle is a city that offers something for everyone, with its rich history, iconic landmarks, stunning natural beauty, and diverse culinary scene. Whether you're a first-time visitor or a seasoned local, there is always something new to discover and experience in this vibrant and dynamic city. So pack your bags, grab your raincoat, and get ready to explore all that Seattle has to offer!\n" - ] - } - ], + "outputs": [], "source": [ "from llama_index.core.llms import ChatMessage\n", "\n", @@ -214,15 +146,7 @@ "execution_count": null, "id": "cd9e2b22-7e62-4f50-a9af-84453aeda071", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Paul Graham is a British computer scientist, entrepreneur, and venture capitalist. He is known for his role in co-founding several companies including Viaweb (which was later acquired by Yahoo and became Yahoo Store), and the startup accelerator, Y Combinator. He is also known for writing essays on topics such as startups, programming, and entrepreneurship, which have been published on his website, PaulGraham.com." - ] - } - ], + "outputs": [], "source": [ "response = octoai.stream_complete(\"Paul Graham is \")\n", "for r in response:\n", @@ -242,47 +166,7 @@ "execution_count": null, "id": "10b63238-8d01-48f7-b2ec-a56d23fec172", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Title: Discovering Seattle: A City of Innovation and Natural Beauty\n", - "\n", - "Seattle, often referred to as the “Emerald City,†is a vibrant and dynamic destination that offers a unique blend of urban sophistication and breathtaking natural beauty. Nestled in the Pacific Northwest, this city has something for everyone, from iconic landmarks and world-class museums to bustling markets and delicious seafood. In this blog, we will explore the best that Seattle has to offer.\n", - "\n", - "Getting to Know Seattle\n", - "\n", - "Seattle is the largest city in the Pacific Northwest and is home to over 750,000 residents. The city is known for its rich history, thriving arts scene, and innovative spirit. It is also famous for its coffee culture, with Starbucks and Seattle's Best Coffee both calling Seattle home.\n", - "\n", - "Exploring Seattle's Landmarks\n", - "\n", - "No trip to Seattle would be complete without visiting the Space Needle, an iconic symbol of the city. Built for the 1962 World's Fair, the Space Needle offers stunning 360-degree views of the city and the surrounding mountains and waterways. Visitors can enjoy a meal at the Space Needle's revolving restaurant, SkyCity, or simply take in the views from the observation deck.\n", - "\n", - "Another must-see landmark is Pike Place Market, a bustling public market that has been a Seattle institution since 1907. Here, visitors can sample fresh seafood, watch fishmongers toss fish, and browse stalls filled with local produce, crafts, and souvenirs. The market is also home to the original Starbucks store, which opened in 1971.\n", - "\n", - "For history buffs, the Museum of History & Industry (MOHAI) is a must-visit. The museum offers a fascinating look at Seattle's history, from its early days as a logging and fishing town to its role as a center of innovation and technology.\n", - "\n", - "Experiencing Seattle's Natural Beauty\n", - "\n", - "Seattle is surrounded by natural beauty, and there are plenty of opportunities to experience it firsthand. The city is home to several beautiful parks, including Discovery Park, which offers stunning views of Puget Sound and the Olympic Mountains. Visitors can hike through the park's forests, explore its beaches, and even visit a historic lighthouse.\n", - "\n", - "For a more urban experience, the Seattle Japanese Garden is a tranquil oasis in the heart of the city. The garden features a variety of plants, waterfalls, and ponds, and is a popular spot for picnics and weddings.\n", - "\n", - "Just a short ferry ride from Seattle is Bainbridge Island, which offers beautiful views of the city skyline and the Olympic Mountains. Visitors can explore the island's charming downtown area, visit its museums and galleries, or simply enjoy a leisurely stroll along the waterfront.\n", - "\n", - "Indulging in Seattle's Cuisine\n", - "\n", - "Seattle is known for its seafood, and there are plenty of opportunities to sample the city's freshest catches. The Crab Pot, located on the waterfront, offers all-you-can-eat seafood boils, while Ivar's Acres of Clams is famous for its clam chowder and fish and chips.\n", - "\n", - "For a more upscale dining experience, Canlis offers stunning views of the city and a menu filled with Pacific Northwest ingredients. The restaurant has been a Seattle institution since 1950 and has won numerous awards for its food and service.\n", - "\n", - "In Conclusion\n", - "\n", - "Seattle is a city that offers something for everyone. From its iconic landmarks and world-class museums to its bustling markets and delicious seafood, there is no shortage of things to see and do in this vibrant and dynamic destination. Whether you're a history buff, a nature lover, or a foodie, Seattle is sure to delight and inspire." - ] - } - ], + "outputs": [], "source": [ "from llama_index.core.llms import ChatMessage\n", "\n", @@ -311,36 +195,13 @@ "execution_count": null, "id": "1ce3de8d-287e-402d-936f-64a106c8fac2", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Paul Graham is a well-known computer scientist, entrepreneur, and essayist. He is best known for his work as a co-founder of Viaweb, a pioneering e-commerce platform, and later as a co-founder of Y Combinator, a successful startup accelerator.\n", - "\n", - "Graham has written extensively on a wide range of topics, including entrepreneurship, technology, and social issues. His essays, which are often published on his personal website, have been widely read and discussed in the tech community. Some of his most popular essays include:\n", - "\n", - "1. \"How to Get Your Startup Funded\" - This essay provides advice for entrepreneurs on how to raise funding for their startups.\n", - "2. \"Do Things That Don't Scale\" - In this essay, Graham argues that entrepreneurs should focus on doing things that don't scale, such as building personal relationships with customers, rather than trying to scale their businesses too quickly.\n", - "3. \"The Age of the Essay\" - This essay explores the role of essays in the tech industry and argues that they are an important way for entrepreneurs to share their ideas and perspectives.\n", - "4. \"The Hundred-Year Language\" - In this essay, Graham discusses the importance of long-term thinking in the tech industry and argues that many of the most successful companies have a long-term perspective.\n", - "5. \"The Two Cultures of Startups\" - This essay explores the differences between the \"maker\" and \"manager\" cultures in startups and argues that successful startups need to balance both cultures.\n", - "\n", - "Graham is also known for his strong opinions and his willingness to speak his mind on a wide range of topics. He has been a vocal critic of some of the tech industry's most prominent companies and has been involved in several high-profile controversies over the years. Despite this, he remains one of the most respected and influential figures in the tech industry.\n" - ] - } - ], + "outputs": [], "source": [ - "from octoai.chat import TextModel\n", - "\n", "# To customize your API token, do this\n", "# otherwise it will lookup OCTOAI_TOKEN from your env variable\n", - "# octoai = OctoAI(model=TextModel.LLAMA_2_13B_CHAT_FP16, token=\"<token>\")\n", - "\n", - "octoai = OctoAI(model=TextModel.LLAMA_2_13B_CHAT_FP16)\n", - "\n", - "# ... or provide the string of the model name instead of using the TextModel enum\n", - "# octoai = OctoAI(model=\"codellama-13b-instruct-fp16\")\n", + "octoai = OctoAI(\n", + " model=\"mistral-7b-instruct\", max_tokens=128, token=OCTOAI_API_KEY\n", + ")\n", "\n", "response = octoai.complete(\"Paul Graham is \")\n", "print(response)" diff --git a/llama-index-integrations/llms/llama-index-llms-octoai/README.md b/llama-index-integrations/llms/llama-index-llms-octoai/README.md index d69014436c4d70f5232c06e34530a2f64c8e6d86..acb6ca90dc049f917343941ee4a8b6f98f9546b4 100644 --- a/llama-index-integrations/llms/llama-index-llms-octoai/README.md +++ b/llama-index-integrations/llms/llama-index-llms-octoai/README.md @@ -1 +1,27 @@ -# LlamaIndex Llms Integration: Octoai +# LlamaIndex Llms Integration: OctoAI + +Using the [OctoAI](https://octo.ai) LLMs Integration is a simple as: + +```python +from llama_index.llms.octoai import OctoAI + +octoai = OctoAI(token=OCTOAI_API_KEY) +response = octoai.complete("Paul Graham is ") +print(response) +``` + +## Calling `chat` with a list of messages + +```python +from llama_index.core.llms import ChatMessage + +messages = [ + ChatMessage( + role="system", + content="Below is an instruction that describes a task. Write a response that appropriately completes the request.", + ), + ChatMessage(role="user", content="Write a blog about Seattle"), +] +response = octoai.chat(messages) +print(response) +``` diff --git a/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/base.py b/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/base.py index 3c2bd0a32fa88fa1252b2303de774805ac71e8d5..2d656bee9e19186fa84ad9783ca32ccff0d05a32 100644 --- a/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/base.py +++ b/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/base.py @@ -37,10 +37,9 @@ from llama_index.llms.octoai.utils import ( to_octoai_messages, ) -from octoai.chat import TextModel from octoai.client import Client -DEFAULT_OCTOAI_MODEL = TextModel.MIXTRAL_8X7B_INSTRUCT +DEFAULT_OCTOAI_MODEL = "mistral-7b-instruct" class OctoAI(LLM): diff --git a/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/utils.py b/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/utils.py index dd8c143e605a3df5061559bf82f57e74d9875369..5d90232c33b1b74f6a06c402cb8921132c0abd3d 100644 --- a/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/utils.py +++ b/llama-index-integrations/llms/llama-index-llms-octoai/llama_index/llms/octoai/utils.py @@ -1,17 +1,23 @@ import logging from typing import Dict, Sequence from llama_index.core.base.llms.types import ChatMessage -from octoai.chat import TextModel TEXT_MODELS: Dict[str, int] = { - TextModel.CODELLAMA_13B_INSTRUCT: 16384, - TextModel.CODELLAMA_34B_INSTRUCT: 16384, - TextModel.CODELLAMA_70B_INSTRUCT: 16384, - TextModel.CODELLAMA_7B_INSTRUCT: 4096, - TextModel.LLAMA_2_13B_CHAT: 4096, - TextModel.LLAMA_2_70B_CHAT: 4096, - TextModel.MISTRAL_7B_INSTRUCT: 32768, - TextModel.MIXTRAL_8X7B_INSTRUCT: 32768, + "codellama-13b-instruct": 16384, + "codellama-34b-instruct": 16384, + "codellama-7b-instruct": 4096, + "meta-llama-3-8b-instruct": 8192, + "meta-llama-3-70b-instruct": 8192, + "llama-2-13b-chat": 4096, + "llama-2-70b-chat": 4096, + "mistral-7b-instruct": 32768, + "mixtral-8x7b-instruct": 32768, + "mixtral-8x22b-instruct": 65536, + "mixtral-8x22b-finetuned": 65536, + "nous-hermes-2-mixtral-8x7b-dpo": 32768, + "hermes-2-pro-mistral-7b": 32768, + "llamaguard-7b": 4096, + "qwen1.5-32b-chat": 32768, } ALL_AVAILABLE_MODELS = {**TEXT_MODELS} @@ -42,11 +48,10 @@ def octoai_modelname_to_contextsize(modelname: str) -> int: max_tokens = octoai.modelname_to_contextsize("llama-2-13b-chat") """ if modelname not in ALL_AVAILABLE_MODELS: - raise ValueError( - f"Unknown model {modelname!r}. Please provide a supported model name as \ - a string or using the TextModel enum from the OctoAI SDK:" - f" {', '.join(ALL_AVAILABLE_MODELS.keys())}" + print( + "WARNING: Model not found in octoai.utils.py, returning a generous default value." ) + return 8192 return ALL_AVAILABLE_MODELS[modelname] diff --git a/llama-index-integrations/llms/llama-index-llms-octoai/pyproject.toml b/llama-index-integrations/llms/llama-index-llms-octoai/pyproject.toml index c7cbd02921ee62abdf7e7304babbc4660c9feb69..0903b32a5688371974d35c2edd67146d1ab6f2e6 100644 --- a/llama-index-integrations/llms/llama-index-llms-octoai/pyproject.toml +++ b/llama-index-integrations/llms/llama-index-llms-octoai/pyproject.toml @@ -33,7 +33,7 @@ version = "0.1.0" [tool.poetry.dependencies] python = ">=3.8.1,<4.0" llama-index-core = "^0.10.0" -octoai-sdk = ">=0.9.1" +octoai-sdk = "~0.10.1" [tool.poetry.group.dev.dependencies] black = {extras = ["jupyter"], version = "<=23.9.1,>=23.7.0"}