Skip to content

Commit 88f42eb

Browse files
authored
Merge pull request #1 from stackql/feature/provider-dev
moved to microsite
2 parents 3a25ca3 + 15f31f1 commit 88f42eb

File tree

63 files changed

+14452
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+14452
-19
lines changed

package-lock.json

Lines changed: 527 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@stackql/pgwire-lite": "^1.0.1",
18-
"@stackql/provider-utils": "^0.4.6"
18+
"@stackql/provider-utils": "^0.5.0"
1919
},
2020
"keywords": [
2121
"stackql",

website/README.md

Lines changed: 258 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,283 @@
1-
# Website
1+
# `openai` provider for [`stackql`](https://github.com/stackql/stackql)
22

3-
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
3+
This repository is used to generate and document the `openai` provider for StackQL, allowing you to query and interact with OpenAI services using SQL-like syntax. The provider is built using the `@stackql/provider-utils` package, which provides tools for converting OpenAPI specifications into StackQL-compatible provider schemas.
44

5-
## Installation
5+
## Prerequisites
6+
7+
To use the OpenAI provider with StackQL, you'll need:
8+
9+
1. An OpenAI account with appropriate API credentials
10+
2. An OpenAI API key with sufficient permissions for the resources you want to access
11+
3. StackQL CLI installed on your system (see [StackQL](https://github.com/stackql/stackql))
12+
13+
## 1. Download the Open API Specification
14+
15+
First, download or create the OpenAI API OpenAPI specification:
616

717
```bash
8-
yarn
18+
mkdir -p provider-dev/downloaded
19+
curl -L https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml \
20+
-o provider-dev/downloaded/openai-openapi.yaml
21+
22+
# Convert YAML to JSON if needed
23+
python3 provider-dev/scripts/yaml_to_json.py \
24+
--input provider-dev/downloaded/openai-openapi.yaml \
25+
--output provider-dev/downloaded/openapi.json
926
```
1027

11-
## Local Development
28+
## 2. Split into Service Specs
29+
30+
Next, split the OpenAPI specification into service-specific files:
1231

1332
```bash
14-
yarn start
33+
rm -rf provider-dev/source/*
34+
npm run split -- \
35+
--provider-name openai \
36+
--api-doc provider-dev/downloaded/openapi.json \
37+
--svc-discriminator tag \
38+
--output-dir provider-dev/source \
39+
--overwrite \
40+
--svc-name-overrides "$(cat <<EOF
41+
{
42+
"models": "models",
43+
"completions": "completions",
44+
"chat": "chat",
45+
"embeddings": "embeddings",
46+
"fine-tuning": "fine_tuning",
47+
"files": "files",
48+
"images": "images",
49+
"audio": "audio",
50+
"moderations": "moderations",
51+
"assistants": "assistants",
52+
"threads": "threads",
53+
"batches": "batches"
54+
}
55+
EOF
56+
)"
1557
```
1658

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.
59+
## 3. Generate Mappings
1860

19-
## Build
61+
Generate the mapping configuration that connects OpenAPI operations to StackQL resources:
2062

2163
```bash
22-
yarn build
64+
npm run generate-mappings -- \
65+
--provider-name openai \
66+
--input-dir provider-dev/source \
67+
--output-dir provider-dev/config
68+
```
69+
70+
Update the resultant `provider-dev/config/all_services.csv` to add the `stackql_resource_name`, `stackql_method_name`, `stackql_verb` values for each operation.
71+
72+
## 4. Generate Provider
73+
74+
This step transforms the split OpenAPI service specs into a fully-functional StackQL provider by applying the resource and method mappings defined in your CSV file.
75+
76+
```bash
77+
rm -rf provider-dev/openapi/*
78+
npm run generate-provider -- \
79+
--provider-name openai \
80+
--input-dir provider-dev/source \
81+
--output-dir provider-dev/openapi/src/openai \
82+
--config-path provider-dev/config/all_services.csv \
83+
--servers '[{"url": "https://api.openai.com/v1"}]' \
84+
--provider-config '{"auth": {"credentialsenvvar": "OPENAI_API_KEY", "type": "bearer"}}' \
85+
--overwrite
2386
```
2487

25-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
88+
## 5. Test Provider
2689

27-
## Deployment
90+
### Starting the StackQL Server
2891

29-
Using SSH:
92+
Before running tests, start a StackQL server with your provider:
3093

3194
```bash
32-
USE_SSH=true yarn deploy
95+
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
96+
npm run start-server -- --provider openai --registry $PROVIDER_REGISTRY_ROOT_DIR
3397
```
3498

35-
Not using SSH:
99+
### Test Meta Routes
100+
101+
Test all metadata routes (services, resources, methods) in the provider:
36102

37103
```bash
38-
GIT_USER=<Your GitHub username> yarn deploy
104+
npm run test-meta-routes -- openai --verbose
39105
```
40106

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.
107+
When you're done testing, stop the StackQL server:
108+
109+
```bash
110+
npm run stop-server
111+
```
112+
113+
Use this command to view the server status:
114+
115+
```bash
116+
npm run server-status
117+
```
118+
119+
### Run test queries
120+
121+
Run some test queries against the provider using the `stackql shell`:
122+
123+
```bash
124+
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
125+
REG_STR='{"url": "file://'${PROVIDER_REGISTRY_ROOT_DIR}'", "localDocRoot": "'${PROVIDER_REGISTRY_ROOT_DIR}'", "verifyConfig": {"nopVerify": true}}'
126+
./stackql shell --registry="${REG_STR}"
127+
```
128+
129+
Example queries to try:
130+
131+
```sql
132+
-- List all available models
133+
SELECT
134+
id,
135+
object,
136+
created,
137+
owned_by
138+
FROM openai.models.models;
139+
140+
-- Get information about a specific model
141+
SELECT
142+
id,
143+
object,
144+
created,
145+
owned_by
146+
FROM openai.models.model
147+
WHERE id = 'gpt-4';
148+
149+
-- List uploaded files
150+
SELECT
151+
id,
152+
object,
153+
bytes,
154+
created_at,
155+
filename,
156+
purpose
157+
FROM openai.files.files;
158+
159+
-- Create a chat completion (text generation)
160+
INSERT INTO openai.chat.completions (
161+
json_data
162+
) VALUES (
163+
'{
164+
"model": "gpt-3.5-turbo",
165+
"messages": [
166+
{
167+
"role": "system",
168+
"content": "You are a helpful assistant."
169+
},
170+
{
171+
"role": "user",
172+
"content": "Hello, how are you today?"
173+
}
174+
]
175+
}'
176+
);
177+
178+
-- Create an embedding
179+
INSERT INTO openai.embeddings.embeddings (
180+
json_data
181+
) VALUES (
182+
'{
183+
"model": "text-embedding-ada-002",
184+
"input": "The food was delicious and the service was excellent."
185+
}'
186+
);
187+
188+
-- List fine-tuning jobs
189+
SELECT
190+
id,
191+
object,
192+
model,
193+
created_at,
194+
finished_at,
195+
fine_tuned_model,
196+
organization_id,
197+
status,
198+
training_file
199+
FROM openai.fine_tuning.jobs;
200+
201+
-- List assistants
202+
SELECT
203+
id,
204+
object,
205+
created_at,
206+
name,
207+
description,
208+
model,
209+
instructions,
210+
tools,
211+
metadata
212+
FROM openai.assistants.assistants;
213+
```
214+
215+
## 6. Publish the provider
216+
217+
To publish the provider push the `openai` dir to `providers/src` in a feature branch of the [`stackql-provider-registry`](https://github.com/stackql/stackql-provider-registry). Follow the [registry release flow](https://github.com/stackql/stackql-provider-registry/blob/dev/docs/build-and-deployment.md).
218+
219+
Launch the StackQL shell:
220+
221+
```bash
222+
export DEV_REG="{ \"url\": \"https://registry-dev.stackql.app/providers\" }"
223+
./stackql --registry="${DEV_REG}" shell
224+
```
225+
226+
Pull the latest dev `openai` provider:
227+
228+
```sql
229+
registry pull openai;
230+
```
231+
232+
Run some test queries to verify the provider works as expected.
233+
234+
## 7. Generate web docs
235+
236+
Provider doc microsites are built using Docusaurus and published using GitHub Pages.
237+
238+
a. Update `headerContent1.txt` and `headerContent2.txt` accordingly in `provider-dev/docgen/provider-data/`
239+
240+
b. Update the following in `website/docusaurus.config.js`:
241+
242+
```js
243+
// Provider configuration - change these for different providers
244+
const providerName = "openai";
245+
const providerTitle = "OpenAI Provider";
246+
```
247+
248+
c. Then generate docs using...
249+
250+
```bash
251+
npm run generate-docs -- \
252+
--provider-name openai \
253+
--provider-dir ./provider-dev/openapi/src/openai/v00.00.00000 \
254+
--output-dir ./website \
255+
--provider-data-dir ./provider-dev/docgen/provider-data
256+
```
257+
258+
## 8. Test web docs locally
259+
260+
```bash
261+
cd website
262+
# test build
263+
yarn build
264+
265+
# run local dev server
266+
yarn start
267+
```
268+
269+
## 9. Publish web docs to GitHub Pages
270+
271+
Under __Pages__ in the repository, in the __Build and deployment__ section select __GitHub Actions__ as the __Source__. In Netlify DNS create the following records:
272+
273+
| Source Domain | Record Type | Target |
274+
|---------------|--------------|--------|
275+
| openai-provider.stackql.io | CNAME | stackql.github.io. |
276+
277+
## License
278+
279+
MIT
280+
281+
## Contributing
282+
283+
Contributions are welcome! Please feel free to submit a Pull Request.

website/docs/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)