-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
647 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
GraphQLObjectType, | ||
GraphQLInterfaceType, | ||
GraphQLString, | ||
GraphQLNonNull, | ||
GraphQLID, | ||
GraphQLInt, | ||
} from 'graphql'; | ||
|
||
import { createConnectionType } from 'graphql/util'; | ||
import Node from '../interfaces/Node'; | ||
import AIResponseTypeEnum from './AIResponseTypeEnum'; | ||
import AIResponseStatusEnum from './AIResponseStatusEnum'; | ||
import User, { userFieldResolver } from './User'; | ||
|
||
const commonAiResponseFields = { | ||
id: { type: new GraphQLNonNull(GraphQLID) }, | ||
|
||
docId: { | ||
description: 'The id for the document that this AI response is for.', | ||
type: GraphQLID, | ||
}, | ||
|
||
type: { | ||
description: 'AI response type', | ||
type: new GraphQLNonNull(AIResponseTypeEnum), | ||
}, | ||
|
||
user: { | ||
description: 'The user triggered this AI response', | ||
type: User, | ||
resolve: userFieldResolver, | ||
}, | ||
|
||
status: { | ||
description: 'Processing status of AI', | ||
type: new GraphQLNonNull(AIResponseStatusEnum), | ||
}, | ||
|
||
text: { | ||
description: 'AI response text. Populated after status becomes SUCCESS.', | ||
type: GraphQLString, | ||
}, | ||
|
||
createdAt: { type: new GraphQLNonNull(GraphQLString) }, | ||
updatedAt: { type: GraphQLString }, | ||
}; | ||
|
||
const AIResponse = new GraphQLInterfaceType({ | ||
name: 'AIResponse', | ||
description: 'Denotes an AI processed response and its processing status.', | ||
interfaces: [Node], | ||
fields: commonAiResponseFields, | ||
resolveType(doc) { | ||
switch (doc.type) { | ||
case 'AI_REPLY': | ||
return AIReply; | ||
} | ||
}, | ||
}); | ||
|
||
export const AIReply = new GraphQLObjectType({ | ||
name: 'AIReply', | ||
description: 'A ChatGPT reply for an article with no human fact-checks yet', | ||
interfaces: [Node, AIResponse], | ||
fields: { | ||
...commonAiResponseFields, | ||
usage: { | ||
description: | ||
'The usage returned from OpenAI. Populated after status becomes SUCCESS.', | ||
type: new GraphQLObjectType({ | ||
name: 'OpenAICompletionUsage', | ||
fields: { | ||
promptTokens: { type: new GraphQLNonNull(GraphQLInt) }, | ||
completionTokens: { type: new GraphQLNonNull(GraphQLInt) }, | ||
totalTokens: { type: new GraphQLNonNull(GraphQLInt) }, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}); | ||
|
||
export const AIResponseConnection = createConnectionType( | ||
'AIResponseConnection', | ||
AIResponse | ||
); | ||
|
||
export default AIResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GraphQLEnumType } from 'graphql'; | ||
|
||
export default new GraphQLEnumType({ | ||
name: 'AIResponseStatusEnum', | ||
values: { | ||
LOADING: { value: 'LOADING' }, | ||
SUCCESS: { value: 'SUCCESS' }, | ||
ERROR: { value: 'ERROR' }, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { GraphQLEnumType } from 'graphql'; | ||
|
||
export default new GraphQLEnumType({ | ||
name: 'AIResponseTypeEnum', | ||
values: { | ||
AI_REPLY: { | ||
description: | ||
'The AI Response is an automated analysis / reply of an article.', | ||
value: 'AI_REPLY', | ||
}, | ||
// TBA: speach-to-text result, OCR result, reply review response, etc | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.