Skip to content

Commit 83ff88c

Browse files
Add an SDK section (#76)
## Description 📝 Adds an SDK section for the available SDKs (Node.js, Python, and Go) We link to the appropriate "home" (npmjs, PyPi, GitHub), show users how to install it, and, create a client, and how to query the available APIs. This is meant to be minimal as a starting place and provide a footprint for these. Updates are expected to come from the authors going forward 🙏 ## Quick Links 🚀 [New SDK section](https://robdominguez-doc-2695-add-an.promptql-docs.pages.dev/promptql-apis/sdk/)
1 parent cd3ca67 commit 83ff88c

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "SDKs",
3+
"position": 5
4+
}

docs/promptql-apis/sdk/go.mdx

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
sidebar_position: 4
3+
sidebar_label: Go
4+
description: "Get started with the Go SDK for PromptQL."
5+
keywords:
6+
- hasura ddn
7+
- promptql apis
8+
- apis
9+
- sdk
10+
- go
11+
---
12+
13+
# Go SDK
14+
15+
## Introduction
16+
17+
The Go SDK is available [here](https://github.com/hasura/promptql-go-sdk).
18+
19+
## Install
20+
21+
```sh title="The SDK can be installed using the Go CLI:"
22+
go get github.com/hasura/promptql-go-sdk
23+
```
24+
25+
## Connect
26+
27+
```go title="You'll connect to an instnace by creating a client:"
28+
import (
29+
"github.com/hasura/promptql-go-sdk/promptql"
30+
)
31+
32+
client, err := promptql.NewClient("<promptql-api-key>", &promptql.ClientConfig{
33+
DdnBaseURL: "https://your-ddn-project",
34+
DdnHeaders: map[string]string{
35+
// Optional: add authorization headers if required by your DDN project
36+
// "Authorization": "Bearer <token>",
37+
},
38+
})
39+
40+
if err != nil {
41+
log.Fatalf("failed to create client: %s", err)
42+
}
43+
```
44+
45+
## Query the Natural Language API
46+
47+
```js title="Then, use your client to query the Natural Language API:"
48+
result, err := client.Query(
49+
context.Background(),
50+
promptql.NewQueryRequestMessage("what can you do?"),
51+
)
52+
53+
if err != nil {
54+
log.Fatalf("query failed: %s", err)
55+
}
56+
57+
58+
// Get the response
59+
if len(result.AssistantActions) > 0 {
60+
if msg := result.AssistantActions[0].Message.Get(); msg != nil {
61+
log.Println(msg)
62+
}
63+
}
64+
65+
```
66+
67+
## Query the Execute Program API
68+
69+
```go title="Or, the Exceute Program API:"
70+
func (c *Client) ExecuteProgram(ctx context.Context, body api.ExecuteRequest) (*api.PromptQlExecutionResult, error)
71+
```

docs/promptql-apis/sdk/index.mdx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
sidebar_position: 1
3+
description: "Learn more about the available SDKs to make development with PromptQL easier."
4+
keywords:
5+
- hasura ddn
6+
- promptql apis
7+
- apis
8+
- sdk
9+
---
10+
11+
# Available SDKs
12+
13+
## Introduction
14+
15+
Hasura provides a set of officially-supported SDKs to make development with PromptQL easier. The following libraries
16+
enable you to connect to a PromptQL instance and interact with both the
17+
[Natural Language](/promptql-apis/natural-language-api.mdx) and
18+
[Execute Program](/promptql-apis/execute-program-api.mdx) APIs.
19+
20+
## Learn more
21+
22+
- [Node.js](/promptql-apis/sdk/nodejs.mdx)
23+
- [Python](/promptql-apis/sdk/python.mdx)
24+
- [Go](/promptql-apis/sdk/go.mdx)

docs/promptql-apis/sdk/nodejs.mdx

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
sidebar_position: 2
3+
sidebar_label: Node.js
4+
description: "Get started with the Node.js SDK for PromptQL."
5+
keywords:
6+
- hasura ddn
7+
- promptql apis
8+
- apis
9+
- sdk
10+
- node
11+
---
12+
13+
# Node.js SDK
14+
15+
## Introduction
16+
17+
The Node.js SDK is available [here](https://www.npmjs.com/package/@hasura/promptql).
18+
19+
## Install
20+
21+
```sh title="The SDK can be installed using npm:"
22+
npm i @hasura/promptql
23+
```
24+
25+
## Connect
26+
27+
```js title="You'll connect to an instnace by creating a client:"
28+
import { createPromptQLClient } from "@hasura/promptql";
29+
30+
const client = createPromptQLClient({
31+
apiKey: "<your-promptql-api-key>",
32+
ddn: {
33+
url: "<your-project-endpoint>",
34+
headers: {
35+
Authorization: "<credential>",
36+
},
37+
},
38+
});
39+
```
40+
41+
## Query the Natural Language API
42+
43+
```js title="Then, use your client to query the Natural Language API:"
44+
client
45+
.queryStream({
46+
artifacts: [],
47+
interactions: [
48+
user_message: {
49+
text: 'what can you do?',
50+
}
51+
],
52+
},
53+
async (chunk) => {
54+
console.log(chunk);
55+
},
56+
);
57+
```
58+
59+
## Query the Execute Program API
60+
61+
```ts title="Or, the Exceute Program API:"
62+
function executeProgram(body: PromptQLExecuteRequest, executeOptions?: FetchOptions) Promise<PromptQlExecutionResult>;
63+
```

docs/promptql-apis/sdk/python.mdx

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
sidebar_position: 3
3+
sidebar_label: Python
4+
description: "Get started with the Python SDK for PromptQL."
5+
keywords:
6+
- hasura ddn
7+
- promptql apis
8+
- apis
9+
- sdk
10+
- python
11+
---
12+
13+
# Python SDK
14+
15+
## Introduction
16+
17+
The Python SDK is available [here](https://pypi.org/project/promptql-api-sdk/).
18+
19+
:::info The Python SDK currently supports the Natural Language API
20+
21+
Support for the Execute Program API will be released soon.
22+
23+
:::
24+
25+
## Install
26+
27+
```sh title="The SDK can be installed using pip:"
28+
pip install promptql-api-sdk
29+
```
30+
31+
```sh title="Or Poetry:"
32+
poetry add promptql-api-sdk
33+
```
34+
35+
## Connect
36+
37+
```python title="You'll connect to an instnace by creating a client:"
38+
from promptql_api_sdk import PromptQLClient
39+
from promptql_api_sdk.types.models import HasuraLLMProvider
40+
41+
# Initialize the client
42+
client = PromptQLClient(
43+
api_key="your-promptql-api-key",
44+
ddn_url="your-ddn-url",
45+
llm_provider=HasuraLLMProvider(),
46+
timezone="America/Los_Angeles",
47+
)
48+
```
49+
50+
## Query the Natural Language API
51+
52+
```python title="Then, use your client to query the Natural Language API:"
53+
# Send a simple query
54+
response = client.query("What is the average temperature in San Francisco?")
55+
print(response.assistant_actions[0].message)
56+
57+
# Use streaming for real-time responses
58+
for chunk in client.query("Tell me about the weather in New York", stream=True):
59+
if hasattr(chunk, "message") and chunk.message:
60+
print(chunk.message, end="", flush=True)
61+
```

0 commit comments

Comments
 (0)