Skip to content

Commit 44ddb28

Browse files
authored
Cleaning up and expanding documentation (#45)
Improving docs CICD to ensure docs build. Adding new docs pages on several topics. Cleaning up existing documentation.
1 parent b31ff37 commit 44ddb28

23 files changed

+696
-90
lines changed

.github/workflows/cicd.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,32 @@ jobs:
6464
# This is associated with the "sdk-test-prod" user, credentials on 1password
6565
GROUNDLIGHT_API_TOKEN: ${{ secrets.GROUNDLIGHT_API_TOKEN_PROD }}
6666

67+
# Check that the docs build. (No broken links, etc.)
68+
test-docs:
69+
runs-on: ubuntu-latest
70+
defaults:
71+
run:
72+
working-directory: docs/
73+
steps:
74+
- name: Get code
75+
uses: actions/checkout@v3
76+
- name: Setup npm
77+
uses: actions/setup-node@v3
78+
with:
79+
node-version: 18
80+
cache: npm
81+
- name: Install dependencies
82+
run: npm install
83+
- name: Build website
84+
run: npm run build
85+
6786
# Run integration tests against the API (only on the main branch, though). The comprehensive
6887
# version runs a matrix of python versions for better coverage.
6988
test-comprehensive:
7089
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
7190
needs:
7291
- test-simple
92+
- test-docs
7393
runs-on: ubuntu-latest
7494
strategy:
7595
# It's totally debatable which is better here: fail-fast or not.
@@ -192,7 +212,7 @@ jobs:
192212
with:
193213
github_token: ${{ secrets.GITHUB_TOKEN }}
194214
publish_dir: ./docs/build
195-
#TODO: setup a staging directory when doing a PR
215+
# Someday we might want to set the destination to a staging dir for PR's
196216
#destination_dir: staging
197217
# The following lines assign commit authorship to the official
198218
# GH-Actions bot for deploys to `gh-pages` branch:

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ Build a working computer vision system in just a few lines of python:
1212

1313
```python
1414
from groundlight import Groundlight
15-
from PIL import Image
16-
import requests
1715

1816
gl = Groundlight()
19-
d = gl.get_or_create_detector(name="doorway", query="Is the doorway open?")
20-
image_url = "https://images.selfstorage.com/large-compress/2174925f24362c479b2.jpg"
21-
image = Image.open(requests.get(image_url, stream=True).raw)
22-
image_query = gl.submit_image_query(detector=d, image=image)
17+
det = gl.get_or_create_detector(name="doorway", query="Is the doorway open?")
18+
img = "./docs/static/img/doorway.jpg" # Image can be a file or a Python object
19+
image_query = gl.submit_image_query(detector=det, image=img)
2320
print(f"The answer is {image_query.result}")
2421
```
2522

2623
### How does it work?
2724

2825
Your images are first analyzed by machine learning (ML) models which are automatically trained on your data. If those models have high enough confidence, that's your answer. But if the models are unsure, then the images are progressively escalated to more resource-intensive analysis methods up to real-time human review. So what you get is a computer vision system that starts working right away without even needing to first gather and label a dataset. At first it will operate with high latency, because people need to review the image queries. But over time, the ML systems will learn and improve so queries come back faster with higher confidence.
2926

30-
_Note: The SDK is currently in "beta" phase. Interfaces are subject to change in future versions._
27+
_Note: The SDK is currently in "beta" phase. Interfaces are subject to change in future versions. We will follow [semver](https://semver.org/) semantics for breaking changes._
3128

3229
## Learn more
3330

docs/README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
# Website
1+
# Documentation: code.groundlight.ai
22

3-
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
3+
This part of the SDK repo contains all the code for the website at [code.groundlight.ai](https://code.groundlight.ai/) It is built with [Docusaurus 2](https://docusaurus.io/).
44

5-
## Installation
5+
The docs are included with the SDK so that we can automate testing of the code samples in the documentation. This way we can ensure that the code samples in our docs always work with the current SDK.
66

7-
```shell
7+
## Previewing doc changes
8+
9+
Doc changes are published automatically when they're merged to main. To preview changes, build and host the site locally. You'll need a reasonably modern version of `npm` and then:
10+
11+
<<<<<<< HEAD
12+
```
813
npm install
14+
npm run build # looks for any errors
15+
npm start # starts interactive server
916
```
1017

11-
## Local Development
18+
and then open [http://localhost:3000/python-sdk](http://localhost:3000/python-sdk).
1219

13-
```shell
14-
npm start
15-
```
1620

17-
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
21+
## Running docs tests
1822

19-
### Build
23+
You'll need python poetry and make installed. And you'll need an API Token configured. Then you can just run:
2024

21-
```shell
22-
npm run build
25+
```
26+
make test-docs
27+
```
28+
=======
29+
```
30+
npm install
31+
npm start
2332
```
2433

25-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26-
27-
### Deployment
34+
and then open [http://localhost:3000/python-sdk](http://localhost:3000/python-sdk).
2835

29-
Using SSH:
3036

31-
```shell
32-
USE_SSH=true npm run deploy
33-
```
37+
## Running docs tests
3438

35-
Not using SSH:
39+
You'll need python poetry and make installed. And you'll need an API Token configured. Then you can just run:
3640

37-
```shell
38-
GIT_USER=<Your GitHub username> npm run deploy
3941
```
40-
41-
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
42+
make test-docs
43+
```
44+
>>>>>>> origin/docs-applications
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
22
"label": "Building Applications",
3-
"position": 2,
4-
"link": {
5-
"type": "generated-index",
6-
"description": "Let's build some reliable vision applications."
7-
}
3+
"position": 2
84
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Building Applications
2+
3+
Groundlight provides a powerful "computer vision powered by natural language" system that enables you to build visual applications with minimal code. With Groundlight, you can quickly create applications for various use cases, from simple object detection to complex visual analysis.
4+
5+
In this page, we'll introduce you to some sample applications built using Groundlight and provide links to more detailed guides on various topics.
6+
7+
## Sample Applications
8+
9+
Explore these GitHub repositories to see examples of Groundlight-powered applications:
10+
11+
### Groundlight Stream Processor
12+
13+
Repository: [https://github.com/groundlight/stream](https://github.com/groundlight/stream)
14+
15+
The Groundlight Stream Processor is an easy-to-use Docker container for analyzing RTSP streams or common USB-based cameras. You can run it with a single Docker command, such as:
16+
17+
```bash
18+
docker run stream:local --help
19+
```
20+
21+
### Arduino ESP32 Camera Sample App
22+
23+
Repository: [https://github.com/groundlight/esp32cam](https://github.com/groundlight/esp32cam)
24+
25+
This sample application allows you to build a working AI vision detector using an inexpensive WiFi camera. With a cost of under $10, you can create a powerful and affordable AI vision system.
26+
27+
### Raspberry Pi
28+
29+
Repository: [https://github.com/groundlight/raspberry-pi-door-lock](https://github.com/groundlight/raspberry-pi-door-lock)
30+
31+
This sample application demonstrates how to set up a Raspberry Pi-based door lock system. The application monitors a door and sends a notification if the door is observed to be unlocked during non-standard business hours.
32+
33+
### Industrial and Manufacturing Applications
34+
35+
Groundlight can be used to [apply modern natural-language-based computer vision to industrial and manufacturing applications](/docs/building-applications/industrial).
36+
37+
## Further Reading
38+
39+
For more in-depth guides on various aspects of building applications with Groundlight, check out the following pages:
40+
41+
- [Working with Detectors](working-with-detectors.md): Learn how to create, configure, and use detectors in your Groundlight-powered applications.
42+
- [Using Groundlight on the edge](edge.md): Discover how to deploy Groundlight in edge computing environments for improved performance and reduced latency.
43+
- [Handling HTTP errors](handling-errors.md): Understand how to handle and troubleshoot HTTP errors that may occur while using Groundlight.
44+
45+
By exploring these resources and sample applications, you'll be well on your way to building powerful visual applications using Groundlight's computer vision and natural language capabilities.
46+
47+
Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,66 @@
1-
# Handling HTTP errors
1+
# Handling Server Errors
22

3-
If there is an HTTP error during an API call, it will raise an `ApiException`. You can access different metadata from that exception:
3+
When building applications with the Groundlight SDK, you may encounter server errors during API calls. This page covers how to handle such errors and build robust code that can gracefully handle exceptions.
44

5-
```python
5+
## Handling ApiException
6+
7+
If there is an HTTP error during an API call, the SDK will raise an `ApiException`. You can access different metadata from that exception:
8+
9+
```python notest
10+
import traceback
611
from groundlight import ApiException, Groundlight
712

813
gl = Groundlight()
914
try:
10-
detectors = gl.list_detectors()
15+
d = gl.get_or_create_detector(
16+
"Road Checker",
17+
"Is the site access road blocked?")
18+
iq = gl.submit_image_query(d, get_image(), wait=60)
1119
except ApiException as e:
12-
# Many fields available to describe the error
13-
print(e)
14-
print(e.args)
15-
print(e.body)
16-
print(e.headers)
17-
print(e.reason)
18-
print(e.status)
20+
# Print a traceback for debugging
21+
traceback.print_exc()
22+
23+
# e.reason contains a textual description of the error
24+
print(f"Error reason: {e.reason}")
25+
26+
# e.status contains the HTTP status code
27+
print(f"HTTP status code: {e.status}")
28+
29+
# Common HTTP status codes:
30+
# 400 Bad Request: The request was invalid or malformed
31+
# 401 Unauthorized: Your GROUNDLIGHT_API_TOKEN is missing or invalid
32+
# 403 Forbidden: The request is not allowed due to insufficient permissions
33+
# 404 Not Found: The requested resource was not found
34+
# 429 Too Many Requests: The rate limit for the API has been exceeded
35+
# 500 Internal Server Error: An error occurred on the server side
1936
```
37+
38+
## Best Practices for Handling Exceptions
39+
40+
When working with the Groundlight SDK, follow these best practices to handle exceptions and build robust code:
41+
42+
### Catch Specific Exceptions
43+
44+
Catch only the specific exceptions that you expect to be raised, such as `ApiException`. Avoid catching broad exceptions like `Exception`, as it may make debugging difficult and obscure other unrelated issues.
45+
46+
### Use Custom Exception Classes
47+
48+
Consider creating custom exception classes for your application-specific errors. This can help you differentiate between errors originating from the Groundlight SDK and those from your application.
49+
50+
### Log Exceptions
51+
52+
Log exceptions with appropriate log levels (e.g., error, warning, etc.) and include relevant context information. This will help you debug issues more effectively and monitor the health of your application.
53+
54+
### Implement Retry Logic
55+
56+
When handling exceptions, implement retry logic with exponential backoff for transient errors, such as network issues or rate-limiting. This can help your application recover from temporary issues without manual intervention.
57+
58+
### Handle Exceptions Gracefully
59+
60+
In addition to logging exceptions, handle them gracefully to ensure that your application remains functional despite errors. This might include displaying an error message to users or falling back to a default behavior.
61+
62+
### Test Your Error Handling
63+
64+
Write tests to ensure that your error handling works as expected. This can help you catch issues early and ensure that your application can handle errors gracefully in production.
65+
66+
By following these best practices, you can create robust and resilient applications that can handle server errors and other exceptions when using the Groundlight SDK.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Industrial and Manufacturing Applications
2+
3+
Modern natural language-based computer vision is transforming industrial and manufacturing applications by enabling more intuitive interaction with automation systems. Groundlight offers cutting-edge computer vision technology that can be seamlessly integrated into various industrial processes, enhancing efficiency, productivity, and quality control.
4+
5+
## Machine Tending
6+
7+
Groundlight's computer vision technology can assist in automating machine-tending tasks, such as loading and unloading materials in CNC machines, milling centers, or injection molding equipment. By enabling robots to recognize parts and tools using natural language, complex machine-tending tasks become more accessible and efficient.
8+
9+
## Process Automation
10+
11+
Integrating Groundlight's computer vision into your process automation systems can help identify bottlenecks, optimize workflows, and reduce manual intervention. Our technology can work hand-in-hand with robotic systems to perform tasks like sorting, assembly, all while interpreting natural language commands to streamline operations.
12+
13+
## Quality Control
14+
15+
Groundlight's computer vision technology can play a vital role in ensuring the highest quality standards in your manufacturing processes. By identifying defects or irregularities in products, our computer vision system can help maintain strict quality control, reducing the need for manual inspections and increasing overall product quality.
16+
17+
## Integration with Cobots and CNC Machines
18+
19+
Groundlight's computer vision technology can be easily integrated with popular cobot robotic arms, such as Universal Robots, to enhance their capabilities and improve collaboration between humans and robots. Additionally, our technology can be integrated into existing CNC machines or other devices using the Modbus interface, allowing for seamless communication and control within your manufacturing environment.
20+
21+
# Contact Sales
22+
23+
To learn more about how Groundlight's natural language computer vision technology can revolutionize your industrial and manufacturing processes, please reach out to us at [[email protected]](mailto:[email protected]).
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# API Tokens
2+
3+
## About API Tokens
4+
5+
To use the Groundlight SDK or API, you need a security token which we call an "API Token." These authenticate you to Groundlight and authorize your code to use services in your account.
6+
7+
API tokens look like `api_2GdXMflhJ...` and consist of a ksuid (a kind of sortable UUID) followed by a secret string.
8+
9+
## Handling API Tokens
10+
11+
**You should treat API tokens like passwords.** Never check them directly into your code or share them. Please use best security practices with your API tokens, because if anybody gets your API token, they have nearly full control over your Groundlight account.
12+
13+
Here are some best practices for handling API tokens:
14+
15+
- Store API tokens in a secure location, such as an encrypted vault.
16+
- Use environment variables to store API tokens, rather than hardcoding them in your application.
17+
- Limit the number of people who have access to API tokens.
18+
- Rotate API tokens regularly and revoke old ones when they are no longer needed.
19+
20+
## Using API Tokens with the SDK
21+
22+
There are a couple of ways the SDK can find your API token:
23+
24+
1. Environment variable (recommended): As a best practice, we recommend storing API tokens in the environment variable `GROUNDLIGHT_API_TOKEN`. This helps avoid accidentally committing the token to your code repository. The SDK will automatically look for the API token there, so you don't have to put it in your code at all.
25+
26+
```python
27+
from groundlight import Groundlight
28+
29+
# looks for API token in environment variable GROUNDLIGHT_API_TOKEN
30+
gl = Groundlight()
31+
```
32+
33+
2. Constructor argument: Alternatively, you can pass the API token directly to the Groundlight constructor. However, be cautious not to commit this code to your repository.
34+
35+
```
36+
from groundlight import Groundlight
37+
38+
token = get_token_from_secure_location()
39+
gl = Groundlight(api_token=token)
40+
```
41+
42+
## Creating and Revoking API Tokens
43+
You can manage your API tokens from the Groundlight website at [https://app.groundlight.ai/reef/my-account/api-tokens](https://app.groundlight.ai/reef/my-account/api-tokens).
44+
45+
46+
### Creating API Tokens
47+
48+
1. Log in to your Groundlight account and navigate to the API tokens page.
49+
1. Click the "Create New API Token" button.
50+
1. Give the new token a descriptive name, so you can easily identify it later.
51+
1. Click "Create Token."
52+
1. Copy the generated token and store it securely, as you won't be able to see it again. Groundlight does not store a copy of your API tokens.
53+
54+
### Viewing and Revoking API Tokens
55+
56+
On the API tokens page, you can see a list of your current tokens, along with the following information:
57+
58+
- Token Name: The descriptive name you assigned when creating the token
59+
- Snippet (prefix): A short, unique identifier for each token
60+
- Last used: The date and time the token was last used
61+
62+
### To revoke an API token
63+
64+
1. Locate the token you want to revoke in the list.
65+
1. Click the "Delete" button next to the token.
66+
1. Confirm that you want to revoke the token.
67+
68+
Note: Revoking an API token will immediately invalidate it and prevent any applications using it from accessing your Groundlight account. Be sure to update your applications with a new token before revoking an old one.
69+

0 commit comments

Comments
 (0)