Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging capabilities #32

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add logging in PromptInput
- Add logUserSearch in each branch of submitApi response checking
  • Loading branch information
mshumayl committed Apr 20, 2023
commit f75485f210503c9110b20d0038d621ae74a71048
12 changes: 12 additions & 0 deletions src/components/PromptInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const PromptInput: FC = ({ }) => {
const maxInputLength = 140;

const submitApi = api.openai.submitPrompt.useMutation();
const logApi = api.openai.logUserSearch.useMutation();

const { data: session } = useSession(); // To get quota

Expand Down Expand Up @@ -76,18 +77,29 @@ const PromptInput: FC = ({ }) => {
setToasterResult(res.result);
setToasterMessage(res.message);

//logSearch here.
//Logging can be improved by doing it on client side.
//However need to make sure that the logging db IO does not slow down response time.
const logRes = await logApi.mutateAsync({ prompt: inputValue, result: res.result, respObj: JSON.stringify(res.respObj) });

} else if (res.result && res.message) {

setToasterResult(res.result);
setToasterMessage(res.message);

//logSearch here
const logRes = await logApi.mutateAsync({ prompt: inputValue, result: res.result });

} else {

const result = "UNEXPECTED"
const message = "Unexpected input. Please try again."
setToasterResult(result);
setToasterMessage(message);

//logSearch here
const logRes = await logApi.mutateAsync({ prompt: inputValue, result: res.result });

}

setDisplayLoader((prevState) => !prevState);
Expand Down