Skip to content

Commit

Permalink
Changed output schema of new mutations to match existing mutations.
Browse files Browse the repository at this point in the history
  • Loading branch information
JSv4 committed May 27, 2024
1 parent aa5ad70 commit 011ab3b
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 24 deletions.
21 changes: 12 additions & 9 deletions config/graphql/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,8 @@ class Arguments:
model = graphene.String(required=True)

ok = graphene.Boolean()
language_model = graphene.Field(LanguageModelType)
message = graphene.String()
obj = graphene.Field(LanguageModelType)

@staticmethod
@login_required
Expand All @@ -1343,16 +1344,16 @@ def mutate(root, info, model):
set_permissions_for_obj_to_user(
info.context.user, language_model, [PermissionTypes.CRUD]
)
return CreateLanguageModel(ok=True, language_model=language_model)

return CreateLanguageModel(ok=True, message="SUCCESS!", obj=language_model)

class CreateFieldset(graphene.Mutation):
class Arguments:
name = graphene.String(required=True)
description = graphene.String(required=True)

ok = graphene.Boolean()
fieldset = graphene.Field(FieldsetType)
message = graphene.String()
obj = graphene.Field(FieldsetType)

@staticmethod
@login_required
Expand All @@ -1367,7 +1368,7 @@ def mutate(root, info, name, description):
set_permissions_for_obj_to_user(
info.context.user, fieldset, [PermissionTypes.CRUD]
)
return CreateFieldset(ok=True, fieldset=fieldset)
return CreateFieldset(ok=True, message="SUCCESS!", obj=fieldset)


class CreateColumn(graphene.Mutation):
Expand All @@ -1382,7 +1383,8 @@ class Arguments:
agentic = graphene.Boolean(required=True)

ok = graphene.Boolean()
column = graphene.Field(ColumnType)
message = graphene.String()
obj = graphene.Field(ColumnType)

@staticmethod
@login_required
Expand Down Expand Up @@ -1417,7 +1419,7 @@ def mutate(
set_permissions_for_obj_to_user(
info.context.user, column, [PermissionTypes.CRUD]
)
return CreateColumn(ok=True, column=column)
return CreateColumn(ok=True, message="SUCCESS!", obj=column)


class StartExtract(graphene.Mutation):
Expand All @@ -1427,7 +1429,8 @@ class Arguments:
fieldset_id = graphene.ID(required=True)

ok = graphene.Boolean()
extract = graphene.Field(ExtractType)
message = graphene.String()
obj = graphene.Field(ExtractType)

@staticmethod
@login_required
Expand All @@ -1450,7 +1453,7 @@ def mutate(root, info, corpus_id, name, fieldset_id):
# Start celery task to process extract
run_extract.delay(extract.id, info.context.user.id)

return StartExtract(ok=True, extract=extract)
return StartExtract(ok=True, message="SUCCESS!", obj=extract)


class Mutation(graphene.ObjectType):
Expand Down
128 changes: 128 additions & 0 deletions frontend/src/extracts/ColumnDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React, { useState } from "react";
import { Button, Form, Input, Select } from "semantic-ui-react";
import { useMutation, useQuery } from "@apollo/client";
import { toast } from "react-toastify";

interface ColumnDetailsProps {
column?: ColumnType;
fieldsetId: string;
onSave: () => void;
}

export const ColumnDetails: React.FC<ColumnDetailsProps> = ({
column,
fieldsetId,
onSave,
}) => {
const [query, setQuery] = useState(column?.query || "");
const [matchText, setMatchText] = useState(column?.matchText || "");
const [outputType, setOutputType] = useState(column?.outputType || "");
const [limitToLabel, setLimitToLabel] = useState(column?.limitToLabel || "");
const [instructions, setInstructions] = useState(column?.instructions || "");
const [languageModelId, setLanguageModelId] = useState(
column?.languageModel.id || ""
);
const [agentic, setAgentic] = useState(column?.agentic || false);

const { data: languageModelsData } = useQuery<{
languageModels: LanguageModelType[];
}>(GET_LANGUAGE_MODELS);

const [createColumn] = useMutation(CREATE_COLUMN);
const [updateColumn] = useMutation(UPDATE_COLUMN);

const handleSave = async () => {
try {
if (column) {
await updateColumn({
variables: {
id: column.id,
query,
matchText,
outputType,
limitToLabel,
instructions,
languageModelId,
agentic,
},
});
} else {
await createColumn({
variables: {
fieldsetId,
query,
matchText,
outputType,
limitToLabel,
instructions,
languageModelId,
agentic,
},
});
}
onSave();
toast.success("Column saved successfully");
} catch (error) {
toast.error("Error saving column");
}
};

return (
<Form>
<Form.Field>
<label>Query</label>
<Input value={query} onChange={(e) => setQuery(e.target.value)} />
</Form.Field>
<Form.Field>
<label>Match Text</label>
<Input
value={matchText}
onChange={(e) => setMatchText(e.target.value)}
/>
</Form.Field>
<Form.Field>
<label>Output Type</label>
<Input
value={outputType}
onChange={(e) => setOutputType(e.target.value)}
/>
</Form.Field>
<Form.Field>
<label>Limit to Label</label>
<Input
value={limitToLabel}
onChange={(e) => setLimitToLabel(e.target.value)}
/>
</Form.Field>
<Form.Field>
<label>Instructions</label>
<Input
value={instructions}
onChange={(e) => setInstructions(e.target.value)}
/>
</Form.Field>
<Form.Field>
<label>Language Model</label>
<Select
value={languageModelId}
options={languageModelsData?.languageModels.map((model) => ({
value: model.id,
text: model.model,
}))}
onChange={(_, { value }) => setLanguageModelId(value as string)}
/>
</Form.Field>
<Form.Field>
<label>Agentic</label>
<input
type="checkbox"
checked={agentic}
onChange={(e) => setAgentic(e.target.checked)}
/>
</Form.Field>
<Button primary onClick={handleSave}>
Save
</Button>
</Form>
);
};
17 changes: 17 additions & 0 deletions frontend/src/graphql/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,20 @@ export const REQUEST_DELETE_ANALYSIS = gql`
}
}
`;

export interface RequestCreateLanguageModelInputType {
model: string;
}

export interface RequestCreateLanguageModelOutputType {}

export const REQUEST_CREATE_LANGUAGEMODEL = gql`
mutation CreateLanguageModel($model: String!) {
createLanguageModel(model: $model) {
languageModel {
id
model
}
}
}
`;
147 changes: 147 additions & 0 deletions frontend/src/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
AnalysisType,
AnnotationLabelType,
LabelType,
LanguageModelType,
FieldsetType,
ExtractType,
} from "./types";

export interface RequestDocumentsInputs {
Expand Down Expand Up @@ -967,3 +970,147 @@ export const GET_EXPORTS = gql`
}
}
`;

export interface GetLanguageModelsOutputs {
languageModels: {
pageInfo: PageInfo;
edges: {
node: LanguageModelType;
}[];
};
}

export const GET_LANGUAGEMODELS = gql`
query GetLanguageModels {
languageModels {
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
edges {
node {
id
model
}
}
}
}
`;

export interface GetFieldsetsOutputs {
fieldsets: {
pageInfo: PageInfo;
edges: {
node: FieldsetType;
}[];
};
}

export const GET_FIELDSETS = gql`
query GetFieldsets {
fieldsets {
edges {
node {
id
owner {
id
username
}
name
description
columns {
id
query
matchText
outputType
limitToLabel
instructions
languageModel {
id
model
}
agentic
}
}
}
}
}
`;

export interface GetFieldsetOutputs {
fieldset: FieldsetType;
}

export const GET_FIELDSET = gql`
query GetFieldset($id: ID!) {
fieldset(id: $id) {
id
owner {
id
username
}
name
description
columns {
id
query
matchText
outputType
limitToLabel
instructions
languageModel {
id
model
}
agentic
}
}
}
`;

export interface GetExportsOutput {
extract: ExtractType;
}

export const GET_EXPORT = gql`
query GetExtract($id: ID!) {
extract(id: $id) {
id
corpus {
id
title
}
name
fieldset {
id
name
columns {
id
query
}
}
owner {
id
username
}
created
started
finished
stacktrace
rows {
id
column {
id
}
data
dataDefinition
started
completed
failed
stacktrace
}
}
}
`;
Loading

0 comments on commit 011ab3b

Please sign in to comment.