GraphQL API

API Endpoint: https://api.chattydocs.com/graphql

GraphQL Schema

1
type Query {
2
viewer: User
3
}
4
5
type Mutation {
6
askDataset(input: AskDatasetInput!): AskDatasetPayload
7
createDataset(input: CreateDatasetInput!): CreateDatasetPayload
8
deleteDataset(input: DeleteDatasetInput!): DeleteDatasetPayload
9
addDocument(input: AddDocumentInput!): AddDocumentPayload
10
deleteDocument(input: DeleteDocumentInput!): DeleteDocumentPayload
11
}
12
13
type User {
14
email: Email!
15
membership: Membership!
16
datasets(first: Int, last: Int, before: ID, after: ID): DatasetConnection
17
}
18
19
type Membership {
20
bytesUploadCredit: Int!
21
queryCredit: Int!
22
active: Boolean!
23
}
24
25
type Dataset {
26
id: ID!
27
name: String!
28
accessLevel: DatasetAccessLevel!
29
createdAt: Time!
30
isViewerControlled: Boolean!
31
historySize: Int!
32
telegramBot: TelegramBot
33
documents(first: Int, last: Int, before: ID, after: ID): DocumentConnection
34
answers(first: Int, last: Int, before: ID, after: ID): AnswerConnection
35
}
36
37
type TelegramBot {
38
name: String!
39
username: String!
40
allowedUserIds: [Int!]
41
userChatLimit: Int
42
}
43
44
type Document {
45
id: ID!
46
name: String!
47
indexStatus: DocumentIndexStatus!
48
createdAt: Time!
49
pageCount: Int!
50
url: String
51
mime: String
52
group: String
53
}
54
55
type Answer {
56
model: String!
57
query: String!
58
response: String!
59
sources: [QuerySource!]!
60
createdAt: Time!
61
informational: Boolean!
62
}
63
64
type QuerySource {
65
excerpt: String!
66
meta: SourceMeta!
67
}
68
69
type SourceMeta {
70
document: Document
71
page: Int
72
}
73
74
type DatasetConnection {
75
edges: [DatasetEdge!]!
76
pageInfo: PageInfo!
77
}
78
79
type DatasetEdge {
80
cursor: ID!
81
node: Dataset!
82
}
83
84
type DocumentConnection {
85
edges: [DocumentEdge!]!
86
pageInfo: PageInfo!
87
}
88
89
type DocumentEdge {
90
cursor: ID!
91
node: Document!
92
}
93
94
type AnswerConnection {
95
edges: [AnswerEdge!]!
96
pageInfo: PageInfo!
97
}
98
99
type AnswerEdge {
100
cursor: ID!
101
node: Answer!
102
}
103
104
type PageInfo {
105
hasNextPage: Boolean!
106
hasPreviousPage: Boolean!
107
startCursor: ID
108
endCursor: ID
109
}
110
111
input AskDatasetInput {
112
dataset: ID!
113
query: String!
114
}
115
116
type AskDatasetPayload {
117
answer: Answer!
118
membership: Membership!
119
incompleteDocuments: Int
120
}
121
122
input CreateDatasetInput {
123
name: String!
124
}
125
126
type CreateDatasetPayload {
127
dataset: Dataset!
128
shared: Boolean! = false
129
}
130
131
input DeleteDatasetInput {
132
id: ID!
133
}
134
135
type DeleteDatasetPayload {
136
dataset: ID
137
}
138
139
input AddDocumentInput {
140
dataset: ID!
141
gzipB64JsonList: String!
142
name: String!
143
url: String
144
mime: String
145
group: String
146
}
147
148
type AddDocumentPayload {
149
document: Document!
150
membership: Membership!
151
}
152
153
input DeleteDocumentInput {
154
id: ID!
155
}
156
157
type DeleteDocumentPayload {
158
document: ID
159
}
160
161
enum DocumentIndexStatus {
162
QUEUED,
163
INDEXING,
164
COMPLETE
165
}
166
167
enum DatasetAccessLevel {
168
PRIVATE,
169
SHARED,
170
PUBLIC
171
}

Example

Sample Python code for adding a document to the dataset.
1
import json
2
import gzip
3
import base64
4
from gql import Client, gql
5
from gql.transport.aiohttp import AIOHTTPTransport
6
7
API_EP = 'https://api.chattydocs.com/graphql'
8
API_KEY = '<API_KEY>' # api key from the website
9
DATASET_ID = '<DATASET_ID>' # id of dataset holding documents
10
11
def compress(pages: list[str]) -> str:
12
data = json.dumps(pages)
13
bytes = data.encode('utf8')
14
gz = gzip.compress(bytes)
15
return base64.b64encode(gz).decode('utf8')
16
17
# mutation based on the GraphQL API schema
18
m_add_document = gql("""
19
mutation AddDocumentMutation($input: AddDocumentInput!) {
20
addDocument(input: $input) {
21
document {
22
id
23
}
24
membership {
25
bytesUploadCredit
26
}
27
}
28
}
29
""")
30
31
if __name__ == "__main__":
32
transport = AIOHTTPTransport(
33
url=API_EP,
34
headers={
35
'Authorization': f"Bearer {API_KEY}"
36
}
37
)
38
client = Client(transport=transport)
39
40
# sample text
41
page = "this is a sample text"
42
pages = compress([page])
43
res = client.execute(m_add_document, variable_values={ 'input': {
44
'dataset': DATASET_ID,
45
'name': 'test',
46
'gzipB64JsonList': pages,
47
}})
48
49
print(res)