From d992286041b71e2a839c3d6e86d4a86e4a98bf4d Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Tue, 1 Oct 2024 13:41:38 -0400 Subject: [PATCH 1/8] feat:codec-route added, testing remain --- CONTRIBUTING.md | 114 +++-- agents-api/.DS_Store | Bin 6148 -> 6148 bytes .../agents_api/routers/internal/__init__.py | 1 + .../agents_api/routers/internal/router.py | 89 ++++ agents-api/agents_api/web.py | 2 + cookbooks/01_Cookbook.ipynb | 371 +++++++++++++++ cookbooks/02_Cookbook.ipynb | 402 +++++++++++++++++ cookbooks/03_Cookbook.ipynb | 422 ++++++++++++++++++ 8 files changed, 1360 insertions(+), 41 deletions(-) create mode 100644 agents-api/agents_api/routers/internal/__init__.py create mode 100644 agents-api/agents_api/routers/internal/router.py create mode 100644 cookbooks/01_Cookbook.ipynb create mode 100644 cookbooks/02_Cookbook.ipynb create mode 100644 cookbooks/03_Cookbook.ipynb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a9c4f24d9..7e9620ffb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,44 +30,76 @@ Improvements to documentation are always appreciated! If you see areas that coul We'd love to hear your feedback and ideas for the project! Feel free to submit an issue or contact the maintainers directly to share your thoughts. Your input is very valuable in shaping the future direction of the project. -## Building Docker Images with Buildx Bake - -We use Docker Buildx Bake to build our Docker images. This allows us to build multiple images concurrently and efficiently. Follow these steps to build the Docker images: - -1. Ensure you have Docker and Docker Buildx installed on your system. - -2. Navigate to the root directory of the project where the `docker-bake.hcl` file is located. - -3. To build all services, run: - ``` - docker buildx bake --file docker-bake.hcl - ``` - -4. To build a specific service, use: - ``` - docker buildx bake --file docker-bake.hcl - ``` - Replace `` with one of the following: - - agents-api - - agents-api-worker - - cozo-migrate - - memory-store - - integrations - - gateway - - embedding-service-cpu - - embedding-service-gpu - -5. To set a custom tag for the images, use: - ``` - docker buildx bake --file docker-bake.hcl --set *.tags=myorg/myimage:v1.0 - ``` - Replace `myorg/myimage:v1.0` with your desired image name and tag. - -6. By default, the images are built with the "latest" tag. To specify a different tag, you can set the TAG variable: - ``` - docker buildx bake --file docker-bake.hcl --set TAG=v1.2.3 - ``` - -Note: The `docker-bake.hcl` file defines the build contexts, Dockerfiles, and tags for each service. If you need to modify the build process for a specific service, update the corresponding target in the `docker-bake.hcl` file. - -Thank you for your interest in contributing to this project! \ No newline at end of file +### Setup Instructions + +##### 1. Clone the Repository +Clone the repository from your preferred source: + +```bash +git clone +``` + +##### 2. Navigate to the Root Directory +Change to the root directory of the project: + +```bash +cd +``` + +##### 3. Set Up Environment Variables +- Create a `.env` file in the root directory. +- Refer to the `.env.example` file for a list of required variables. +- Ensure that all necessary variables are set in the `.env` file. + +##### 4. Create a Docker Volume for Backup +Create a Docker volume named `cozo_backup`: + +```bash +docker volume create cozo_backup +``` + +##### 5. Run the Project using Docker Compose +You can run the project in two different modes: **Single Tenant** or **Multi-Tenant**. Choose one of the following commands based on your requirement: + +###### Single-Tenant Mode +Run the project in single-tenant mode: + +```bash +docker compose --env-file .env --profile temporal-ui --profile single-tenant --profile embedding-cpu --profile self-hosted-db up --force-recreate --build --watch +``` + +> **Note:** In single-tenant mode, you can interact with the SDK directly without the need fopr the API KEY. + +###### Multi-Tenant Mode +Run the project in multi-tenant mode: + +```bash +docker compose --env-file .env --profile temporal-ui --profile multi-tenant --profile embedding-cpu --profile self-hosted-db up --force-recreate --build --watch +``` + +> **Note:** In multi-tenant mode, you need to generate a JWT token that act as an API KEY to interact with the SDK in the local setup. + +##### 6. Generate a JWT Token (Only for Multi-Tenant Mode) + +To generate a JWT token, `jwt-cli` is required. Install it using the following command: + +```bash +npm install -g jwt-cli +``` + +Use the following command and replace `{JWT_SHARED_KEY}` with the corresponding key from your `.env` file to generate a JWT token: + +```bash +jwt encode --secret {JWT_SHARED_KEY} --alg HS512 --exp=$(date -j -v +10d +%s) --sub '00000000-0000-0000-0000-000000000000' '{}' +``` + +This command generates a JWT token that will be valid for 10 days. + +##### 7. Access and Interact +- **Temporal UI**: You can access the Temporal UI through the specified port in your `.env` file. +- **API Interactions**: Depending on the chosen mode, interact with the setup using the provided endpoints. + +##### Troubleshooting +- Ensure that all required Docker images are available. +- Check for missing environment variables in the `.env` file. +- Use the `docker compose logs` command to view detailed logs for debugging. \ No newline at end of file diff --git a/agents-api/.DS_Store b/agents-api/.DS_Store index f34bf5fc6ab49ff1afc9cc40f9c76332bc3f65db..04526ed473706adce6fc097c8f456c9f5425d70f 100644 GIT binary patch delta 161 zcmZoMXfc@JFUrioz`)4BAi%&-!cfc*&ydJaz>vB5BlB`bE07cyP#~Qll_3vVI;p(4 zASow52`IlKsURn_xWvHV8Y2@k3o9Et2RjEh$7CJmFkKE#4$gQ1iRx-219Ke(V?)DQ z9ffL3BLf`;6JxX5T22m8Wqs?Q`0SkAy!@`o8<^!8yEp%2;$xlIAh?;G<1aq|A2TM9 delta 85 zcmZoMXfc@JFU-Qgz`)4BAi%&-mQ-F`kd%|3wD}?PN=AN=1S^9cLm5LVLmorf None: + super().__init__() + self.converter = PydanticEncodingPayloadConverter() + + async def encode(self, payloads: Iterable[Payload]) -> List[Payload]: + return [ + self.converter.to_payload(p) + for p in payloads + ] + + async def decode(self, payloads: Iterable[Payload]) -> List[Payload]: + ret: List[Payload] = [] + for p in payloads: + payload_data = self.converter.from_payload(p) + ret.append(Payload.FromString(bytes(payload_data))) + return ret + +# Assuming Payloads and Payload are properly defined, and EncryptionCodec class is implemented +router: APIRouter = APIRouter() +# codec instantiation +codec = CodecInstantion() + +# CORS middleware +async def cors_middleware(req: Request) -> Response: + origin = req.headers.get("origin") + # Set specific CORS headers for requests from "* + if origin == "*": + headers = { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "POST", + "Access-Control-Allow-Headers": "content-type,x-namespace", + } + return Response(status_code=200, headers=headers) + return Response(status_code=status.HTTP_400_BAD_REQUEST) # Forbidden for other origins + +# Encode route +@router.post("/encode", tags=["encryption"]) +async def encode_payloads(req: Request) -> Response: + if req.headers.get("Content-Type") != "application/json": + raise HTTPException(status_code=400, detail="Invalid content type") + + payloads = json_format.Parse(await req.read(), Payloads()) + + # Apply encoding + encoded_payloads = Payloads(payloads=await codec.encode(payloads.payloads)) + print(encoded_payloads) + + response = JSONResponse(content=json_format.MessageToDict(encoded_payloads)) + print(response) + # await cors_middleware(response) + + define_message = { + "message": "Encoded payloads" + } + + return JSONResponse(content=define_message) + +# Decode route +@router.post("/decode", tags=["decryption"]) +async def decode_payloads(req: Request)-> Response: + if req.headers.get("Content-Type") != "application/json": + raise HTTPException(status_code=400, detail="Invalid content type") + + payloads = json_format.Parse(await req.read(), Payloads()) + + # Apply decoding + decoded_payloads = Payloads(payloads=await codec.decode(payloads.payloads)) + + print(decoded_payloads) + response = JSONResponse(content=json_format.MessageToDict(decoded_payloads)) + + print(response) + # await cors_middleware(response) + + define_message = { + "message": "Decoded payloads" + } + + return JSONResponse(content=define_message) \ No newline at end of file diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index fc730fe82..65c9eefe6 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -28,6 +28,7 @@ sessions, tasks, users, + internal, ) if not sentry_dsn: @@ -122,6 +123,7 @@ async def scalar_html(): app.include_router(jobs.router, dependencies=[Depends(get_api_key)]) app.include_router(docs.router, dependencies=[Depends(get_api_key)]) app.include_router(tasks.router, dependencies=[Depends(get_api_key)]) +app.include_router(internal.router, dependencies=[Depends(get_api_key)]) # TODO: CORS should be enabled only for JWT auth # diff --git a/cookbooks/01_Cookbook.ipynb b/cookbooks/01_Cookbook.ipynb new file mode 100644 index 000000000..6aa6bbbc5 --- /dev/null +++ b/cookbooks/01_Cookbook.ipynb @@ -0,0 +1,371 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Task Definition: Sarcastic News Headline Generator using DuckDuckGo Integration\n", + "\n", + "## Overview\n", + "\n", + "This task is designed to generate a sarcastic news headline on a specific topic provided by the user. The process utilizes a web search to gather additional information and context about the topic and then uses that information to create a headline with a sarcastic tone. Below is a breakdown of how the task works:\n", + "\n", + "### Task Flow\n", + "\n", + "1. **Input**: The user provides a topic for the sarcastic news headline. For example, this could be \"technology\" or \"politics.\"\n", + "\n", + "2. **Web Search Tool using DuckDuckGo Integration**: \n", + " - A search is conducted to find additional information about the topic. The search engine looks for funny or humorous content related to the given subject. \n", + " - This helps in gathering relevant context and funny details to be used in the headline generation.\n", + "\n", + "3. **Headline Creation by the Agent**: \n", + " - Based on the topic and the gathered information, the system generates a sarcastic news headline. The result is a headline that mixes factual or common perceptions of the topic with humor and sarcasm.\n", + " \n", + "4. **Output**: The final result is a sarcastic, witty headline on the given topic, which can be used for entertainment or as a creative writing prompt.\n", + "\n", + "\n", + "This task leverages web search to enhance the system's ability to generate sarcastic content, making the results more contextually relevant and amusing." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf/view?usp=sharing)\n", + "\n", + "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Installing the Julep Client" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install julep -U --quiet" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### NOTE:\n", + "\n", + "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", + "\n", + "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "# Global UUID is generated for agent and task\n", + "import uuid\n", + "\n", + "AGENT_UUID = uuid.uuid4()\n", + "TASK_UUID = uuid.uuid4() " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating Julep Client with the API Key" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "from julep import Client\n", + "\n", + "api_key = \"\" # Your API key here\n", + "\n", + "# Create a client\n", + "client = Client(api_key=api_key, environment=\"dev\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating an \"agent\"\n", + "\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": 13, + "metadata": {}, + "outputs": [], + "source": [ + "# Defining the agent\n", + "name = \"Jarvis\"\n", + "about = \"The original AI conscious the Iron Man.\"\n", + "default_settings = {\n", + " \"temperature\": 0.7,\n", + " \"top_p\": 1,\n", + " \"min_p\": 0.01,\n", + " \"presence_penalty\": 0,\n", + " \"frequency_penalty\": 0,\n", + " \"length_penalty\": 1.0,\n", + " \"max_tokens\": 150,\n", + "}\n", + "\n", + "\n", + "# Create the agent\n", + "agent = client.agents.create_or_update(\n", + " agent_id=AGENT_UUID,\n", + " name=name,\n", + " about=about,\n", + " model=\"gpt-4o\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Listing all the agents\n", + "\n", + "We list the agents to see what agents are available." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Listing all agents available in the account\n", + "get_agents = client.agents.list()\n", + "get_agents.items" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We get the current agent ID from the list of agents." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get the agent id\n", + "agent_id = get_agents.items[0].id\n", + "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", + "You can use them to conduct complex actions by defining them step-by-step. They have access to all Julep integrations.\n", + "\n", + "To learn more about tasks, visit [Julep documentation](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#task)." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo search tool.\n", + "\n", + "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "# defining the task definition\n", + "task_def = yaml.safe_load(\"\"\"\n", + "name: write a sarcastic news headline on a topic\n", + "\n", + "tools:\n", + "- name: websearch\n", + " type: integration\n", + " integration:\n", + " provider: duckduckgo_search\n", + "\n", + "main:\n", + "- tool: websearch\n", + " arguments:\n", + " query: \"_.topic + ' funny'\"\n", + "\n", + "- prompt:\n", + " - role: system\n", + " content: >-\n", + " write a sarcastic news headline on the topic of {{inputs[0].topic}}.\n", + " Here's some more info on this: {{_}}\n", + " unwrap: true\n", + "\n", + "\"\"\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# creating the task object\n", + "task = client.tasks.create_or_update(\n", + " task_id=TASK_UUID,\n", + " agent_id=AGENT_UUID,\n", + " **task_def\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#listing all tasks for a given agent\n", + "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", + "get_tasks.items " + ] + }, + { + "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": "markdown", + "metadata": {}, + "source": [ + "Creates a execution worflow for the Task defined in the yaml file." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# creating an execution object\n", + "execution = client.executions.create(\n", + " task_id=TASK_UUID,\n", + " input={\n", + " \"topic\": \"elon musk\"\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# getting the execution details\n", + "execution = client.executions.get(execution.id)\n", + "#printing the output\n", + "execution.output" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Streaming execution steps of the defined Task." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.stream(execution_id=execution.id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lisitng all the executions states of the task." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.list(execution_id=execution.id).items" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ai", + "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": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cookbooks/02_Cookbook.ipynb b/cookbooks/02_Cookbook.ipynb new file mode 100644 index 000000000..0ebaaebe2 --- /dev/null +++ b/cookbooks/02_Cookbook.ipynb @@ -0,0 +1,402 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Task: Research Assistant with Web Search Integration\n", + "\n", + "## Overview\n", + "\n", + "This task involves conducting research on a list of topics provided by the user. The task flow includes performing web searches to gather information on the latest news for each topic, generating relevant keywords, and utilizing various tools to accomplish the task efficiently.\n", + "\n", + "### Task Flow\n", + "\n", + "1. **Input**: \n", + " - The user provides a list of topics they want to research. Each topic is handled individually to gather relevant information.\n", + "\n", + "2. **Web Search and Context**: \n", + " - For each topic, a web search is conducted using DuckDuckGo to find the latest news and information.\n", + " \n", + "3. **Research Assistant**: \n", + " - The system analyzes the search results (HTML snippets) and generates a list of Wikipedia keywords related to the topic.\n", + " - A prompt instructs the assistant to identify relevant keywords based on the search result content.\n", + "\n", + "4. **Parallel Processing**: \n", + " - The task allows for parallel processing of topics to improve efficiency and speed up the keyword generation process.\n", + "\n", + "This workflow allows for efficient gathering of research topics and relevant Wikipedia keywords, providing a comprehensive approach to in-depth topic exploration.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1C_yeSW4hAMLp0kNseXoxGpAA2cpC9DLu/view?usp=sharing)\n", + "\n", + "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Installing the Julep Client" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install julep -U --quiet" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### NOTE:\n", + "\n", + "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", + "\n", + "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# Global UUID is generated for agent and task\n", + "import uuid\n", + "\n", + "AGENT_UUID = uuid.uuid4()\n", + "TASK_UUID = uuid.uuid4() " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating Julep Client with the API Key" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from julep import Client\n", + "\n", + "api_key = \"\" # Your API key here\n", + "\n", + "# Create a client\n", + "client = Client(api_key=api_key, environment=\"dev\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating an \"agent\"\n", + "\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": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# Defining the agent\n", + "name = \"Jarvis\"\n", + "about = \"The original AI conscious the Iron Man.\"\n", + "default_settings = {\n", + " \"temperature\": 0.7,\n", + " \"top_p\": 1,\n", + " \"min_p\": 0.01,\n", + " \"presence_penalty\": 0,\n", + " \"frequency_penalty\": 0,\n", + " \"length_penalty\": 1.0,\n", + " \"max_tokens\": 150,\n", + "}\n", + "\n", + "\n", + "# Create the agent\n", + "agent = client.agents.create_or_update(\n", + " agent_id=AGENT_UUID,\n", + " name=name,\n", + " about=about,\n", + " model=\"gpt-4o\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Listing all the agents\n", + "\n", + "We list the agents to see what agents are available." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Listing all agents available in the account\n", + "get_agents = client.agents.list()\n", + "get_agents.items" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We get the current agent ID from the list of agents." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get the agent id\n", + "agent_id = get_agents.items[0].id\n", + "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", + "You can use them to conduct complex actions by defining them step-by-step. They have access to all Julep integrations.\n", + "\n", + "To learn more about tasks, visit [Julep documentation](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#task)." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo and Wikipedia tool.\n", + "\n", + "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "task_def= yaml.safe_load(\"\"\"\n", + "name: Research Assistant to find Wikipedia Keywords\n", + "\n", + "input_schema:\n", + " type: object\n", + " properties:\n", + " topics:\n", + " type: array\n", + " items:\n", + " type: string\n", + " description: The topics to search for.\n", + " location:\n", + " type: array\n", + " items:\n", + " type: string\n", + " description: The loacation to search for.\n", + "\n", + "tools:\n", + "- name: websearch\n", + " type: integration\n", + " integration:\n", + " provider: duckduckgo_search\n", + "\n", + "main:\n", + "- over: _.topics\n", + " map:\n", + " tool: websearch\n", + " arguments:\n", + " query: \"'the latest news about ' + _\"\n", + "\n", + "- over: _\n", + " parallelism: 2\n", + " map:\n", + " prompt:\n", + " - role: system\n", + " content: >-\n", + " You are a research assistant.\n", + " I need you to do in-depth research on topics trending in the news currently.\n", + " Based on the following latest html news snippet, come up with a list of wikipedia keywords to search:\n", + " \"{{_}}\"\n", + " Your response should be a list of keywords, separated by commas. Do not add any other text.\n", + " Example: `KEYWORDS: keyword1, keyword2, keyword3`\n", + "\n", + " unwrap: true\n", + "\"\"\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "# creating the task object\n", + "task = client.tasks.create_or_update(\n", + " task_id=TASK_UUID,\n", + " agent_id=AGENT_UUID,\n", + " **task_def\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#listing all tasks for a given agent\n", + "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", + "get_tasks.items " + ] + }, + { + "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": "markdown", + "metadata": {}, + "source": [ + "Creates a execution worflow for the Task defined in the yaml file." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "execution= client.executions.create(\n", + " task_id=task.id,\n", + " input={\n", + " \"topics\": [\"Burger King Cup on the Ground Behind a Wendy’s\",\"Forbidden Chemical X\",\"Finger Bracelets\",\"Amusing Notions\"]\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "execution.id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# getting the execution details\n", + "execution = client.executions.get(execution.id)\n", + "#printing the output\n", + "execution.output" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Streaming execution steps of the defined Task." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.stream(execution_id=execution.id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Listing the execution states." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.list(execution_id=execution.id).items" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ai", + "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": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cookbooks/03_Cookbook.ipynb b/cookbooks/03_Cookbook.ipynb new file mode 100644 index 000000000..d616561d4 --- /dev/null +++ b/cookbooks/03_Cookbook.ipynb @@ -0,0 +1,422 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Task: Travel Itinerary Assistant with Weather and Wikipedia Integrations\n", + "\n", + "## Overview\n", + "The task is designed to assist users in planning a travel itinerary that takes into account current weather conditions and local tourist attractions. The task integrates data from Wikipedia for tourist attractions and uses weather information from an API to provide a comprehensive travel plan.\n", + "\n", + "### Task Flow\n", + "\n", + "1. **Input Locations**: \n", + " - User provides a list of locations.\n", + "\n", + "2. **Fetch Weather Data**: \n", + " - Retrieve current weather conditions for each location using the Weather integration.\n", + "\n", + "3. **Fetch Tourist Attractions**: \n", + " - Use Wikipedia integration to find tourist attractions for each location by appending \"tourist attractions\" to the location name.\n", + "\n", + "4. **Data Evaluation**: \n", + " - Combine the weather and attraction data into a list of tuples: (location, weather, attractions).\n", + "\n", + "5. **Generate Itinerary**: \n", + " - Create a detailed travel itinerary for each location based on:\n", + " - Current weather conditions\n", + " - Top tourist attractions\n", + " - Suggestions for outdoor or indoor activities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)]()\n", + "\n", + "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Installing the Julep Client" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install julep -U --quiet" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### NOTE:\n", + "\n", + "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", + "\n", + "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# Global UUID is generated for agent and task\n", + "import uuid\n", + "\n", + "AGENT_UUID = uuid.uuid4()\n", + "TASK_UUID = uuid.uuid4() " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating Julep Client with the API Key" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "from julep import Client\n", + "\n", + "api_key = \"\" # Your API key here\n", + "\n", + "# Create a client\n", + "client = Client(api_key=api_key, environment=\"dev\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating an \"agent\"\n", + "\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": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# Defining the agent\n", + "name = \"Jarvis\"\n", + "about = \"The original AI conscious the Iron Man.\"\n", + "default_settings = {\n", + " \"temperature\": 0.7,\n", + " \"top_p\": 1,\n", + " \"min_p\": 0.01,\n", + " \"presence_penalty\": 0,\n", + " \"frequency_penalty\": 0,\n", + " \"length_penalty\": 1.0,\n", + " \"max_tokens\": 150,\n", + "}\n", + "\n", + "# Create the agent\n", + "agent = client.agents.create_or_update(\n", + " agent_id=AGENT_UUID,\n", + " name=name,\n", + " about=about,\n", + " model=\"gpt-4o\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Listing all the agents\n", + "\n", + "We list the agents to see what agents are available." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Listing all agents available in the account\n", + "get_agents = client.agents.list()\n", + "get_agents.items" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We get the current agent ID from the list of agents." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get the agent id\n", + "agent_id = get_agents.items[0].id\n", + "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", + "You can use them to conduct complex actions by defining them step-by-step. They have access to all Julep integrations.\n", + "\n", + "To learn more about tasks, visit [Julep documentation](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#task)." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo and Wikipedia tool.\n", + "\n", + "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "task_def= yaml.safe_load(\"\"\"\n", + "name: TouristPlanWithWeatherAndAttractions\n", + "\n", + "input_schema:\n", + " type: object\n", + " properties:\n", + " locations:\n", + " type: array\n", + " items:\n", + " type: string\n", + " description: The locations to search for.\n", + "\n", + "tools:\n", + "\n", + "- name: wikipedia\n", + " type: integration\n", + " integration:\n", + " provider: wikipedia\n", + "\n", + "- name: weather\n", + " type: integration\n", + " integration:\n", + " provider: weather\n", + " setup:\n", + " openweathermap_api_key: '\"\"'\n", + "\n", + "main:\n", + "\n", + "- over: _ \n", + " map: \n", + " tool: weather\n", + " arguments:\n", + " location: _\n", + "\n", + "- over: inputs[0].locations \n", + " map: \n", + " tool: wikipedia\n", + " arguments:\n", + " query: \"_ + ' tourist attractions'\"\n", + "\n", + "- over: _ \n", + " evaluate:\n", + " zipped: list(zip(inputs[0].locations, outputs[0], outputs[1])) # [(location, weather, attractions)]\n", + "\n", + "- over: _\n", + " parallelism: 1\n", + " map:\n", + " prompt:\n", + " - role: system\n", + " content: >-\n", + " You are a travel assistant. Your task is to create a detailed itinerary for visiting tourist attractions in {{_[0]}} based on the weather conditions and the top tourist attractions provided.\n", + " \n", + " Current weather condition at {{_[0]}}:\n", + " {{_[1]}}\n", + "\n", + "\n", + " Top tourist attractions in {{_[0]}}:\n", + " {{_[2]}}\n", + "\n", + "\n", + " Suggest outdoor or indoor activities based on the above information.\n", + " \n", + " unwrap: true \n", + "\"\"\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "# creating the task object\n", + "task = client.tasks.create_or_update(\n", + " task_id=TASK_UUID,\n", + " agent_id=AGENT_UUID,\n", + " **task_def\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#listing all tasks for a given agent\n", + "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", + "get_tasks.items " + ] + }, + { + "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": "markdown", + "metadata": {}, + "source": [ + "Creates a execution worflow for the Task defined in the yaml file." + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "execution = client.executions.create(\n", + " task_id=task.id,\n", + " input={\n", + " \"locations\": [\"New York\"]\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "execution.id" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "# getting the execution details\n", + "execution = client.executions.get(execution.id)\n", + "#printing the output\n", + "execution.output" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Streaming execution steps of the defined Task." + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.stream(execution_id=execution.id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Listing the execution states." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.list(execution_id=execution.id).items" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ai", + "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": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 13070032c475f9a9e2e097e9efe77a7d325c6f72 Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Tue, 1 Oct 2024 17:20:24 -0400 Subject: [PATCH 2/8] fix: cookbooks tested and comments added/codec fixes --- .../agents_api/routers/internal/router.py | 18 +- cookbooks/01_Cookbook.ipynb | 47 +- cookbooks/02_Cookbook.ipynb | 113 ++--- cookbooks/03_Cookbook.ipynb | 123 +++--- cookbooks/04_Cookbook.ipynb | 418 ++++++++++++++++++ 5 files changed, 532 insertions(+), 187 deletions(-) create mode 100644 cookbooks/04_Cookbook.ipynb diff --git a/agents-api/agents_api/routers/internal/router.py b/agents-api/agents_api/routers/internal/router.py index 0f73419bc..aac35e664 100644 --- a/agents-api/agents_api/routers/internal/router.py +++ b/agents-api/agents_api/routers/internal/router.py @@ -57,13 +57,9 @@ async def encode_payloads(req: Request) -> Response: response = JSONResponse(content=json_format.MessageToDict(encoded_payloads)) print(response) - # await cors_middleware(response) - - define_message = { - "message": "Encoded payloads" - } + # response = await cors_middleware(response) - return JSONResponse(content=define_message) + return response # Decode route @router.post("/decode", tags=["decryption"]) @@ -80,10 +76,6 @@ async def decode_payloads(req: Request)-> Response: response = JSONResponse(content=json_format.MessageToDict(decoded_payloads)) print(response) - # await cors_middleware(response) - - define_message = { - "message": "Decoded payloads" - } - - return JSONResponse(content=define_message) \ No newline at end of file + # response = await cors_middleware(response) + + return response \ No newline at end of file diff --git a/cookbooks/01_Cookbook.ipynb b/cookbooks/01_Cookbook.ipynb index 6aa6bbbc5..a68a92bc6 100644 --- a/cookbooks/01_Cookbook.ipynb +++ b/cookbooks/01_Cookbook.ipynb @@ -4,27 +4,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task Definition: Sarcastic News Headline Generator using DuckDuckGo Integration\n", + "# Task Definition: Spider Crawler Integration without Agents\n", "\n", "## Overview\n", "\n", - "This task is designed to generate a sarcastic news headline on a specific topic provided by the user. The process utilizes a web search to gather additional information and context about the topic and then uses that information to create a headline with a sarcastic tone. Below is a breakdown of how the task works:\n", + "This task is designed to generate a simple Spider Crawler and integarte it with the worflow to scrape the data from the web.\n", "\n", "### Task Flow\n", "\n", - "1. **Input**: The user provides a topic for the sarcastic news headline. For example, this could be \"technology\" or \"politics.\"\n", + "1. **Input**: The user provides url to crawl.\"\n", "\n", - "2. **Web Search Tool using DuckDuckGo Integration**: \n", - " - A search is conducted to find additional information about the topic. The search engine looks for funny or humorous content related to the given subject. \n", - " - This helps in gathering relevant context and funny details to be used in the headline generation.\n", + "2. **Spider Tool ntegration**: \n", + " - Create a spider tool that can crawl the web and extract the data from the given url.\n", "\n", - "3. **Headline Creation by the Agent**: \n", - " - Based on the topic and the gathered information, the system generates a sarcastic news headline. The result is a headline that mixes factual or common perceptions of the topic with humor and sarcasm.\n", - " \n", - "4. **Output**: The final result is a sarcastic, witty headline on the given topic, which can be used for entertainment or as a creative writing prompt.\n", + "3. **Output**: The final output is the extracted data from the given url.\n", "\n", - "\n", - "This task leverages web search to enhance the system's ability to generate sarcastic content, making the results more contextually relevant and amusing." + "This task leverages the Spider Crawler tool to extract the data from the given url." ] }, { @@ -87,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -113,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -216,26 +211,20 @@ "source": [ "# defining the task definition\n", "task_def = yaml.safe_load(\"\"\"\n", - "name: write a sarcastic news headline on a topic\n", + "name: Agent Crawler\n", "\n", "tools:\n", - "- name: websearch\n", + "- name: spider_crawler\n", " type: integration\n", " integration:\n", - " provider: duckduckgo_search\n", + " provider: spider\n", + " setup:\n", + " spider_api_key: \"your_spider_api_key\"\n", "\n", "main:\n", - "- tool: websearch\n", + "- tool: spider_crawler\n", " arguments:\n", - " query: \"_.topic + ' funny'\"\n", - "\n", - "- prompt:\n", - " - role: system\n", - " content: >-\n", - " write a sarcastic news headline on the topic of {{inputs[0].topic}}.\n", - " Here's some more info on this: {{_}}\n", - " unwrap: true\n", - "\n", + " url: '\"https://spider.cloud\"'\n", "\"\"\")" ] }, @@ -296,9 +285,7 @@ "# creating an execution object\n", "execution = client.executions.create(\n", " task_id=TASK_UUID,\n", - " input={\n", - " \"topic\": \"elon musk\"\n", - " }\n", + " input={}\n", ")" ] }, diff --git a/cookbooks/02_Cookbook.ipynb b/cookbooks/02_Cookbook.ipynb index 0ebaaebe2..65bda5ac7 100644 --- a/cookbooks/02_Cookbook.ipynb +++ b/cookbooks/02_Cookbook.ipynb @@ -4,28 +4,27 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task: Research Assistant with Web Search Integration\n", + "# Task Definition: Sarcastic News Headline Generator using Bravesearch Integration\n", "\n", "## Overview\n", "\n", - "This task involves conducting research on a list of topics provided by the user. The task flow includes performing web searches to gather information on the latest news for each topic, generating relevant keywords, and utilizing various tools to accomplish the task efficiently.\n", + "This task is designed to generate a sarcastic news headline on a specific topic provided by the user. The process utilizes a web search to gather additional information and context about the topic and then uses that information to create a headline with a sarcastic tone. Below is a breakdown of how the task works:\n", "\n", "### Task Flow\n", "\n", - "1. **Input**: \n", - " - The user provides a list of topics they want to research. Each topic is handled individually to gather relevant information.\n", + "1. **Input**: The user provides a topic for the sarcastic news headline. For example, this could be \"technology\" or \"politics.\"\n", "\n", - "2. **Web Search and Context**: \n", - " - For each topic, a web search is conducted using DuckDuckGo to find the latest news and information.\n", + "2. **Web Search Tool using Bravesearch Integration**: \n", + " - A search is conducted to find additional information about the topic. The search engine looks for funny or humorous content related to the given subject. \n", + " - This helps in gathering relevant context and funny details to be used in the headline generation.\n", + "\n", + "3. **Headline Creation by the Agent**: \n", + " - Based on the topic and the gathered information, the system generates a sarcastic news headline. The result is a headline that mixes factual or common perceptions of the topic with humor and sarcasm.\n", " \n", - "3. **Research Assistant**: \n", - " - The system analyzes the search results (HTML snippets) and generates a list of Wikipedia keywords related to the topic.\n", - " - A prompt instructs the assistant to identify relevant keywords based on the search result content.\n", + "4. **Output**: The final result is a sarcastic, witty headline on the given topic, which can be used for entertainment or as a creative writing prompt.\n", "\n", - "4. **Parallel Processing**: \n", - " - The task allows for parallel processing of topics to improve efficiency and speed up the keyword generation process.\n", "\n", - "This workflow allows for efficient gathering of research topics and relevant Wikipedia keywords, providing a comprehensive approach to in-depth topic exploration.\n" + "This task leverages web search to enhance the system's ability to generate sarcastic content, making the results more contextually relevant and amusing." ] }, { @@ -34,7 +33,7 @@ "source": [ "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1C_yeSW4hAMLp0kNseXoxGpAA2cpC9DLu/view?usp=sharing)\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf/view?usp=sharing)\n", "\n", "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." ] @@ -48,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -68,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -88,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -114,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -193,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -204,61 +203,41 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo and Wikipedia tool.\n", + "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo search tool.\n", "\n", "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ - "task_def= yaml.safe_load(\"\"\"\n", - "name: Research Assistant to find Wikipedia Keywords\n", - "\n", - "input_schema:\n", - " type: object\n", - " properties:\n", - " topics:\n", - " type: array\n", - " items:\n", - " type: string\n", - " description: The topics to search for.\n", - " location:\n", - " type: array\n", - " items:\n", - " type: string\n", - " description: The loacation to search for.\n", + "# defining the task definition\n", + "task_def = yaml.safe_load(\"\"\"\n", + "name: Sarcasm Headline Generator\n", "\n", "tools:\n", - "- name: websearch\n", + "- name: brave_search\n", " type: integration\n", " integration:\n", - " provider: duckduckgo_search\n", + " provider: brave\n", + " setup:\n", + " api_key: \"YOU_API_KEY\"\n", "\n", "main:\n", - "- over: _.topics\n", - " map:\n", - " tool: websearch\n", - " arguments:\n", - " query: \"'the latest news about ' + _\"\n", + "- tool: brave_search\n", + " arguments:\n", + " query: \"_.topic + ' funny'\"\n", "\n", - "- over: _\n", - " parallelism: 2\n", - " map:\n", - " prompt:\n", - " - role: system\n", - " content: >-\n", - " You are a research assistant.\n", - " I need you to do in-depth research on topics trending in the news currently.\n", - " Based on the following latest html news snippet, come up with a list of wikipedia keywords to search:\n", - " \"{{_}}\"\n", - " Your response should be a list of keywords, separated by commas. Do not add any other text.\n", - " Example: `KEYWORDS: keyword1, keyword2, keyword3`\n", + "- prompt:\n", + " - role: system\n", + " content: >-\n", + " write a sarcastic news headline on the topic of {{inputs[0].topic}}.\n", + " Here's some more info on this: {{_}}\n", + " unwrap: true\n", "\n", - " unwrap: true\n", "\"\"\")" ] }, @@ -271,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -312,27 +291,19 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ - "execution= client.executions.create(\n", - " task_id=task.id,\n", + "# creating an execution object\n", + "execution = client.executions.create(\n", + " task_id=TASK_UUID,\n", " input={\n", - " \"topics\": [\"Burger King Cup on the Ground Behind a Wendy’s\",\"Forbidden Chemical X\",\"Finger Bracelets\",\"Amusing Notions\"]\n", + " \"topic\": \"elon musk\"\n", " }\n", ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "execution.id" - ] - }, { "cell_type": "code", "execution_count": null, @@ -365,7 +336,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Listing the execution states." + "Lisitng all the executions states of the task." ] }, { diff --git a/cookbooks/03_Cookbook.ipynb b/cookbooks/03_Cookbook.ipynb index d616561d4..b9b40e246 100644 --- a/cookbooks/03_Cookbook.ipynb +++ b/cookbooks/03_Cookbook.ipynb @@ -4,30 +4,28 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task: Travel Itinerary Assistant with Weather and Wikipedia Integrations\n", + "# Task: Research Assistant with Web Search Integration\n", "\n", "## Overview\n", - "The task is designed to assist users in planning a travel itinerary that takes into account current weather conditions and local tourist attractions. The task integrates data from Wikipedia for tourist attractions and uses weather information from an API to provide a comprehensive travel plan.\n", "\n", - "### Task Flow\n", + "This task involves conducting research on a list of topics provided by the user. The task flow includes performing web searches to gather information on the latest news for each topic, generating relevant keywords, and utilizing various tools to accomplish the task efficiently.\n", "\n", - "1. **Input Locations**: \n", - " - User provides a list of locations.\n", + "### Task Flow\n", "\n", - "2. **Fetch Weather Data**: \n", - " - Retrieve current weather conditions for each location using the Weather integration.\n", + "1. **Input**: \n", + " - The user provides a list of topics they want to research. Each topic is handled individually to gather relevant information.\n", "\n", - "3. **Fetch Tourist Attractions**: \n", - " - Use Wikipedia integration to find tourist attractions for each location by appending \"tourist attractions\" to the location name.\n", + "2. **Web Search and Context**: \n", + " - For each topic, a web search is conducted using BraveWeb to find the latest news and information.\n", + " \n", + "3. **Research Assistant**: \n", + " - The system analyzes the search results (HTML snippets) and generates a list of Wikipedia keywords related to the topic.\n", + " - A prompt instructs the assistant to identify relevant keywords based on the search result content.\n", "\n", - "4. **Data Evaluation**: \n", - " - Combine the weather and attraction data into a list of tuples: (location, weather, attractions).\n", + "4. **Parallel Processing**: \n", + " - The task allows for parallel processing of topics to improve efficiency and speed up the keyword generation process.\n", "\n", - "5. **Generate Itinerary**: \n", - " - Create a detailed travel itinerary for each location based on:\n", - " - Current weather conditions\n", - " - Top tourist attractions\n", - " - Suggestions for outdoor or indoor activities" + "This workflow allows for efficient gathering of research topics and relevant Wikipedia keywords, providing a comprehensive approach to in-depth topic exploration.\n" ] }, { @@ -36,7 +34,7 @@ "source": [ "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)]()\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1C_yeSW4hAMLp0kNseXoxGpAA2cpC9DLu/view?usp=sharing)\n", "\n", "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." ] @@ -50,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -70,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -78,7 +76,7 @@ "import uuid\n", "\n", "AGENT_UUID = uuid.uuid4()\n", - "TASK_UUID = uuid.uuid4() " + "TASK_UUID = uuid.uuid4()" ] }, { @@ -90,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -116,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -133,6 +131,7 @@ " \"max_tokens\": 150,\n", "}\n", "\n", + "\n", "# Create the agent\n", "agent = client.agents.create_or_update(\n", " agent_id=AGENT_UUID,\n", @@ -194,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -212,73 +211,51 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "task_def= yaml.safe_load(\"\"\"\n", - "name: TouristPlanWithWeatherAndAttractions\n", + "name: Research Assistant to find Wikipedia Keywords\n", "\n", "input_schema:\n", " type: object\n", " properties:\n", - " locations:\n", + " topics:\n", " type: array\n", " items:\n", " type: string\n", - " description: The locations to search for.\n", + " description: The topics to search for.\n", "\n", "tools:\n", - "\n", - "- name: wikipedia\n", + "- name: brave_search\n", " type: integration\n", " integration:\n", - " provider: wikipedia\n", - "\n", - "- name: weather\n", - " type: integration\n", - " integration:\n", - " provider: weather\n", + " provider: brave\n", " setup:\n", - " openweathermap_api_key: '\"\"'\n", + " api_key: \"YOUR_API_KEY\"\n", "\n", "main:\n", - "\n", - "- over: _ \n", - " map: \n", - " tool: weather\n", - " arguments:\n", - " location: _\n", - "\n", - "- over: inputs[0].locations \n", - " map: \n", - " tool: wikipedia\n", + "- over: _.topics\n", + " map:\n", + " tool: brave_search\n", " arguments:\n", - " query: \"_ + ' tourist attractions'\"\n", - "\n", - "- over: _ \n", - " evaluate:\n", - " zipped: list(zip(inputs[0].locations, outputs[0], outputs[1])) # [(location, weather, attractions)]\n", + " query: \"'the latest news about ' + _\"\n", "\n", "- over: _\n", - " parallelism: 1\n", + " parallelism: 2\n", " map:\n", " prompt:\n", " - role: system\n", " content: >-\n", - " You are a travel assistant. Your task is to create a detailed itinerary for visiting tourist attractions in {{_[0]}} based on the weather conditions and the top tourist attractions provided.\n", - " \n", - " Current weather condition at {{_[0]}}:\n", - " {{_[1]}}\n", - "\n", - "\n", - " Top tourist attractions in {{_[0]}}:\n", - " {{_[2]}}\n", - "\n", - "\n", - " Suggest outdoor or indoor activities based on the above information.\n", - " \n", - " unwrap: true \n", + " You are a research assistant.\n", + " I need you to do in-depth research on topics trending in the news currently.\n", + " Based on the following latest html news snippet, come up with a list of wikipedia keywords to search:\n", + " \"{{_}}\"\n", + " Your response should be a list of keywords, separated by commas. Do not add any other text.\n", + " Example: `KEYWORDS: keyword1, keyword2, keyword3`\n", + "\n", + " unwrap: true\n", "\"\"\")" ] }, @@ -291,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -332,14 +309,14 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "execution = client.executions.create(\n", + "execution= client.executions.create(\n", " task_id=task.id,\n", " input={\n", - " \"locations\": [\"New York\"]\n", + " \"topics\": [\"Burger King Cup on the Ground Behind a Wendy’s\",\"Forbidden Chemical X\",\"Finger Bracelets\",\"Amusing Notions\"]\n", " }\n", ")" ] @@ -355,13 +332,13 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "# getting the execution details\n", "execution = client.executions.get(execution.id)\n", - "#printing the output\n", + "#printing the outpu\n", "execution.output" ] }, @@ -374,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -414,7 +391,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/cookbooks/04_Cookbook.ipynb b/cookbooks/04_Cookbook.ipynb new file mode 100644 index 000000000..8ec82e543 --- /dev/null +++ b/cookbooks/04_Cookbook.ipynb @@ -0,0 +1,418 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Task: Travel Itinerary Assistant with Weather and Wikipedia Integrations\n", + "\n", + "## Overview\n", + "The task is designed to assist users in planning a travel itinerary that takes into account current weather conditions and local tourist attractions. The task integrates data from Wikipedia for tourist attractions and uses weather information from an API to provide a comprehensive travel plan.\n", + "\n", + "### Task Flow\n", + "\n", + "1. **Input Locations**: \n", + " - User provides a list of locations.\n", + "\n", + "2. **Fetch Weather Data**: \n", + " - Retrieve current weather conditions for each location using the Weather integration.\n", + "\n", + "3. **Fetch Tourist Attractions**: \n", + " - Use Wikipedia integration to find tourist attractions for each location by appending \"tourist attractions\" to the location name.\n", + "\n", + "4. **Data Evaluation**: \n", + " - Combine the weather and attraction data into a list of tuples: (location, weather, attractions).\n", + "\n", + "5. **Generate Itinerary**: \n", + " - Create a detailed travel itinerary for each location based on:\n", + " - Current weather conditions\n", + " - Top tourist attractions\n", + " - Suggestions for outdoor or indoor activities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)]()\n", + "\n", + "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Installing the Julep Client" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install julep -U --quiet" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### NOTE:\n", + "\n", + "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", + "\n", + "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# Global UUID is generated for agent and task\n", + "import uuid\n", + "\n", + "AGENT_UUID = uuid.uuid4()\n", + "TASK_UUID = uuid.uuid4() " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating Julep Client with the API Key" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "from julep import Client\n", + "\n", + "api_key = \"\" # Your API key here\n", + "\n", + "# Create a client\n", + "client = Client(api_key=api_key, environment=\"dev\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating an \"agent\"\n", + "\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": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# Defining the agent\n", + "name = \"Jarvis\"\n", + "about = \"The original AI conscious the Iron Man.\"\n", + "default_settings = {\n", + " \"temperature\": 0.7,\n", + " \"top_p\": 1,\n", + " \"min_p\": 0.01,\n", + " \"presence_penalty\": 0,\n", + " \"frequency_penalty\": 0,\n", + " \"length_penalty\": 1.0,\n", + " \"max_tokens\": 150,\n", + "}\n", + "\n", + "# Create the agent\n", + "agent = client.agents.create_or_update(\n", + " agent_id=AGENT_UUID,\n", + " name=name,\n", + " about=about,\n", + " model=\"gpt-4o\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Listing all the agents\n", + "\n", + "We list the agents to see what agents are available." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Listing all agents available in the account\n", + "get_agents = client.agents.list()\n", + "get_agents.items" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We get the current agent ID from the list of agents." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get the agent id\n", + "agent_id = get_agents.items[0].id\n", + "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", + "You can use them to conduct complex actions by defining them step-by-step. They have access to all Julep integrations.\n", + "\n", + "To learn more about tasks, visit [Julep documentation](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#task)." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo and Wikipedia tool.\n", + "\n", + "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "task_def= yaml.safe_load(\"\"\"\n", + "name: Tourist Plan With Weather And Attractions\n", + "\n", + "input_schema:\n", + " type: object\n", + " properties:\n", + " locations:\n", + " type: array\n", + " items:\n", + " type: string\n", + " description: The locations to search for.\n", + "\n", + "tools:\n", + "- name: wikipedia\n", + " type: integration\n", + " integration:\n", + " provider: wikipedia\n", + "\n", + "- name: weather\n", + " type: integration\n", + " integration:\n", + " provider: weather\n", + " setup:\n", + " openweathermap_api_key: \"YOUR_API_KEY\"\n", + "\n", + "main:\n", + "- over: inputs[0].locations\n", + " map:\n", + " tool: weather\n", + " arguments:\n", + " location: _\n", + "\n", + "- over: inputs[0].locations\n", + " map:\n", + " tool: wikipedia\n", + " arguments:\n", + " query: \"_ + ' tourist attractions'\"\n", + "\n", + "- over: _\n", + " evaluate:\n", + " zipped: \"list(zip(inputs[0].locations, outputs[0], outputs[1]))\" # [(location, weather, attractions)]\n", + "\n", + "- over: _\n", + " parallelism: 1\n", + " map:\n", + " prompt:\n", + " - role: system\n", + " content: >-\n", + " You are a travel assistant. Your task is to create a detailed itinerary for visiting tourist attractions in \"{{_[0]}}\" based on the weather conditions and the top tourist attractions provided.\n", + " \n", + " Current weather condition at \"{{_[0]}}\":\n", + " \"{{_[1]}}\"\n", + "\n", + " Top tourist attractions in \"{{_[0]}}\":\n", + " \"{{_[2]}}\"\n", + "\n", + " Suggest outdoor or indoor activities based on the above information.\n", + " unwrap: true\n", + " \n", + "\"\"\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "# creating the task object\n", + "task = client.tasks.create_or_update(\n", + " task_id=TASK_UUID,\n", + " agent_id=AGENT_UUID,\n", + " **task_def\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#listing all tasks for a given agent\n", + "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", + "get_tasks.items " + ] + }, + { + "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": "markdown", + "metadata": {}, + "source": [ + "Creates a execution worflow for the Task defined in the yaml file." + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "execution = client.executions.create(\n", + " task_id=task.id,\n", + " input={\n", + " \"locations\": [\"New York\"]\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "execution.id" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "# getting the execution details\n", + "execution = client.executions.get(execution.id)\n", + "#printing the output\n", + "execution.output" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Streaming execution steps of the defined Task." + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.stream(execution_id=execution.id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Listing the execution states." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client.executions.transitions.list(execution_id=execution.id).items" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ai", + "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": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 797e88ea4e59dbc14502215fce7997f8c017cf43 Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Tue, 1 Oct 2024 18:34:25 -0400 Subject: [PATCH 3/8] cookboks: updated the comment --- cookbooks/01_Cookbook.ipynb | 41 ++++++++++++-------- cookbooks/02_Cookbook.ipynb | 70 +++++++++++++++++++++++++--------- cookbooks/03_Cookbook.ipynb | 69 ++++++++++++++++++++++++---------- cookbooks/04_Cookbook.ipynb | 75 ++++++++++++++++++++++++++----------- 4 files changed, 181 insertions(+), 74 deletions(-) diff --git a/cookbooks/01_Cookbook.ipynb b/cookbooks/01_Cookbook.ipynb index a68a92bc6..a1ce59823 100644 --- a/cookbooks/01_Cookbook.ipynb +++ b/cookbooks/01_Cookbook.ipynb @@ -4,33 +4,44 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task Definition: Spider Crawler Integration without Agents\n", + "
\n", + " \"julep\"\n", + "
\n", "\n", - "## Overview\n", + "## Task Definition: Spider Crawler Integration without Agents\n", "\n", - "This task is designed to generate a simple Spider Crawler and integarte it with the worflow to scrape the data from the web.\n", + "### Overview\n", + "\n", + "This task is designed to generate a simple Spider Crawler and integrate it with the workflow to scrape data from the web.\n", "\n", "### Task Flow\n", "\n", - "1. **Input**: The user provides url to crawl.\"\n", + "1. **Input**: The user provides a URL to crawl.\n", "\n", - "2. **Spider Tool ntegration**: \n", - " - Create a spider tool that can crawl the web and extract the data from the given url.\n", + "2. **Spider Tool Integration**: \n", + " - Create a spider tool that can crawl the web and extract data from the given URL.\n", "\n", - "3. **Output**: The final output is the extracted data from the given url.\n", + "3. **Output**: The final output is the extracted data from the given URL.\n", "\n", - "This task leverages the Spider Crawler tool to extract the data from the given url." + "This task leverages the Spider Crawler tool to extract data from the given URL." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "### 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", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf/view?usp=sharing)\n", + "### Additional Information\n", "\n", - "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + "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:** [hey@julep.ai](mailto:hey@julep.ai)" ] }, { @@ -55,9 +66,10 @@ "source": [ "#### NOTE:\n", "\n", - "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", - "\n", - "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + "- 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." ] }, { @@ -100,7 +112,6 @@ "source": [ "## Creating an \"agent\"\n", "\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)." diff --git a/cookbooks/02_Cookbook.ipynb b/cookbooks/02_Cookbook.ipynb index 65bda5ac7..a186e789f 100644 --- a/cookbooks/02_Cookbook.ipynb +++ b/cookbooks/02_Cookbook.ipynb @@ -4,38 +4,73 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task Definition: Sarcastic News Headline Generator using Bravesearch Integration\n", + "
\n", + " \"julep\"\n", + "
\n", "\n", - "## Overview\n", + "## Task Definition: Sarcastic News Headline Generator using Brave Search Integration\n", "\n", - "This task is designed to generate a sarcastic news headline on a specific topic provided by the user. The process utilizes a web search to gather additional information and context about the topic and then uses that information to create a headline with a sarcastic tone. Below is a breakdown of how the task works:\n", + "### Overview\n", + "\n", + "This task generates a sarcastic news headline on a user-provided topic. It utilizes web search to gather context and information about the topic, then uses this data to create a headline with a sarcastic tone. \n", "\n", "### Task Flow\n", "\n", - "1. **Input**: The user provides a topic for the sarcastic news headline. For example, this could be \"technology\" or \"politics.\"\n", + "1. **Input**: \n", + " - User provides a topic for the sarcastic news headline (e.g., \"technology\" or \"politics\").\n", "\n", - "2. **Web Search Tool using Bravesearch Integration**: \n", - " - A search is conducted to find additional information about the topic. The search engine looks for funny or humorous content related to the given subject. \n", - " - This helps in gathering relevant context and funny details to be used in the headline generation.\n", + "2. **Web Search using Bravesearch Integration**: \n", + " - Conducts a search to find information about the topic, focusing on humorous or quirky content.\n", + " - Gathers relevant context and amusing details for headline generation.\n", "\n", - "3. **Headline Creation by the Agent**: \n", - " - Based on the topic and the gathered information, the system generates a sarcastic news headline. The result is a headline that mixes factual or common perceptions of the topic with humor and sarcasm.\n", + "3. **Headline Creation**: \n", + " - Generates a sarcastic news headline based on the topic and gathered information.\n", + " - Combines factual or common perceptions with humor and sarcasm.\n", " \n", - "4. **Output**: The final result is a sarcastic, witty headline on the given topic, which can be used for entertainment or as a creative writing prompt.\n", + "4. **Output**: \n", + " - Produces a sarcastic, witty headline on the given topic.\n", + " - Can be used for entertainment or as a creative writing prompt.\n", + "\n", + "### Key Features\n", + "\n", + "- Leverages web search to enhance contextual relevance of sarcastic content.\n", + "- Combines real-world information with humorous twists for engaging headlines.\n", + "- Adaptable to various topics, allowing for diverse and creative outputs.\n", + "\n", + "```\n", + "\n", "\n", + " +----------+ +------------+ +------------+ +-----------+\n", + " | User | | Brave | | Agent | | Sarcastic |\n", + " | Input | --> | Search | --> | Processing | --> | Headline |\n", + " | (Topic) | | | | | | Output |\n", + " +----------+ +------------+ +------------+ +-----------+\n", + " | | | |\n", + " | | | |\n", + " v v v v\n", + " \"politics\" Find funny Generate witty \"Area Man Still\n", + " content headline Believes in \n", + " Democracy\"\n", "\n", - "This task leverages web search to enhance the system's ability to generate sarcastic content, making the results more contextually relevant and amusing." + "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "### Implementation\n", "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf/view?usp=sharing)\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", - "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\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:** [hey@julep.ai](mailto:hey@julep.ai)" ] }, { @@ -60,9 +95,10 @@ "source": [ "#### NOTE:\n", "\n", - "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", - "\n", - "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + "- 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." ] }, { diff --git a/cookbooks/03_Cookbook.ipynb b/cookbooks/03_Cookbook.ipynb index b9b40e246..a9125dfb9 100644 --- a/cookbooks/03_Cookbook.ipynb +++ b/cookbooks/03_Cookbook.ipynb @@ -4,39 +4,67 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task: Research Assistant with Web Search Integration\n", + "
\n", + " \"julep\"\n", + "
\n", "\n", - "## Overview\n", + "## Task: Research Assistant with Web Search Integration\n", "\n", - "This task involves conducting research on a list of topics provided by the user. The task flow includes performing web searches to gather information on the latest news for each topic, generating relevant keywords, and utilizing various tools to accomplish the task efficiently.\n", + "### Overview\n", + "\n", + "This task is designed to conduct comprehensive research on multiple user-provided topics. It leverages web search capabilities to gather up-to-date information and generates relevant keywords for each topic, streamlining the research process through efficient tool integration and parallel processing.\n", "\n", "### Task Flow\n", "\n", - "1. **Input**: \n", - " - The user provides a list of topics they want to research. Each topic is handled individually to gather relevant information.\n", + "1. **User Input**\n", + " - User provides a list of research topics\n", + " - Each topic is processed individually\n", + "\n", + "2. **Web Search and Information Gathering**\n", + " - Utilizes BraveWeb to conduct searches for each topic\n", + " - Retrieves latest news and relevant information\n", + "\n", + "3. **Intelligent Analysis**\n", + " - System analyzes search results (HTML snippets)\n", + " - Generates Wikipedia keywords related to each topic\n", + " - AI assistant identifies most relevant keywords based on search content\n", + "\n", + "4. **Parallel Processing**\n", + " - Implements concurrent topic processing\n", + " - Enhances efficiency and reduces overall research time\n", + "\n", + "### Key Features\n", "\n", - "2. **Web Search and Context**: \n", - " - For each topic, a web search is conducted using BraveWeb to find the latest news and information.\n", - " \n", - "3. **Research Assistant**: \n", - " - The system analyzes the search results (HTML snippets) and generates a list of Wikipedia keywords related to the topic.\n", - " - A prompt instructs the assistant to identify relevant keywords based on the search result content.\n", + "- **Multi-topic Research**: Handles multiple research topics simultaneously\n", + "- **Up-to-date Information**: Utilizes web search to access current data\n", + "- **Keyword Generation**: Provides relevant Wikipedia keywords for each topic\n", + "- **AI-assisted Analysis**: Employs AI to identify and prioritize key information\n", + "- **Efficient Processing**: Leverages parallel processing for faster results\n", "\n", - "4. **Parallel Processing**: \n", - " - The task allows for parallel processing of topics to improve efficiency and speed up the keyword generation process.\n", + "### Output\n", "\n", - "This workflow allows for efficient gathering of research topics and relevant Wikipedia keywords, providing a comprehensive approach to in-depth topic exploration.\n" + "- Comprehensive list of relevant Wikipedia keywords for each input topic\n", + "- Curated, up-to-date information gathered from web searches\n", + "\n", + "This workflow provides a robust, efficient approach to in-depth topic exploration, combining the power of web search, AI analysis, and parallel processing.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "### 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", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1C_yeSW4hAMLp0kNseXoxGpAA2cpC9DLu/view?usp=sharing)\n", + "### Additional Information\n", "\n", - "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + "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:** [hey@julep.ai](mailto:hey@julep.ai)" ] }, { @@ -61,9 +89,10 @@ "source": [ "#### NOTE:\n", "\n", - "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", - "\n", - "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + "- 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." ] }, { diff --git a/cookbooks/04_Cookbook.ipynb b/cookbooks/04_Cookbook.ipynb index 8ec82e543..fb08fb6e7 100644 --- a/cookbooks/04_Cookbook.ipynb +++ b/cookbooks/04_Cookbook.ipynb @@ -4,41 +4,71 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Task: Travel Itinerary Assistant with Weather and Wikipedia Integrations\n", + "
\n", + " \"julep\"\n", + "
\n", "\n", - "## Overview\n", - "The task is designed to assist users in planning a travel itinerary that takes into account current weather conditions and local tourist attractions. The task integrates data from Wikipedia for tourist attractions and uses weather information from an API to provide a comprehensive travel plan.\n", + "## Task: Travel Itinerary Assistant with Weather and Wikipedia Integrations\n", + "\n", + "### Overview\n", + "\n", + "The Travel Itinerary Assistant helps users plan a travel itinerary that takes into account current weather conditions and local tourist attractions. By integrating data from Wikipedia for tourist attractions and using a weather API for real-time weather updates, the tool provides a comprehensive travel plan tailored to each location. The generated itinerary suggests appropriate activities based on the weather, enhancing the overall travel experience.\n", "\n", "### Task Flow\n", "\n", - "1. **Input Locations**: \n", - " - User provides a list of locations.\n", + "1. **User Input**\n", + " - User provides a list of desired travel locations.\n", + " - Each location is processed individually to gather the required data.\n", + "\n", + "2. **Weather Data Retrieval**\n", + " - Fetch current weather data for each location using a weather API.\n", + " - Extract relevant weather details, such as temperature, weather condition, and recommendations.\n", + "\n", + "3. **Tourist Attractions Lookup**\n", + " - Use Wikipedia to search for the top tourist attractions for each location.\n", + " - The query format used is: `\" tourist attractions\"`.\n", + " - Retrieve and compile a list of popular tourist spots and landmarks.\n", + "\n", + "4. **Data Evaluation and Integration**\n", + " - Combine weather data and tourist attractions into a unified list for each location.\n", + " - Format the data into a structured tuple: `(location, weather, attractions)`.\n", "\n", - "2. **Fetch Weather Data**: \n", - " - Retrieve current weather conditions for each location using the Weather integration.\n", + "5. **Itinerary Generation**\n", + " - Create a detailed travel itinerary based on:\n", + " - Current weather conditions (e.g., sunny, rainy, cloudy).\n", + " - Top tourist attractions for each location.\n", + " - Suggested activities categorized as indoor or outdoor based on weather.\n", "\n", - "3. **Fetch Tourist Attractions**: \n", - " - Use Wikipedia integration to find tourist attractions for each location by appending \"tourist attractions\" to the location name.\n", + "### Key Features\n", "\n", - "4. **Data Evaluation**: \n", - " - Combine the weather and attraction data into a list of tuples: (location, weather, attractions).\n", + "- **Multi-location Travel Planning**: Handles multiple destinations simultaneously, offering a consolidated travel plan.\n", + "- **Real-time Weather Data**: Leverages weather APIs to provide up-to-date weather conditions.\n", + "- **Tourist Attraction Discovery**: Integrates Wikipedia to find and recommend popular attractions.\n", + "- **Intelligent Itinerary Suggestions**: Suggests indoor or outdoor activities based on the weather.\n", + "- **Comprehensive Itinerary Output**: Combines weather and tourist data into a user-friendly travel plan.\n", "\n", - "5. **Generate Itinerary**: \n", - " - Create a detailed travel itinerary for each location based on:\n", - " - Current weather conditions\n", - " - Top tourist attractions\n", - " - Suggestions for outdoor or indoor activities" + "### Output\n", + "\n", + "- A detailed travel itinerary for each location\n", + "- Curated, up-to-date information gathered from weather searches\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "To recreate the notebook, a link to the Colab notebook is provided below. The notebook contains the code implementation for the task.\n", + "### 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", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)]()\n", + "### Additional Information\n", "\n", - "For more details on the task or any questions, please feel free to reach out to the author, [Julep AI](hey@julep.ai)." + "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:** [hey@julep.ai](mailto:hey@julep.ai)" ] }, { @@ -63,9 +93,10 @@ "source": [ "#### NOTE:\n", "\n", - "The uuid is generated for the agent and task, and is used to identify the agent and task in the system. Once the agent and task are created, the uuid should not be changed for simplicity.\n", - "\n", - "Changing the uuid will cause the agent and task to be treated as a new agent and task respectively. The previous agent and task will still persist in the system." + "- 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." ] }, { From 922bb6269781fef4a321dbe6d24c1d717cfe16aa Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Tue, 1 Oct 2024 18:38:38 -0400 Subject: [PATCH 4/8] fix(agents-api): Fix the temporal codec server Signed-off-by: Diwank Singh Tomer --- .../agents_api/routers/internal/router.py | 87 ++++--------------- agents-api/agents_api/web.py | 2 +- agents-api/docker-compose.yml | 6 +- 3 files changed, 22 insertions(+), 73 deletions(-) diff --git a/agents-api/agents_api/routers/internal/router.py b/agents-api/agents_api/routers/internal/router.py index aac35e664..4d930b7c8 100644 --- a/agents-api/agents_api/routers/internal/router.py +++ b/agents-api/agents_api/routers/internal/router.py @@ -1,81 +1,30 @@ -from fastapi import Request, Response, HTTPException, status -from typing import List, Iterable +from fastapi import APIRouter, Request, Response from google.protobuf import json_format -from fastapi.responses import JSONResponse -from temporalio.api.common.v1 import Payloads, Payload -from temporalio.converter import PayloadCodec -from ...worker.codec import PydanticEncodingPayloadConverter -from fastapi import APIRouter - -class CodecInstantion(PayloadCodec): - def __init__(self) -> None: - super().__init__() - self.converter = PydanticEncodingPayloadConverter() - - async def encode(self, payloads: Iterable[Payload]) -> List[Payload]: - return [ - self.converter.to_payload(p) - for p in payloads - ] +from temporalio.api.common.v1 import Payloads - async def decode(self, payloads: Iterable[Payload]) -> List[Payload]: - ret: List[Payload] = [] - for p in payloads: - payload_data = self.converter.from_payload(p) - ret.append(Payload.FromString(bytes(payload_data))) - return ret +from ...worker.codec import PydanticEncodingPayloadConverter -# Assuming Payloads and Payload are properly defined, and EncryptionCodec class is implemented router: APIRouter = APIRouter() -# codec instantiation -codec = CodecInstantion() - -# CORS middleware -async def cors_middleware(req: Request) -> Response: - origin = req.headers.get("origin") - # Set specific CORS headers for requests from "* - if origin == "*": - headers = { - "Access-Control-Allow-Origin": "*", - "Access-Control-Allow-Methods": "POST", - "Access-Control-Allow-Headers": "content-type,x-namespace", - } - return Response(status_code=200, headers=headers) - return Response(status_code=status.HTTP_400_BAD_REQUEST) # Forbidden for other origins -# Encode route -@router.post("/encode", tags=["encryption"]) -async def encode_payloads(req: Request) -> Response: - if req.headers.get("Content-Type") != "application/json": - raise HTTPException(status_code=400, detail="Invalid content type") - - payloads = json_format.Parse(await req.read(), Payloads()) - - # Apply encoding - encoded_payloads = Payloads(payloads=await codec.encode(payloads.payloads)) - print(encoded_payloads) - - response = JSONResponse(content=json_format.MessageToDict(encoded_payloads)) - print(response) - # response = await cors_middleware(response) - - return response +converter = PydanticEncodingPayloadConverter() # Decode route -@router.post("/decode", tags=["decryption"]) +@router.post("/temporal/decode", tags=["temporal"]) async def decode_payloads(req: Request)-> Response: - if req.headers.get("Content-Type") != "application/json": - raise HTTPException(status_code=400, detail="Invalid content type") - - payloads = json_format.Parse(await req.read(), Payloads()) + body = json_format.Parse(await req.body(), Payloads()) + payloads = body.payloads + + decoded_payloads = [] - # Apply decoding - decoded_payloads = Payloads(payloads=await codec.decode(payloads.payloads)) + for p in payloads: + data = converter.from_payload(p) - print(decoded_payloads) - response = JSONResponse(content=json_format.MessageToDict(decoded_payloads)) + if hasattr(data, 'model_dump'): + data = data.model_dump() - print(response) - # response = await cors_middleware(response) + decoded_payloads.append({ + "data": data, + "metadata": p.metadata + }) - return response \ No newline at end of file + return {"payloads": decoded_payloads} \ No newline at end of file diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index 65c9eefe6..99b2cbcfa 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -123,7 +123,7 @@ async def scalar_html(): app.include_router(jobs.router, dependencies=[Depends(get_api_key)]) app.include_router(docs.router, dependencies=[Depends(get_api_key)]) app.include_router(tasks.router, dependencies=[Depends(get_api_key)]) -app.include_router(internal.router, dependencies=[Depends(get_api_key)]) +app.include_router(internal.router) # TODO: CORS should be enabled only for JWT auth # diff --git a/agents-api/docker-compose.yml b/agents-api/docker-compose.yml index cc2f2b262..e086affbf 100644 --- a/agents-api/docker-compose.yml +++ b/agents-api/docker-compose.yml @@ -34,6 +34,9 @@ x--base-agents-api: &base-agents-api context: . dockerfile: Dockerfile + ports: + - "8080:8080" + develop: watch: - action: sync+restart @@ -54,9 +57,6 @@ services: - '' # Acts as a default profile. See: https://stackoverflow.com/questions/75758174/how-to-make-profile-default-for-docker-compose - single-tenant - ports: - - "8080:8080" - agents-api-multi-tenant: <<: *base-agents-api profiles: From 80439decf02835bc91ef72378a56061f40b84a7d Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Tue, 1 Oct 2024 18:46:05 -0400 Subject: [PATCH 5/8] notebooks: colan links updated --- cookbooks/01_Cookbook.ipynb | 2 +- cookbooks/02_Cookbook.ipynb | 2 +- cookbooks/03_Cookbook.ipynb | 2 +- cookbooks/04_Cookbook.ipynb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cookbooks/01_Cookbook.ipynb b/cookbooks/01_Cookbook.ipynb index a1ce59823..85cc6571c 100644 --- a/cookbooks/01_Cookbook.ipynb +++ b/cookbooks/01_Cookbook.ipynb @@ -34,7 +34,7 @@ "\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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/19GOnl_RZWUGIlrQ-a1Abw53w79XgaH61/view?usp=sharing)\n", "\n", "### Additional Information\n", "\n", diff --git a/cookbooks/02_Cookbook.ipynb b/cookbooks/02_Cookbook.ipynb index a186e789f..83e7e646d 100644 --- a/cookbooks/02_Cookbook.ipynb +++ b/cookbooks/02_Cookbook.ipynb @@ -63,7 +63,7 @@ "\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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/169hp4MOCXmhEKzKloBV_klzrxg3IoI1G/view?usp=sharing)\n", "\n", "### Additional Information\n", "\n", diff --git a/cookbooks/03_Cookbook.ipynb b/cookbooks/03_Cookbook.ipynb index a9125dfb9..8edaabd06 100644 --- a/cookbooks/03_Cookbook.ipynb +++ b/cookbooks/03_Cookbook.ipynb @@ -57,7 +57,7 @@ "\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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/14ntgAPmm2-QD3KArc5-lyM5wCMyTx5b1/view?usp=drive_link)\n", "\n", "### Additional Information\n", "\n", diff --git a/cookbooks/04_Cookbook.ipynb b/cookbooks/04_Cookbook.ipynb index fb08fb6e7..2d4a37ac8 100644 --- a/cookbooks/04_Cookbook.ipynb +++ b/cookbooks/04_Cookbook.ipynb @@ -61,7 +61,7 @@ "\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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1JLXPn-MWxA-4rVABuZ0ZvIcdh6AQVnRf?usp=sharing)\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1fYLeJN-1y2_SXVU32yk6OSQF-W25HmYb/view?usp=sharing)\n", "\n", "### Additional Information\n", "\n", From e8238b27e4aa487c49d1e71711c7424f00d2ddd4 Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Wed, 2 Oct 2024 13:38:42 -0400 Subject: [PATCH 6/8] PR Fix: incorporated the comments --- CONTRIBUTING.md | 14 +- .../agents_api/routers/internal/router.py | 18 ++- agents-api/agents_api/web.py | 2 +- ... => 01-Website_Crawler_using_Spider.ipynb} | 63 ++------- ...2-Sarcastic_News_Headline_Generator.ipynb} | 90 +++---------- ...> 03-SmartResearcher_With_WebSearch.ipynb} | 81 ++++-------- ...ipPlanner_With_Weather_And_WikiInfo.ipynb} | 125 +++++++----------- 7 files changed, 115 insertions(+), 278 deletions(-) rename cookbooks/{01_Cookbook.ipynb => 01-Website_Crawler_using_Spider.ipynb} (85%) rename cookbooks/{02_Cookbook.ipynb => 02-Sarcastic_News_Headline_Generator.ipynb} (79%) rename cookbooks/{03_Cookbook.ipynb => 03-SmartResearcher_With_WebSearch.ipynb} (79%) rename cookbooks/{04_Cookbook.ipynb => 04-TripPlanner_With_Weather_And_WikiInfo.ipynb} (72%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e9620ffb..e60c31973 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,7 +68,7 @@ Run the project in single-tenant mode: docker compose --env-file .env --profile temporal-ui --profile single-tenant --profile embedding-cpu --profile self-hosted-db up --force-recreate --build --watch ``` -> **Note:** In single-tenant mode, you can interact with the SDK directly without the need fopr the API KEY. +> **Note:** In single-tenant mode, you can interact with the SDK directly without the need for the API KEY. ###### Multi-Tenant Mode Run the project in multi-tenant mode: @@ -77,20 +77,16 @@ Run the project in multi-tenant mode: docker compose --env-file .env --profile temporal-ui --profile multi-tenant --profile embedding-cpu --profile self-hosted-db up --force-recreate --build --watch ``` -> **Note:** In multi-tenant mode, you need to generate a JWT token that act as an API KEY to interact with the SDK in the local setup. +> **Note:** In multi-tenant mode, you need to generate a JWT token locally that act as an API KEY to interact with the SDK. ##### 6. Generate a JWT Token (Only for Multi-Tenant Mode) -To generate a JWT token, `jwt-cli` is required. Install it using the following command: +To generate a JWT token, `jwt-cli` is required. Kindly install the same before proceeding with the next steps. -```bash -npm install -g jwt-cli -``` - -Use the following command and replace `{JWT_SHARED_KEY}` with the corresponding key from your `.env` file to generate a JWT token: +Use the following command and replace `JWT_SHARED_KEY` with the corresponding key from your `.env` file to generate a JWT token: ```bash -jwt encode --secret {JWT_SHARED_KEY} --alg HS512 --exp=$(date -j -v +10d +%s) --sub '00000000-0000-0000-0000-000000000000' '{}' +jwt encode --secret JWT_SHARED_KEY --alg HS512 --exp=$(date -j -v +10d +%s) --sub '00000000-0000-0000-0000-000000000000' '{}' ``` This command generates a JWT token that will be valid for 10 days. diff --git a/agents-api/agents_api/routers/internal/router.py b/agents-api/agents_api/routers/internal/router.py index 4d930b7c8..3293f2463 100644 --- a/agents-api/agents_api/routers/internal/router.py +++ b/agents-api/agents_api/routers/internal/router.py @@ -6,25 +6,23 @@ router: APIRouter = APIRouter() -converter = PydanticEncodingPayloadConverter() +converter = PydanticEncodingPayloadConverter() + # Decode route @router.post("/temporal/decode", tags=["temporal"]) -async def decode_payloads(req: Request)-> Response: +async def decode_payloads(req: Request) -> dict: body = json_format.Parse(await req.body(), Payloads()) payloads = body.payloads - + decoded_payloads = [] for p in payloads: data = converter.from_payload(p) - if hasattr(data, 'model_dump'): + if hasattr(data, "model_dump"): data = data.model_dump() - decoded_payloads.append({ - "data": data, - "metadata": p.metadata - }) - - return {"payloads": decoded_payloads} \ No newline at end of file + decoded_payloads.append({"data": data, "metadata": p.metadata}) + + return {"payloads": decoded_payloads} diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index 99b2cbcfa..048887f68 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -24,11 +24,11 @@ from .routers import ( agents, docs, + internal, jobs, sessions, tasks, users, - internal, ) if not sentry_dsn: diff --git a/cookbooks/01_Cookbook.ipynb b/cookbooks/01-Website_Crawler_using_Spider.ipynb similarity index 85% rename from cookbooks/01_Cookbook.ipynb rename to cookbooks/01-Website_Crawler_using_Spider.ipynb index 85cc6571c..251e699f4 100644 --- a/cookbooks/01_Cookbook.ipynb +++ b/cookbooks/01-Website_Crawler_using_Spider.ipynb @@ -34,14 +34,16 @@ "\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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/19GOnl_RZWUGIlrQ-a1Abw53w79XgaH61/view?usp=sharing)\n", + "\n", + " \"Open\n", + "\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:** [hey@julep.ai](mailto:hey@julep.ai)" + "**Contact:** [hey@julep.ai](mailto:hey@julep.ai) or Discord" ] }, { @@ -146,44 +148,6 @@ ")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Listing all the agents\n", - "\n", - "We list the agents to see what agents are available." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Listing all agents available in the account\n", - "get_agents = client.agents.list()\n", - "get_agents.items" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We get the current agent ID from the list of agents." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# get the agent id\n", - "agent_id = get_agents.items[0].id\n", - "agent_id" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -260,17 +224,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#listing all tasks for a given agent\n", - "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", - "get_tasks.items " - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -316,7 +269,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Streaming execution steps of the defined Task." + "Retrieves and lists all the steps of a defined task that have been executed up to that point in time. Unlike streaming, this function does not continuously monitor the execution; it only provides a snapshot of the steps completed so far without displaying real-time updates as the task progresses." ] }, { @@ -325,14 +278,14 @@ "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.stream(execution_id=execution.id)" + "client.executions.transitions.list(execution_id=execution.id).items" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Lisitng all the executions states of the task." + "Continuously monitor and stream the steps of a defined task. It retrieves and displays the transitions or execution steps of the task identified by execution.id in real-time, showing each step sequentially until the task is either completed or an error causes it to terminate." ] }, { @@ -341,7 +294,7 @@ "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.list(execution_id=execution.id).items" + "client.executions.transitions.stream(execution_id=execution.id)" ] } ], diff --git a/cookbooks/02_Cookbook.ipynb b/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb similarity index 79% rename from cookbooks/02_Cookbook.ipynb rename to cookbooks/02-Sarcastic_News_Headline_Generator.ipynb index 83e7e646d..618d95df9 100644 --- a/cookbooks/02_Cookbook.ipynb +++ b/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb @@ -37,20 +37,17 @@ "- Combines real-world information with humorous twists for engaging headlines.\n", "- Adaptable to various topics, allowing for diverse and creative outputs.\n", "\n", - "```\n", - "\n", - "\n", - " +----------+ +------------+ +------------+ +-----------+\n", - " | User | | Brave | | Agent | | Sarcastic |\n", - " | Input | --> | Search | --> | Processing | --> | Headline |\n", - " | (Topic) | | | | | | Output |\n", - " +----------+ +------------+ +------------+ +-----------+\n", - " | | | |\n", - " | | | |\n", - " v v v v\n", - " \"politics\" Find funny Generate witty \"Area Man Still\n", - " content headline Believes in \n", - " Democracy\"\n", + "```plaintext\n", + "+----------+ +------------+ +------------+ +-----------+\n", + "| User | | Brave | | Agent | | Sarcastic |\n", + "| Input | --> | Search | --> | Processing | --> | Headline |\n", + "| (Topic) | | | | | | Output |\n", + "+----------+ +------------+ +------------+ +-----------+\n", + " | | | |\n", + " | | | |\n", + " v v v v\n", + " \"politics\" Find funny Generate witty \"Area Man Still\n", + " content headline Believes in Democracy\"\n", "\n", "```" ] @@ -59,18 +56,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Implementation\n", + "## 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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/169hp4MOCXmhEKzKloBV_klzrxg3IoI1G/view?usp=sharing)\n", + "\n", + " \"Open\n", + "\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:** [hey@julep.ai](mailto:hey@julep.ai)" + "**Contact:** [hey@julep.ai](mailto:hey@julep.ai) or Discord" ] }, { @@ -176,44 +175,6 @@ ")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Listing all the agents\n", - "\n", - "We list the agents to see what agents are available." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Listing all agents available in the account\n", - "get_agents = client.agents.list()\n", - "get_agents.items" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We get the current agent ID from the list of agents." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# get the agent id\n", - "agent_id = get_agents.items[0].id\n", - "agent_id" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -298,17 +259,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#listing all tasks for a given agent\n", - "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", - "get_tasks.items " - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -356,7 +306,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Streaming execution steps of the defined Task." + "Retrieves and lists all the steps of a defined task that have been executed up to that point in time. Unlike streaming, this function does not continuously monitor the execution; it only provides a snapshot of the steps completed so far without displaying real-time updates as the task progresses." ] }, { @@ -365,14 +315,14 @@ "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.stream(execution_id=execution.id)" + "client.executions.transitions.list(execution_id=execution.id).items" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Lisitng all the executions states of the task." + "Continuously monitor and stream the steps of a defined task. It retrieves and displays the transitions or execution steps of the task identified by execution.id in real-time, showing each step sequentially until the task is either completed or an error causes it to terminate." ] }, { @@ -381,7 +331,7 @@ "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.list(execution_id=execution.id).items" + "client.executions.transitions.stream(execution_id=execution.id)" ] } ], diff --git a/cookbooks/03_Cookbook.ipynb b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb similarity index 79% rename from cookbooks/03_Cookbook.ipynb rename to cookbooks/03-SmartResearcher_With_WebSearch.ipynb index 8edaabd06..b32d0f95b 100644 --- a/cookbooks/03_Cookbook.ipynb +++ b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb @@ -46,7 +46,23 @@ "- Comprehensive list of relevant Wikipedia keywords for each input topic\n", "- Curated, up-to-date information gathered from web searches\n", "\n", - "This workflow provides a robust, efficient approach to in-depth topic exploration, combining the power of web search, AI analysis, and parallel processing.\n" + "This workflow provides a robust, efficient approach to in-depth topic exploration, combining the power of web search, AI analysis, and parallel processing.\n", + "\n", + "```plaintext\n", + "\n", + "+----------------+ +--------------------------+ +-----------------+ +------------------------+ +-------------------------+\n", + "| User Input | | Web Search & Information | | Intelligent | | Parallel Processing | | Output Stage |\n", + "|(List of Topics)| --> | Gathering (BraveWeb) | --> | Analysis | --> | (Concurrent Execution) | --> | Summarized Research |\n", + "| | | | | | | | | (Final Report) |\n", + "+----------------+ +--------------------------+ +-----------------+ +------------------------+ +-------------------------+\n", + " | | | | |\n", + " | | | | |\n", + " v v v v v\n", + " Topic 1, Topic 2, ... Retrieve HTML snippets Extract Wikipedia Process multiple Compile summary and \n", + " Each topic processed from search results keywords from HTML topics concurrently present most relevant \n", + " individually. for each topic. snippets, analyze for faster results. findings per topic.\n", + " relevance.\n", + "```\n" ] }, { @@ -57,14 +73,16 @@ "\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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/14ntgAPmm2-QD3KArc5-lyM5wCMyTx5b1/view?usp=drive_link)\n", + "\n", + " \"Open\n", + "\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:** [hey@julep.ai](mailto:hey@julep.ai)" + "**Contact:** [hey@julep.ai](mailto:hey@julep.ai) or Discord" ] }, { @@ -170,44 +188,6 @@ ")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Listing all the agents\n", - "\n", - "We list the agents to see what agents are available." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Listing all agents available in the account\n", - "get_agents = client.agents.list()\n", - "get_agents.items" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We get the current agent ID from the list of agents." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# get the agent id\n", - "agent_id = get_agents.items[0].id\n", - "agent_id" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -309,17 +289,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#listing all tasks for a given agent\n", - "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", - "get_tasks.items " - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -375,7 +344,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Streaming execution steps of the defined Task." + "Retrieves and lists all the steps of a defined task that have been executed up to that point in time. Unlike streaming, this function does not continuously monitor the execution; it only provides a snapshot of the steps completed so far without displaying real-time updates as the task progresses." ] }, { @@ -384,14 +353,14 @@ "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.stream(execution_id=execution.id)" + "client.executions.transitions.list(execution_id=execution.id).items" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Listing the execution states." + "Continuously monitor and stream the steps of a defined task. It retrieves and displays the transitions or execution steps of the task identified by execution.id in real-time, showing each step sequentially until the task is either completed or an error causes it to terminate." ] }, { @@ -400,7 +369,7 @@ "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.list(execution_id=execution.id).items" + "client.executions.transitions.stream(execution_id=execution.id)" ] } ], diff --git a/cookbooks/04_Cookbook.ipynb b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb similarity index 72% rename from cookbooks/04_Cookbook.ipynb rename to cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb index 2d4a37ac8..cfc95f3c2 100644 --- a/cookbooks/04_Cookbook.ipynb +++ b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "
\n", + "div align=\"center\">\n", " \"julep\"\n", "
\n", "\n", @@ -50,25 +50,46 @@ "### Output\n", "\n", "- A detailed travel itinerary for each location\n", - "- Curated, up-to-date information gathered from weather searches\n" + "- Curated, up-to-date information gathered from weather searches and Wikipedia\n", + "\n", + "```plaintext\n", + "\n", + "+----------------+ +--------------------------+ +--------------------------+ +------------------------------+ +-------------------------+\n", + "| User Input | | Weather Data Retrieval | | Tourist Attractions | | Data Evaluation & Integration| | Itinerary Generation |\n", + "| (List of | --> | (Weather API) | --> | Lookup (Wikipedia) | --> | (Combine Weather & | --> | (Generate Suggested |\n", + "| Locations) | | | | | | Attractions Data) | | Activities/Plan) |\n", + "+----------------+ +--------------------------+ +--------------------------+ +------------------------------+ +-------------------------+\n", + " | | | | |\n", + " | | | | |\n", + " v v v v v\n", + "Location 1, Location 2, ... Fetch weather for each Search Wikipedia for Combine weather data and Create itinerary with\n", + "Each location processed location individually, \" tourist tourist attractions into suggested activities\n", + "individually for extracting temp., attractions\", retrieve a structured tuple: based on weather and\n", + "weather data. conditions, & top spots. (location, weather, attractions.\n", + " recommendations. attractions).\n", + "```\n", + "\n", + "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Implementation\n", + "## 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", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://drive.google.com/file/d/1fYLeJN-1y2_SXVU32yk6OSQF-W25HmYb/view?usp=sharing)\n", + "\n", + " \"Open\n", + "\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:** [hey@julep.ai](mailto:hey@julep.ai)" + "**Contact:** [hey@julep.ai](mailto:hey@julep.ai) or Discord" ] }, { @@ -173,44 +194,6 @@ ")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Listing all the agents\n", - "\n", - "We list the agents to see what agents are available." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Listing all agents available in the account\n", - "get_agents = client.agents.list()\n", - "get_agents.items" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We get the current agent ID from the list of agents." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# get the agent id\n", - "agent_id = get_agents.items[0].id\n", - "agent_id" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -247,7 +230,7 @@ "metadata": {}, "outputs": [], "source": [ - "task_def= yaml.safe_load(\"\"\"\n", + "task_def = yaml.safe_load(\"\"\"\n", "name: Tourist Plan With Weather And Attractions\n", "\n", "input_schema:\n", @@ -285,27 +268,26 @@ " arguments:\n", " query: \"_ + ' tourist attractions'\"\n", "\n", - "- over: _\n", - " evaluate:\n", - " zipped: \"list(zip(inputs[0].locations, outputs[0], outputs[1]))\" # [(location, weather, attractions)]\n", + "- evaluate:\n", + " zipped: \"list(zip(inputs[0].locations, [output['result'] for output in outputs[0]], [output['documents'][0]['page_content'] for output in outputs[1]]))\" # [(location, weather, attractions)]\n", "\n", - "- over: _\n", - " parallelism: 1\n", + "\n", + "- over: _['zipped']\n", + " parallelism: 3\n", " map:\n", " prompt:\n", - " - role: system\n", - " content: >-\n", - " You are a travel assistant. Your task is to create a detailed itinerary for visiting tourist attractions in \"{{_[0]}}\" based on the weather conditions and the top tourist attractions provided.\n", - " \n", - " Current weather condition at \"{{_[0]}}\":\n", - " \"{{_[1]}}\"\n", + " - role: system\n", + " content: >-\n", + " You are a travel assistant. Your task is to create a detailed itinerary for visiting tourist attractions in \"{{_[0]}}\" based on the weather conditions and the top tourist attractions provided.\n", + " \n", + " Current weather condition at \"{{_[0]}}\":\n", + " \"{{_[1]}}\"\n", "\n", - " Top tourist attractions in \"{{_[0]}}\":\n", - " \"{{_[2]}}\"\n", + " Top tourist attractions in \"{{_[0]}}\":\n", + " \"{{_[2]}}\"\n", "\n", - " Suggest outdoor or indoor activities based on the above information.\n", + " Suggest outdoor or indoor activities based on the above information.\n", " unwrap: true\n", - " \n", "\"\"\")" ] }, @@ -330,17 +312,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#listing all tasks for a given agent\n", - "get_tasks = client.tasks.list(agent_id=AGENT_UUID)\n", - "get_tasks.items " - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -366,7 +337,7 @@ "execution = client.executions.create(\n", " task_id=task.id,\n", " input={\n", - " \"locations\": [\"New York\"]\n", + " \"locations\": [\"New York\", \"London\", \"Paris\", \"Tokyo\", \"Sydney\"]\n", " }\n", ")" ] @@ -396,32 +367,32 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Streaming execution steps of the defined Task." + "Retrieves and lists all the steps of a defined task that have been executed up to that point in time. Unlike streaming, this function does not continuously monitor the execution; it only provides a snapshot of the steps completed so far without displaying real-time updates as the task progresses." ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.stream(execution_id=execution.id)" + "client.executions.transitions.list(execution_id=execution.id).items" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Listing the execution states." + "Continuously monitor and stream the steps of a defined task. It retrieves and displays the transitions or execution steps of the task identified by execution.id in real-time, showing each step sequentially until the task is either completed or an error causes it to terminate." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ - "client.executions.transitions.list(execution_id=execution.id).items" + "client.executions.transitions.stream(execution_id=execution.id)" ] } ], From 96e17f9c732a8e2e345aa8b0f45112688f4feb75 Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Wed, 2 Oct 2024 14:40:50 -0400 Subject: [PATCH 7/8] cookbooks: Added Readme and noteboook links updated --- .../01-Website_Crawler_using_Spider.ipynb | 4 +-- ...02-Sarcastic_News_Headline_Generator.ipynb | 2 +- .../03-SmartResearcher_With_WebSearch.ipynb | 2 +- cookbooks/README.md | 29 +++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 cookbooks/README.md diff --git a/cookbooks/01-Website_Crawler_using_Spider.ipynb b/cookbooks/01-Website_Crawler_using_Spider.ipynb index 251e699f4..36a77d525 100644 --- a/cookbooks/01-Website_Crawler_using_Spider.ipynb +++ b/cookbooks/01-Website_Crawler_using_Spider.ipynb @@ -30,11 +30,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Implementation\n", + "## 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", - "\n", + "\n", " \"Open\n", "\n", "\n", diff --git a/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb b/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb index 618d95df9..fded810a1 100644 --- a/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb +++ b/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb @@ -60,7 +60,7 @@ "\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", - "\n", + "\n", " \"Open\n", "\n", "\n", diff --git a/cookbooks/03-SmartResearcher_With_WebSearch.ipynb b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb index b32d0f95b..50f9c7268 100644 --- a/cookbooks/03-SmartResearcher_With_WebSearch.ipynb +++ b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb @@ -73,7 +73,7 @@ "\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", - "\n", + "\n", " \"Open\n", "\n", "\n", diff --git a/cookbooks/README.md b/cookbooks/README.md new file mode 100644 index 000000000..84774675f --- /dev/null +++ b/cookbooks/README.md @@ -0,0 +1,29 @@ +
+ julep +
+ +# Julep AI - Notebook Overview + +Welcome to the **Julep AI Notebook Collection**! This directory contains a set of Jupyter notebooks designed for a variety of AI and automation tasks. + +Each notebook explores a unique use case, ranging from web crawling to running complex workflows using AI Agents. + +Below is a quick overview of the notebooks, their purpose, and a link to run each of them on Google Colab. + +| **Notebook Name** | **Colab Link** | **Description** | +|------------------------------------------------- |---------------------------------------------------------------------------- |--------------------------------------------------------------------| +| `01-Website_Crawler_using_Spider.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/01-Website_Crawler_using_Spider.ipynb) | Implements a web crawler using a spider to extract website content. | +| `02-Sarcastic_News_Headline_Generator.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb) | Generates sarcastic news headlines using a Brave Search Tool. | +| `03-SmartResearcher_With_WebSearch.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb) | Searches and aggregates web information for research purposes using Brave Search. | +| `04-TripPlanner_With_Weather_And_WikiInfo.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb) | Plans trips using weather data and Wikipedia information. | + +### Additional Information + +For more details about the task or if you have any questions, please don't hesitate to contact the author: + +**Author:** Julep AI +**Contact:** [hey@julep.ai](mailto:hey@julep.ai) or Discord + +--- + +If you have feedback or would like to contribute to the notebooks, feel free to open an issue(s) in the [repository](https://github.com/julep-ai/julep). From a1ad58e6c8b460962b4b76ee428f9e7934f1be25 Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Wed, 2 Oct 2024 14:49:03 -0400 Subject: [PATCH 8/8] cookbooks: Added Readme and noteboook links updated --- cookbooks/03-SmartResearcher_With_WebSearch.ipynb | 2 +- cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb | 2 +- cookbooks/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbooks/03-SmartResearcher_With_WebSearch.ipynb b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb index 50f9c7268..c01b54652 100644 --- a/cookbooks/03-SmartResearcher_With_WebSearch.ipynb +++ b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb @@ -73,7 +73,7 @@ "\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", - "\n", + "\n", " \"Open\n", "\n", "\n", diff --git a/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb index cfc95f3c2..d7fc39840 100644 --- a/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb +++ b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb @@ -80,7 +80,7 @@ "\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", - "\n", + "\n", " \"Open\n", "\n", "\n", diff --git a/cookbooks/README.md b/cookbooks/README.md index 84774675f..2b89ca22a 100644 --- a/cookbooks/README.md +++ b/cookbooks/README.md @@ -14,7 +14,7 @@ Below is a quick overview of the notebooks, their purpose, and a link to run eac |------------------------------------------------- |---------------------------------------------------------------------------- |--------------------------------------------------------------------| | `01-Website_Crawler_using_Spider.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/01-Website_Crawler_using_Spider.ipynb) | Implements a web crawler using a spider to extract website content. | | `02-Sarcastic_News_Headline_Generator.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb) | Generates sarcastic news headlines using a Brave Search Tool. | -| `03-SmartResearcher_With_WebSearch.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb) | Searches and aggregates web information for research purposes using Brave Search. | +| `03-SmartResearcher_With_WebSearch.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/03-SmartResearcher_With_WebSearch.ipynb) | Searches and aggregates web information for research purposes using Brave Search. | | `04-TripPlanner_With_Weather_And_WikiInfo.ipynb` | [Colab Link](https://colab.research.google.com/github/julep-ai/julep/blob/dev/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb) | Plans trips using weather data and Wikipedia information. | ### Additional Information