Skip to content
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

feat(docs): Update cookbooks #858

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
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
168 changes: 168 additions & 0 deletions cookbooks/00-Devfest-Email-Assistant.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div align=\"center\" id=\"top\">\n",
" <img src=\"https://socialify.git.ci/julep-ai/julep/image?description=1&descriptionEditable=API%20for%20AI%20agents%20and%20multi-step%20tasks&forks=1&name=1&owner=1&pattern=Solid&stargazers=1&font=Source%20Code%20Pro&logo=https%3A%2F%2Fraw.githubusercontent.com%2Fjulep-ai%2Fjulep%2Fdev%2F.github%2Fjulep-logo.svg&theme=Auto\" alt=\"julep\" width=\"640\" height=\"320\" />\n",
"</div>\n",
"\n",
"<p align=\"center\">\n",
" <br />\n",
" <a href=\"https://docs.julep.ai\" rel=\"dofollow\">Explore Docs (wip)</a>\n",
" ·\n",
" <a href=\"https://discord.com/invite/JTSBGRZrzj\" rel=\"dofollow\">Discord</a>\n",
" ·\n",
" <a href=\"https://x.com/julep_ai\" rel=\"dofollow\">𝕏</a>\n",
" ·\n",
" <a href=\"https://www.linkedin.com/company/julep-ai\" rel=\"dofollow\">LinkedIn</a>\n",
"</p>\n",
"\n",
"<p align=\"center\">\n",
" <a href=\"https://www.npmjs.com/package/@julep/sdk\"><img src=\"https://img.shields.io/npm/v/%40julep%2Fsdk?style=social&amp;logo=npm&amp;link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40julep%2Fsdk\" alt=\"NPM Version\"></a>\n",
" <span>&nbsp;</span>\n",
" <a href=\"https://pypi.org/project/julep\"><img src=\"https://img.shields.io/pypi/v/julep?style=social&amp;logo=python&amp;label=PyPI&amp;link=https%3A%2F%2Fpypi.org%2Fproject%2Fjulep\" alt=\"PyPI - Version\"></a>\n",
" <span>&nbsp;</span>\n",
" <a href=\"https://hub.docker.com/u/julepai\"><img src=\"https://img.shields.io/docker/v/julepai/agents-api?sort=semver&amp;style=social&amp;logo=docker&amp;link=https%3A%2F%2Fhub.docker.com%2Fu%2Fjulepai\" alt=\"Docker Image Version\"></a>\n",
" <span>&nbsp;</span>\n",
" <a href=\"https://choosealicense.com/licenses/apache/\"><img src=\"https://img.shields.io/github/license/julep-ai/julep\" alt=\"GitHub License\"></a>\n",
"</p>\n",
"\n",
"## Task Definition: Email Assistant\n",
"\n",
"### Overview\n",
"\n",
"This task creates an email assistant that can receive emails, search through Julep documentation, and respond to user inquiries automatically. It combines email integration with documentation search capabilities to provide relevant and informed responses.\n",
"\n",
"### Task Tools:\n",
"\n",
"**send_email**: An `integration` type tool that handles email sending via Mailgun SMTP.\n",
"**search_docs**: A `system` type tool that searches through agent documentation.\n",
"\n",
"### Task Input:\n",
"\n",
"A dictionary containing:\n",
"- **from**: Sender's email address\n",
"- **to**: Recipient's email address\n",
"- **subject**: Email subject\n",
"- **body**: Email content\n",
"\n",
"### Task Output:\n",
"\n",
"An email response sent to the inquirer with:\n",
"- Generated subject line\n",
"- Generated response body based on documentation search results\n",
"\n",
"### Task Flow\n",
"\n",
"1. **Input**: Receive email details (from, to, subject, body)\n",
"2. **Query Generation**: Generate a search query based on the email content\n",
"3. **Documentation Search**: Search Julep documentation using the generated query\n",
"4. **Response Generation**: Create a response using the found documentation\n",
"5. **Email Sending**: Send the response back to the original sender via Mailgun\n",
"\n",
"```plaintext\n",
"+----------+ +-------------+ +------------+ +-----------+\n",
"| Email | | Query | | Doc | | Email |\n",
"| Input | --> | Generation | --> | Search | --> | Response |\n",
"| (Query) | | | | | | Output |\n",
"+----------+ +-------------+ +------------+ +-----------+\n",
" | | | |\n",
" | | | |\n",
" v v v v\n",
" \"How do I\" Create search Find relevant \"Here's how to\n",
" \"use Julep?\" keywords documentation get started...\"\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Implementation\n",
"\n",
"To recreate the notebook and see the code implementation for this task, you can access the Google Colab notebook using the link below:\n",
"\n",
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/00-Devfest-Email-Assistant.ipynb\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
"</a>\n",
"\n",
"### Additional Information\n",
"\n",
"For more details about the task or if you have any questions, please don't hesitate to contact the author:\n",
"\n",
"**Author:** Julep AI \n",
"**Contact:** [[email protected]](mailto:[email protected]) or <a href=\"https://discord.com/invite/JTSBGRZrzj\" rel=\"dofollow\">Discord</a>"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand Down Expand Up @@ -29,6 +125,13 @@
"!pip install julep"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating Julep Client with the API Key"
]
},
{
"cell_type": "code",
"execution_count": 8,
Expand All @@ -45,6 +148,17 @@
"julep = Julep(api_key=api_key, environment=\"dev\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating an \"agent\"\n",
"\n",
"Agent is the object to which LLM settings, like model, temperature along with tools are scoped to.\n",
"\n",
"To learn more about the agent, please refer to the [documentation](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#agent)."
]
},
{
"cell_type": "code",
"execution_count": 9,
Expand Down Expand Up @@ -82,6 +196,19 @@
"agent.id"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining a Task\n",
"\n",
"Tasks in Julep are Github-Actions-style workflows that define long-running, multi-step actions.\n",
"\n",
"You can use them to conduct complex actions by defining them step-by-step.\n",
"\n",
"To learn more about tasks, please refer to the `Tasks` section in [Julep Concepts](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#tasks)."
]
},
{
"cell_type": "code",
"execution_count": 11,
Expand Down Expand Up @@ -180,6 +307,22 @@
"\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<span style=\"color:olive;\">Notes:</span>\n",
"- The reason for using the quadruple curly braces `{{{{}}}}` for the jinja template is to avoid conflicts with the curly braces when using the `f` formatted strings in python. [More information here](https://stackoverflow.com/questions/64493332/jinja-templating-in-airflow-along-with-formatted-text)\n",
"- The `unwrap: True` in the prompt step is used to unwrap the output of the prompt step (to unwrap the `choices[0].message.content` from the output of the model).\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a task"
]
},
{
"cell_type": "code",
"execution_count": 12,
Expand Down Expand Up @@ -212,6 +355,15 @@
"task.id"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating an Execution\n",
"\n",
"An execution is a single run of a task. It is a way to run a task with a specific set of inputs."
]
},
{
"cell_type": "code",
"execution_count": 14,
Expand Down Expand Up @@ -244,6 +396,22 @@
"julep.executions.get(execution.id)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Checking execution details and output\n",
"\n",
"There are multiple ways to get the execution details and the output:\n",
"\n",
"1. **Get Execution Details**: This method retrieves the details of the execution, including the output of the last transition that took place.\n",
"\n",
"2. **List Transitions**: This method lists all the task steps that have been executed up to this point in time, so the output of a successful execution will be the output of the last transition (first in the transition list as it is in reverse chronological order), which should have a type of `finish`.\n",
"\n",
"\n",
"<span style=\"color:olive;\">Note: You need to wait for a few seconds for the execution to complete before you can get the final output, so feel free to run the following cells multiple times until you get the final output.</span>\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
Expand Down
Loading
Loading