GraphQL API
API Endpoint: https://api.chattydocs.com/graphql
GraphQL Schema
1type Query {2viewer: User3}45type Mutation {6askDataset(input: AskDatasetInput!): AskDatasetPayload7createDataset(input: CreateDatasetInput!): CreateDatasetPayload8deleteDataset(input: DeleteDatasetInput!): DeleteDatasetPayload9addDocument(input: AddDocumentInput!): AddDocumentPayload10deleteDocument(input: DeleteDocumentInput!): DeleteDocumentPayload11}1213type User {14email: Email!15membership: Membership!16datasets(first: Int, last: Int, before: ID, after: ID): DatasetConnection17}1819type Membership {20bytesUploadCredit: Int!21queryCredit: Int!22active: Boolean!23}2425type Dataset {26id: ID!27name: String!28accessLevel: DatasetAccessLevel!29createdAt: Time!30isViewerControlled: Boolean!31historySize: Int!32telegramBot: TelegramBot33documents(first: Int, last: Int, before: ID, after: ID): DocumentConnection34answers(first: Int, last: Int, before: ID, after: ID): AnswerConnection35}3637type TelegramBot {38name: String!39username: String!40allowedUserIds: [Int!]41userChatLimit: Int42}4344type Document {45id: ID!46name: String!47indexStatus: DocumentIndexStatus!48createdAt: Time!49pageCount: Int!50url: String51mime: String52group: String53}5455type Answer {56model: String!57query: String!58response: String!59sources: [QuerySource!]!60createdAt: Time!61informational: Boolean!62}6364type QuerySource {65excerpt: String!66meta: SourceMeta!67}6869type SourceMeta {70document: Document71page: Int72}7374type DatasetConnection {75edges: [DatasetEdge!]!76pageInfo: PageInfo!77}7879type DatasetEdge {80cursor: ID!81node: Dataset!82}8384type DocumentConnection {85edges: [DocumentEdge!]!86pageInfo: PageInfo!87}8889type DocumentEdge {90cursor: ID!91node: Document!92}9394type AnswerConnection {95edges: [AnswerEdge!]!96pageInfo: PageInfo!97}9899type AnswerEdge {100cursor: ID!101node: Answer!102}103104type PageInfo {105hasNextPage: Boolean!106hasPreviousPage: Boolean!107startCursor: ID108endCursor: ID109}110111input AskDatasetInput {112dataset: ID!113query: String!114}115116type AskDatasetPayload {117answer: Answer!118membership: Membership!119incompleteDocuments: Int120}121122input CreateDatasetInput {123name: String!124}125126type CreateDatasetPayload {127dataset: Dataset!128shared: Boolean! = false129}130131input DeleteDatasetInput {132id: ID!133}134135type DeleteDatasetPayload {136dataset: ID137}138139input AddDocumentInput {140dataset: ID!141gzipB64JsonList: String!142name: String!143url: String144mime: String145group: String146}147148type AddDocumentPayload {149document: Document!150membership: Membership!151}152153input DeleteDocumentInput {154id: ID!155}156157type DeleteDocumentPayload {158document: ID159}160161enum DocumentIndexStatus {162QUEUED,163INDEXING,164COMPLETE165}166167enum DatasetAccessLevel {168PRIVATE,169SHARED,170PUBLIC171}
Example
Sample Python code for adding a document to the dataset.
1import json2import gzip3import base644from gql import Client, gql5from gql.transport.aiohttp import AIOHTTPTransport67API_EP = 'https://api.chattydocs.com/graphql'8API_KEY = '<API_KEY>' # api key from the website9DATASET_ID = '<DATASET_ID>' # id of dataset holding documents1011def compress(pages: list[str]) -> str:12data = json.dumps(pages)13bytes = data.encode('utf8')14gz = gzip.compress(bytes)15return base64.b64encode(gz).decode('utf8')1617# mutation based on the GraphQL API schema18m_add_document = gql("""19mutation AddDocumentMutation($input: AddDocumentInput!) {20addDocument(input: $input) {21document {22id23}24membership {25bytesUploadCredit26}27}28}29""")3031if __name__ == "__main__":32transport = AIOHTTPTransport(33url=API_EP,34headers={35'Authorization': f"Bearer {API_KEY}"36}37)38client = Client(transport=transport)3940# sample text41page = "this is a sample text"42pages = compress([page])43res = client.execute(m_add_document, variable_values={ 'input': {44'dataset': DATASET_ID,45'name': 'test',46'gzipB64JsonList': pages,47}})4849print(res)