llama-index-tools-azure-code-interpreter


Namellama-index-tools-azure-code-interpreter JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
Summaryllama-index tools azure dynamic sessions integration for code interpreter
upload_time2024-08-22 07:24:33
maintainerajhofmann
docs_urlNone
authorYour Name
requires_python<4.0,>=3.8.1
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Azure Code Interpreter Tool

This tool leverages Azure Dynamic Sessions Pool to enable an Agent to run generated Python code in a secure environment with very low latency.

In order to utilize the tool, you will need to have the Session Pool management endpoint first. [Learn more](https://aka.ms/aca/sessions)

## Prerequisites

- Make sure to create a Session Pool and note down the `poolManagementEndpoint`.

- In order to have the code execution right, the correct role needs to be assigned to the current user agent. Be sure to assign `Session Pool Executor` role to the correct user agent's identity (e.g. User Email, Service Principal, Managed Identity, etc.) in Session Pool's access control panel through the Portal or CLI. [Learn more](https://aka.ms/aca/sessions)

## Usage

A more detailed sample is located in a Jupyter notebook [here](https://github.com/run-llama/llama_index/tree/main/docs/docs/examples/tools/azure_code_interpreter.ipynb)

Here's an example usage of the `AzureCodeInterpreterToolSpec`.

1. First, install the Azure Dynamic Sessions package using `pip`:

```
pip install llama-index-tools-azure-code-interpreter
```

2. Create a file named `.env` in the same directory as your script with the following content:

```
AZURE_POOL_MANAGEMENT_ENDPOINT=<poolManagementEndpoint>
```

3. Next, set up the Dynamic Sessions tool and a LLM agent:

```python
from llama_index.tools.azure_code_interpreter import (
    AzureCodeInterpreterToolSpec,
)
from llama_index.core.agent import ReActAgent
from llama_index.llms.azure_openai import AzureOpenAI

llm = AzureOpenAI(
    model="gpt-35-turbo",
    deployment_name="gpt-35-deploy",
    api_key=api_key,
    azure_endpoint=azure_endpoint,
    api_version=api_version,
)

code_interpreter_spec = AzureCodeInterpreterToolSpec(
    pool_management_endpoint=os.getenv("AZURE_POOL_MANAGEMENT_ENDPOINT")
)

agent = ReActAgent.from_tools(
    code_interpreter_spec.to_tool_list(), llm=llm, verbose=True
)
```

4. Use the tool as you need:

```python
print(agent.chat("Tell me the current time in Seattle."))

"""
Sample Return:
Thought: To provide the current time in Seattle, I need to calculate it based on the current UTC time and adjust for Seattle's time zone, which is Pacific Daylight Time (PDT) during daylight saving time and Pacific Standard Time (PST) outside of daylight saving time. PDT is UTC-7, and PST is UTC-8. I can use the code interpreter tool to get the current UTC time and adjust it accordingly.
Action: code_interpreter
Action Input: {'python_code': "from datetime import datetime, timedelta; import pytz; utc_now = datetime.now(pytz.utc); seattle_time = utc_now.astimezone(pytz.timezone('America/Los_Angeles')); seattle_time.strftime('%Y-%m-%d %H:%M:%S %Z%z')"}
Observation: {'$id': '1', 'status': 'Success', 'stdout': '', 'stderr': '', 'result': '2024-05-04 13:54:09 PDT-0700', 'executionTimeInMilliseconds': 120}
Thought: I can answer without using any more tools. I'll use the user's language to answer.
Answer: The current time in Seattle is 2024-05-04 13:54:09 PDT.
The current time in Seattle is 2024-05-04 13:54:09 PDT.
"""

print(dynamic_session_tool.code_interpreter("1+1"))

"""
Sample Return:
{'$id': '1', 'status': 'Success', 'stdout': '', 'stderr': '', 'result': 2, 'executionTimeInMilliseconds': 11}
"""
```

## Included Tools

The `AzureCodeInterpreterToolSpec` provides the following tools to the agent:

`code_interpreter`: (Available to developer and LLM Agent in tool spec) Send a Python code to be executed in Azure Container Apps Dynamic Sessions and return the output in a JSON format.

`list_files`: (Available to developer and LLM Agent in tool spec) List the files available in a Session under the path `/mnt/data`.

`upload_file`: (Available to developer) Upload a file or a stream of data into a Session under the path `/mnt/data`.

`download_file`: (Available to developer) Download a file by its path relative to the path `/mnt/data` to the tool's hosting agent.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-tools-azure-code-interpreter",
    "maintainer": "ajhofmann",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "you@example.com",
    "download_url": "https://files.pythonhosted.org/packages/73/64/9f19a43e9726f640b1db8c617d12a94418a423ead53de48e4602de25b6a5/llama_index_tools_azure_code_interpreter-0.3.0.tar.gz",
    "platform": null,
    "description": "# Azure Code Interpreter Tool\n\nThis tool leverages Azure Dynamic Sessions Pool to enable an Agent to run generated Python code in a secure environment with very low latency.\n\nIn order to utilize the tool, you will need to have the Session Pool management endpoint first. [Learn more](https://aka.ms/aca/sessions)\n\n## Prerequisites\n\n- Make sure to create a Session Pool and note down the `poolManagementEndpoint`.\n\n- In order to have the code execution right, the correct role needs to be assigned to the current user agent. Be sure to assign `Session Pool Executor` role to the correct user agent's identity (e.g. User Email, Service Principal, Managed Identity, etc.) in Session Pool's access control panel through the Portal or CLI. [Learn more](https://aka.ms/aca/sessions)\n\n## Usage\n\nA more detailed sample is located in a Jupyter notebook [here](https://github.com/run-llama/llama_index/tree/main/docs/docs/examples/tools/azure_code_interpreter.ipynb)\n\nHere's an example usage of the `AzureCodeInterpreterToolSpec`.\n\n1. First, install the Azure Dynamic Sessions package using `pip`:\n\n```\npip install llama-index-tools-azure-code-interpreter\n```\n\n2. Create a file named `.env` in the same directory as your script with the following content:\n\n```\nAZURE_POOL_MANAGEMENT_ENDPOINT=<poolManagementEndpoint>\n```\n\n3. Next, set up the Dynamic Sessions tool and a LLM agent:\n\n```python\nfrom llama_index.tools.azure_code_interpreter import (\n    AzureCodeInterpreterToolSpec,\n)\nfrom llama_index.core.agent import ReActAgent\nfrom llama_index.llms.azure_openai import AzureOpenAI\n\nllm = AzureOpenAI(\n    model=\"gpt-35-turbo\",\n    deployment_name=\"gpt-35-deploy\",\n    api_key=api_key,\n    azure_endpoint=azure_endpoint,\n    api_version=api_version,\n)\n\ncode_interpreter_spec = AzureCodeInterpreterToolSpec(\n    pool_management_endpoint=os.getenv(\"AZURE_POOL_MANAGEMENT_ENDPOINT\")\n)\n\nagent = ReActAgent.from_tools(\n    code_interpreter_spec.to_tool_list(), llm=llm, verbose=True\n)\n```\n\n4. Use the tool as you need:\n\n```python\nprint(agent.chat(\"Tell me the current time in Seattle.\"))\n\n\"\"\"\nSample Return:\nThought: To provide the current time in Seattle, I need to calculate it based on the current UTC time and adjust for Seattle's time zone, which is Pacific Daylight Time (PDT) during daylight saving time and Pacific Standard Time (PST) outside of daylight saving time. PDT is UTC-7, and PST is UTC-8. I can use the code interpreter tool to get the current UTC time and adjust it accordingly.\nAction: code_interpreter\nAction Input: {'python_code': \"from datetime import datetime, timedelta; import pytz; utc_now = datetime.now(pytz.utc); seattle_time = utc_now.astimezone(pytz.timezone('America/Los_Angeles')); seattle_time.strftime('%Y-%m-%d %H:%M:%S %Z%z')\"}\nObservation: {'$id': '1', 'status': 'Success', 'stdout': '', 'stderr': '', 'result': '2024-05-04 13:54:09 PDT-0700', 'executionTimeInMilliseconds': 120}\nThought: I can answer without using any more tools. I'll use the user's language to answer.\nAnswer: The current time in Seattle is 2024-05-04 13:54:09 PDT.\nThe current time in Seattle is 2024-05-04 13:54:09 PDT.\n\"\"\"\n\nprint(dynamic_session_tool.code_interpreter(\"1+1\"))\n\n\"\"\"\nSample Return:\n{'$id': '1', 'status': 'Success', 'stdout': '', 'stderr': '', 'result': 2, 'executionTimeInMilliseconds': 11}\n\"\"\"\n```\n\n## Included Tools\n\nThe `AzureCodeInterpreterToolSpec` provides the following tools to the agent:\n\n`code_interpreter`: (Available to developer and LLM Agent in tool spec) Send a Python code to be executed in Azure Container Apps Dynamic Sessions and return the output in a JSON format.\n\n`list_files`: (Available to developer and LLM Agent in tool spec) List the files available in a Session under the path `/mnt/data`.\n\n`upload_file`: (Available to developer) Upload a file or a stream of data into a Session under the path `/mnt/data`.\n\n`download_file`: (Available to developer) Download a file by its path relative to the path `/mnt/data` to the tool's hosting agent.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "llama-index tools azure dynamic sessions integration for code interpreter",
    "version": "0.3.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e914b60c9c1ed06eee336a29a67ebd5bacc1d5a47e19c12c3e40298c345937a",
                "md5": "28e6f843594c564ed998f43ae2c7ca4c",
                "sha256": "05ed9b5ca60f9c8dec636f91c2f89618f3ff963d719d6a1d8b22fdcb8c675aba"
            },
            "downloads": -1,
            "filename": "llama_index_tools_azure_code_interpreter-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "28e6f843594c564ed998f43ae2c7ca4c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8.1",
            "size": 6529,
            "upload_time": "2024-08-22T07:24:31",
            "upload_time_iso_8601": "2024-08-22T07:24:31.736240Z",
            "url": "https://files.pythonhosted.org/packages/8e/91/4b60c9c1ed06eee336a29a67ebd5bacc1d5a47e19c12c3e40298c345937a/llama_index_tools_azure_code_interpreter-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73649f19a43e9726f640b1db8c617d12a94418a423ead53de48e4602de25b6a5",
                "md5": "91a398b4f426e3de1fa42f07205be319",
                "sha256": "ecde01976eb639ab0196401867a08ca80ec19bb5d0c1bd371e566b77e362fdf8"
            },
            "downloads": -1,
            "filename": "llama_index_tools_azure_code_interpreter-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "91a398b4f426e3de1fa42f07205be319",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8.1",
            "size": 6047,
            "upload_time": "2024-08-22T07:24:33",
            "upload_time_iso_8601": "2024-08-22T07:24:33.021431Z",
            "url": "https://files.pythonhosted.org/packages/73/64/9f19a43e9726f640b1db8c617d12a94418a423ead53de48e4602de25b6a5/llama_index_tools_azure_code_interpreter-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-22 07:24:33",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-tools-azure-code-interpreter"
}
        
Elapsed time: 0.32314s