Skip to content

Commit

Permalink
Refactor/doc snippets (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter authored Aug 9, 2024
1 parent 8648aeb commit 4d71d3a
Show file tree
Hide file tree
Showing 316 changed files with 5,118 additions and 5,089 deletions.
2 changes: 1 addition & 1 deletion .github/actions/init-bare-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ runs:

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with test --with dev
run: poetry install --no-interaction --with test --with dev
shell: bash

- name: Activate venv
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/init-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ runs:

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with test --with dev --all-extras
run: poetry install --no-interaction --with test --with dev --with docs --all-extras
shell: bash

- name: Activate venv
Expand Down
22 changes: 1 addition & 21 deletions .github/workflows/docs-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
name: Docs Integration Tests

on:
pull_request_review:
types: [submitted]
push:
branches:
- main
- dev
branches: [ "main", "dev" ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
if: github.event.review.state == 'APPROVED' || github.event_name == 'push'
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -145,22 +140,7 @@ jobs:
uses: actions/checkout@v3
- name: Init environment
uses: ./.github/actions/init-environment
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
if: github.event_name == 'pull_request_review'
with:
files: |
**.md
- name: List all changed files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
- name: Run integration tests
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name == 'push'
run: make test/integration
env:
DOCS_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files || '' }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ check/lint:

.PHONY: check/types
check/types:
@poetry run pyright griptape/
@poetry run pyright griptape/ docs/**/src/**

.PHONY: check/spell
check/spell:
Expand Down
5 changes: 0 additions & 5 deletions docs/assets/css/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@
.md-typeset table:not([class]) {
display: table;
}

/* Hide the code block title since we're using it for other purposes.*/
.filename {
display: none !important
}
35 changes: 1 addition & 34 deletions docs/examples/amazon-dynamodb-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,7 @@ In this example, we will show you how to use the [AmazonDynamoDbConversationMemo
This code implements the idea of a generic "Session" that represents a Conversation Memory entry. For example, a "Session" could be used to represent an individual user's conversation, or a group conversation thread.

```python
import sys
import os
import argparse

import boto3
from griptape.drivers import (
AmazonDynamoDbConversationMemoryDriver,
)
from griptape.structures import Agent
from griptape.memory.structure import ConversationMemory

if len(sys.argv) > 2:
input = sys.argv[1]
session_id = sys.argv[2]
else:
input = "Hello!" # Default input
session_id = "session-id-123" # Default session ID

structure = Agent(
conversation_memory=ConversationMemory(
driver=AmazonDynamoDbConversationMemoryDriver(
session=boto3.Session(
aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
),
table_name=os.environ["DYNAMODB_TABLE_NAME"], # The name of the DynamoDB table
partition_key="id", # The name of the partition key
partition_key_value=session_id, # The value of the partition key
value_attribute_key="value", # The key in the DynamoDB item that stores the memory value
)
)
)

print(structure.run(input).output_task.output.value)
--8<-- "docs/examples/src/amazon_dynamodb_sessions_1.py"
```

Conversation Memory for an individual user:
Expand Down
43 changes: 1 addition & 42 deletions docs/examples/load-and-query-pinecone.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
```python
import hashlib
import os
import json
from urllib.request import urlopen
from griptape.drivers import PineconeVectorStoreDriver, OpenAiEmbeddingDriver

def load_data(driver: PineconeVectorStoreDriver) -> None:
response = urlopen(
"https://raw.githubusercontent.com/wedeploy-examples/"
"supermarket-web-example/master/products.json"
)

for product in json.loads(response.read()):
driver.upsert_text(
product["description"],
vector_id=hashlib.md5(product["title"].encode()).hexdigest(),
meta={
"title": product["title"],
"description": product["description"],
"type": product["type"],
"price": product["price"],
"rating": product["rating"],
},
namespace="supermarket-products",
)

vector_driver = PineconeVectorStoreDriver(
api_key=os.environ["PINECONE_API_KEY"],
environment=os.environ["PINECONE_ENVIRONMENT"],
index_name=os.environ["PINECONE_INDEX_NAME"],
embedding_driver=OpenAiEmbeddingDriver()
)

load_data(vector_driver)

result = vector_driver.query(
"fruit",
count=3,
filter={"price": {"$lte": 15}, "rating": {"$gte": 4}},
namespace="supermarket-products",
)
print(result)
--8<-- "docs/examples/src/load_and_query_pinecone_1.py"
```
44 changes: 2 additions & 42 deletions docs/examples/load-query-and-chat-marqo.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
```python title="PYTEST_IGNORE"
import os
from griptape import utils
from griptape.drivers import MarqoVectorStoreDriver
from griptape.loaders import WebLoader
from griptape.structures import Agent
from griptape.tools import VectorStoreClient
from griptape.drivers import OpenAiEmbeddingDriver

# Define the namespace
namespace = "griptape-ai"

# # Initialize the vector store driver
vector_store = MarqoVectorStoreDriver(
api_key=os.environ["MARQO_API_KEY"],
url=os.environ["MARQO_URL"],
index=os.environ["MARQO_INDEX_NAME"],
embedding_driver=OpenAiEmbeddingDriver()
)

# Initialize the knowledge base tool
vector_store_tool = VectorStoreClient(
description="Contains information about the Griptape Framework from www.griptape.ai",
namespace=namespace,
vector_store_driver=vector_store
)

# Load artifacts from the web
artifacts = WebLoader().load("https://www.griptape.ai")

# Upsert the artifacts into the vector store
vector_store.upsert_text_artifacts(
{
namespace: artifacts,
}
)

# Initialize the agent
agent = Agent(tools=[vector_store_tool])

# Start the chat
utils.Chat(agent).start()
```python
--8<-- "docs/examples/src/load_query_and_chat_marqo_1.py"
```
Loading

0 comments on commit 4d71d3a

Please sign in to comment.