Skip to content

Commit

Permalink
Merge branch 'dev' into x/readme-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedantsahai18 authored Feb 11, 2025
2 parents 543a0a1 + 4398793 commit c55e1af
Show file tree
Hide file tree
Showing 31 changed files with 3,785 additions and 9,699 deletions.
277 changes: 146 additions & 131 deletions cookbooks/00-Devfest-Email-Assistant.ipynb

Large diffs are not rendered by default.

129 changes: 75 additions & 54 deletions cookbooks/01-website-crawler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@
"!pip install --upgrade julep --quiet"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### NOTE:\n",
"\n",
"- UUIDs are generated for both the agent and task to uniquely identify them within the system.\n",
"- Once created, these UUIDs should remain unchanged for simplicity.\n",
"- Altering a UUID will result in the system treating it as a new agent or task.\n",
"- If a UUID is changed, the original agent or task will continue to exist in the system alongside the new one."
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down Expand Up @@ -140,21 +152,21 @@
"from julep import Client\n",
"import os\n",
"\n",
"api_key = os.getenv(\"JULEP_API_KEY\")\n",
"JULEP_API_KEY = \"YOUR_JULEP_API_KEY\"\n",
"\n",
"# Create a Julep client\n",
"client = Client(api_key=api_key, environment=\"production\")"
"client = Client(api_key=JULEP_API_KEY, environment=\"production\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating an \"agent\"\n",
"### 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)."
"To learn more about the agent, please refer to the Agent section in [Julep Concepts](https://docs.julep.ai/docs/concepts/agents)."
]
},
{
Expand All @@ -176,13 +188,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining a Task\n",
"### 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)."
"To learn more about tasks, please refer to the `Tasks` section in [Julep Concepts](https://docs.julep.ai/docs/concepts/tasks)."
]
},
{
Expand All @@ -193,55 +205,76 @@
"source": [
"import yaml\n",
"\n",
"spider_api_key = os.getenv(\"SPIDER_API_KEY\")\n",
"SPIDER_API_KEY = \"YOUR_SPIDER_API_KEY\"\n",
"\n",
"# Define the task\n",
"task_def = yaml.safe_load(f\"\"\"\n",
"name: Crawling Task\n",
"\n",
"# Define the tools that the agent will use in this workflow\n",
"task_def = yaml.safe_load(f\"\"\" \n",
"# yaml-language-server: $schema=https://raw.githubusercontent.com/julep-ai/julep/refs/heads/dev/schemas/create_task_request.json \n",
"name: Julep Crawling Task\n",
"description: Crawl a website and create a summary of the results\n",
"\n",
"########################################################\n",
"####################### INPUT SCHEMA ###################\n",
"########################################################\n",
"\n",
"input_schema:\n",
" type: object\n",
" properties:\n",
" url:\n",
" type: string\n",
" description: The URL of the website to crawl\n",
"\n",
"########################################################\n",
"####################### TOOLS ##########################\n",
"########################################################\n",
"\n",
"# Define the tools that the task will use in this workflow\n",
"tools:\n",
"- name: spider_crawler\n",
" type: integration\n",
" integration:\n",
" provider: spider\n",
" setup:\n",
" spider_api_key: \"{spider_api_key}\"\n",
" spider_api_key: \"{SPIDER_API_KEY}\"\n",
"\n",
"########################################################\n",
"####################### MAIN WORKFLOW ##################\n",
"########################################################\n",
"\n",
"# Define the steps of the workflow\n",
"main:\n",
"\n",
"# Define a tool call step that calls the spider_crawler tool with the url input\n",
"# Step 0: Call the spider_crawler tool with the url input\n",
"- tool: spider_crawler\n",
" arguments:\n",
" url: \"_['url']\" # You can also use 'inputs[0]['url']'\n",
" url: $_['url'] # You can also use 'steps[0].input.url'\n",
" params:\n",
" request: \"'smart_mode'\"\n",
" request: smart_mode\n",
" limit: \"1\"\n",
" return_format: \"'markdown'\"\n",
" proxy_enabled: \"True\"\n",
" filter_output_images: \"True\"\n",
" filter_output_svg: \"True\"\n",
" readability: \"True\"\n",
" return_format: markdown\n",
" proxy_enabled: $ True\n",
" filter_output_images: $ True\n",
" filter_output_svg: $ True\n",
" readability: $ True\n",
"\n",
"# Evaluate step to create a summary of the results\n",
"# Step 1: Evaluate step to create a summary of the results\n",
"- evaluate:\n",
" documents: |\n",
" \" \".join(\n",
" $ \" \".join(\n",
" list(\n",
" page['content'] for page in _['result']\n",
" )\n",
" )\n",
" \n",
"# Prompt step to create a summary of the results\n",
"# Step 2: Prompt step to create a summary of the results\n",
"- prompt: |\n",
" You are {{{{agent.about}}}}\n",
" I have given you this url: {{{{inputs[0]['url']}}}}\n",
" $ f'''\n",
" You are {{agent.about}}\n",
" I have given you this url: {{steps[0].input.url}}\n",
" And you have crawled that website. Here are the results you found:\n",
" {{{{_['documents']}}}}\n",
" {{_['documents']}}\n",
" I want you to create a short summary (no longer than 100 words) of the results you found while crawling that website.\n",
"\n",
" unwrap: True\n",
" '''\n",
" unwrap: True\n",
"\"\"\")"
]
},
Expand All @@ -250,15 +283,11 @@
"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/Updating a task"
"- 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",
"- The `$` sign is used to differentiate between a Python expression and a string.\n",
"- The `_` refers to the output of the previous step.\n",
"- The `steps[index].input` refers to the input of the step at `index`.\n",
"- The `steps[index].output` refers to the output of the step at `index`."
]
},
{
Expand All @@ -279,14 +308,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating an Execution"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An execution is a single run of a task. It is a way to run a task with a specific set of inputs."
"### 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.\n",
"\n",
"To learn more about executions, please refer to the `Executions` section in [Julep Concepts](https://docs.julep.ai/docs/concepts/execution)."
]
},
{
Expand Down Expand Up @@ -370,7 +396,7 @@
"# Lists all the task steps that have been executed up to this point in time\n",
"transitions = client.executions.transitions.list(execution_id=execution.id).items\n",
"\n",
"# Transitions are retreived in reverse chronological order\n",
"# Transitions are retrieved in reverse chronological order\n",
"for transition in reversed(transitions):\n",
" print(\"Transition type: \", transition.type)\n",
" print(\"Transition output: \", transition.output)\n",
Expand All @@ -381,13 +407,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Running the same task with a different URL"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Running the same task with a different URL\n",
"\n",
"We will use the same code to run the same task, but with a different URL"
]
},
Expand Down
109 changes: 0 additions & 109 deletions cookbooks/01-website-crawler.py

This file was deleted.

Loading

0 comments on commit c55e1af

Please sign in to comment.