Skip to content

Commit c3dc877

Browse files
committed
Initial commit.
0 parents  commit c3dc877

File tree

10 files changed

+331
-0
lines changed

10 files changed

+331
-0
lines changed

.gitignore

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#########################################
2+
# Editor temporary/working/backup files #
3+
.#*
4+
*\#*\#
5+
[#]*#
6+
*~
7+
*$
8+
*.bak
9+
*flymake*
10+
*.iml
11+
*.kdev4
12+
*.log
13+
*.swp
14+
*.pdb
15+
*.zip
16+
.project
17+
.pydevproject
18+
.settings
19+
.idea
20+
.vagrant
21+
.noseids
22+
.ipynb_checkpoints
23+
.tags
24+
.cache/
25+
.vscode/
26+
27+
# Compiled source #
28+
###################
29+
*.a
30+
*.com
31+
*.class
32+
*.dll
33+
*.exe
34+
*.pxi
35+
*.o
36+
*.py[ocd]
37+
*.so
38+
.build_cache_dir
39+
.mesonpy-native-file.ini
40+
MANIFEST
41+
compile_commands.json
42+
debug
43+
.debug
44+
45+
# Python files #
46+
################
47+
# setup.py working directory
48+
build
49+
# sphinx build directory
50+
doc/_build
51+
# setup.py dist directory
52+
dist
53+
# Egg metadata
54+
*.egg-info
55+
.eggs
56+
.pypirc
57+
# type checkers
58+
pandas/py.typed
59+
60+
# pyenv
61+
.python-version
62+
63+
# tox testing tool
64+
.tox
65+
# rope
66+
.ropeproject
67+
# wheel files
68+
*.whl
69+
**/wheelhouse/*
70+
pip-wheel-metadata
71+
# coverage
72+
.coverage
73+
coverage.xml
74+
coverage_html_report
75+
.mypy_cache
76+
*.pytest_cache
77+
.ruff_cache
78+
# hypothesis test database
79+
.hypothesis/
80+
__pycache__
81+
# pytest-monkeytype
82+
monkeytype.sqlite3
83+
# meson editable install folder
84+
.mesonpy
85+
86+
87+
# OS generated files #
88+
######################
89+
.directory
90+
.gdb_history
91+
.DS_Store
92+
ehthumbs.db
93+
Icon?
94+
Thumbs.db
95+
96+
# Data files #
97+
##############
98+
*.dta
99+
*.xpt
100+
*.h5
101+
pandas/io/*.dat
102+
pandas/io/*.json
103+
scikits
104+
105+
# Generated Sources #
106+
#####################
107+
!skts.c
108+
*.c
109+
*.cpp
110+
!pandas/_libs/src/**/*.c
111+
!pandas/_libs/src/**/*.h
112+
!pandas/_libs/include/**/*.h
113+
114+
# Unit / Performance Testing #
115+
##############################
116+
asv_bench/env/
117+
asv_bench/html/
118+
asv_bench/results/
119+
asv_bench/pandas/
120+
test-data.xml
121+
122+
# Documentation generated files #
123+
#################################
124+
doc/source/generated
125+
doc/source/user_guide/styled.xlsx
126+
doc/source/reference/api
127+
doc/source/_static/*.html
128+
doc/source/vbench
129+
doc/source/vbench.rst
130+
doc/source/index.rst
131+
doc/build/html/index.html
132+
# Windows specific leftover:
133+
doc/tmp.sv
134+
env/
135+
doc/source/savefig/
136+
137+
# Interactive terminal generated files #
138+
########################################
139+
.jupyterlite.doit.db

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Unstruk Data Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Agent Tools for Graphlit Platform
2+
3+
## Overview
4+
5+
TODO
6+
7+
## Prerequisites
8+
9+
Before you begin, ensure you have the following:
10+
11+
- Python 3.x installed on your system.
12+
- An active account on the [Graphlit Platform](https://portal.graphlit.dev) with access to the API settings dashboard.
13+
14+
## Installation
15+
16+
To install the Graphlit Agent Tools, use pip:
17+
18+
```bash
19+
pip install graphlit-tools
20+
```
21+
22+
## Configuration
23+
24+
The Graphlit Client supports environment variables to be set for authentication and configuration:
25+
26+
- `GRAPHLIT_ENVIRONMENT_ID`: Your environment ID.
27+
- `GRAPHLIT_ORGANIZATION_ID`: Your organization ID.
28+
- `GRAPHLIT_JWT_SECRET`: Your JWT secret for signing the JWT token.
29+
30+
Alternately, you can pass these values with the constructor of the Graphlit client.
31+
32+
You can find these values in the API settings dashboard on the [Graphlit Platform](https://portal.graphlit.dev).
33+
34+
### Setting Environment Variables
35+
36+
To set these environment variables on your system, use the following commands, replacing `your_value` with the actual values from your account.
37+
38+
For Unix/Linux/macOS:
39+
40+
```bash
41+
export GRAPHLIT_ENVIRONMENT_ID=your_environment_id_value
42+
export GRAPHLIT_ORGANIZATION_ID=your_organization_id_value
43+
export GRAPHLIT_JWT_SECRET=your_secret_key_value
44+
```
45+
46+
For Windows Command Prompt (CMD):
47+
48+
```cmd
49+
set GRAPHLIT_ENVIRONMENT_ID=your_environment_id_value
50+
set GRAPHLIT_ORGANIZATION_ID=your_organization_id_value
51+
set GRAPHLIT_JWT_SECRET=your_secret_key_value
52+
```
53+
54+
For Windows PowerShell:
55+
56+
```powershell
57+
$env:GRAPHLIT_ENVIRONMENT_ID="your_environment_id_value"
58+
$env:GRAPHLIT_ORGANIZATION_ID="your_organization_id_value"
59+
$env:GRAPHLIT_JWT_SECRET="your_secret_key_value"
60+
```
61+
62+
## Support
63+
64+
Please refer to the [Graphlit API Documentation](https://docs.graphlit.dev/).
65+
66+
For support with the Graphlit Agent Tools, please submit a [GitHub Issue](https://github.com/graphlit/graphlit-tools/issues).
67+
68+
For further support with the Graphlit Platform, please join our [Discord](https://discord.gg/ygFmfjy3Qx) community.

__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .tools import (
2+
RetrievalTool
3+
)

azure-pipelines.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
trigger:
2+
branches:
3+
include:
4+
- main
5+
6+
name: $(Date:yyyyMMdd)$(Rev:rrr)
7+
8+
pool:
9+
vmImage: "ubuntu-latest"
10+
11+
steps:
12+
- task: UsePythonVersion@0
13+
inputs:
14+
versionSpec: "3.x"
15+
addToPath: true
16+
17+
- script: |
18+
echo "##vso[task.setvariable variable=PACKAGE_VERSION]1.0.$(Build.BuildNumber)"
19+
displayName: "Set package version"
20+
21+
- script: |
22+
python -m pip install --upgrade pip
23+
pip install setuptools wheel twine
24+
python setup.py sdist bdist_wheel
25+
displayName: "Install dependencies and build"
26+
27+
- script: |
28+
twine upload dist/* -u __token__ -p $(PYPI_TOKEN) --skip-existing
29+
displayName: "Upload to PyPI"
30+
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))

pyproject.toml

Whitespace-only changes.

setup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
from setuptools import setup, find_packages
3+
4+
# Read the content of your README file
5+
with open("README.md", "r", encoding="utf-8") as fh:
6+
long_description = fh.read()
7+
8+
version = os.getenv('PACKAGE_VERSION', '1.0.0')
9+
10+
setup(
11+
name='graphlit-tools',
12+
version=version,
13+
packages=find_packages(),
14+
install_requires=[
15+
'graphlit-client',
16+
'langchain-core'
17+
],
18+
python_requires='>=3.6',
19+
author='Unstruk Data Inc.',
20+
author_email='[email protected]',
21+
description='Graphlit Agent Tools',
22+
url='https://github.com/graphlit/graphlit-tools/',
23+
long_description=long_description,
24+
long_description_content_type="text/markdown",
25+
)

tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .retrieval.retrieval_tool import RetrievalTool

tools/retrieval/__init__.py

Whitespace-only changes.

tools/retrieval/retrieval_tool.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import asyncio
2+
import logging
3+
from typing import Type, List, Optional
4+
from graphlit import Graphlit
5+
from graphlit_api import exceptions, ContentFilter, QueryContentsContentsResults
6+
from langchain_core.pydantic_v1 import Field
7+
from langchain_core.tools import BaseTool, ToolException
8+
9+
logger = logging.getLogger(__name__)
10+
11+
class RetrievalTool(BaseTool):
12+
name = "retrieval"
13+
description = """Retrieves content based on a ContentFilter.
14+
Can search through web pages, PDFs, and other unstructured data.
15+
Filters can include query, date ranges, content types, and other criteria."""
16+
args_schema: Type[ContentFilter] = ContentFilter
17+
18+
graphlit: Graphlit = Field(exclude=True)
19+
20+
def __init__(self, graphlit: Optional[Graphlit] = None):
21+
super().__init__()
22+
self.graphlit = graphlit or Graphlit()
23+
24+
async def _arun(self, content_filter: ContentFilter) -> Optional[List[QueryContentsContentsResults]]:
25+
try:
26+
response = await self.graphlit.client.query_contents(
27+
filter=content_filter
28+
)
29+
30+
return response.contents.results if response.contents is not None else None
31+
except exceptions.GraphQLClientError as e:
32+
logger.error(str(e))
33+
raise ToolException(str(e)) from e
34+
35+
def _run(self, content_filter: ContentFilter) -> Optional[List[QueryContentsContentsResults]]:
36+
try:
37+
loop = asyncio.get_event_loop()
38+
if loop.is_running():
39+
future = asyncio.ensure_future(self._arun(content_filter))
40+
return loop.run_until_complete(future)
41+
else:
42+
return loop.run_until_complete(self._arun(content_filter))
43+
except RuntimeError:
44+
return asyncio.run(self._arun(content_filter))

0 commit comments

Comments
 (0)