AI Agent
API Documentation for Upcycling AI tRPC endpoint reference for question mutations and queries on upcycled images
Legacy documentation: this page describes an application that is not maintained in this repository. Content was migrated from the previous docs site and may be outdated.
api.question.mutation askQuestion (asks AI questions about an upcycled image)name type data type description question required string The question to ask about the image imageUrl required string URL of the upcycled image to ask about generationId optional string ID of the upcycle generation to associate with
status data type response successobject{ data: { answer: string }, message: "Question answered successfully" }errorTRPCError{ code: "BAD_REQUEST", message: "Invalid question data" }errorTRPCError{ code: "UNAUTHORIZED", message: "Not authorized to ask questions" }
// Client-side usage
import { api } from "~/trpc/react" ;
const apiUtils = api. useUtils ();
// Using React Query mutation
const askQuestionMutation = api.question.askQuestion. useMutation ({
onSuccess : ({ data }) => setAnswer (data.answer),
onError : () => toastService. error ({ message: "Failed to get answer" }),
onSettled : () => void apiUtils.refinement. invalidate (),
});
// Example call
const handleAskQuestion = () =>
askQuestionMutation. mutate ({
imageUrl: upcycleImage,
question: question,
generationId: generationId,
});
api.question.query getQuestions (retrieves questions for a specific generation)name type data type description generationId required string ID of the upcycle generation to query for
status data type response successarrayArray of question objects with their responses, sorted by newest first errorTRPCError{ code: "BAD_REQUEST", message: "Invalid generation ID" }errorTRPCError{ code: "UNAUTHORIZED", message: "Not authorized to view questions" }
// Client-side usage
import { api } from "~/trpc/react" ;
// Using React Query hook
const getQuestions = api.question.getQuestions. useQuery (generationId, {
enabled: !! generationId,
});
// Accessing the data
return (
< div >
{ getQuestions ?. isPending ? (
< Spinner />
) : getQuestions ?. data ?. length > 0 ? (
getQuestions ?. data ?. map (( q ) => (
< QuestionCard key = {q.id} question = {q.question} answer = {q.llmResponse} date = {q.createdAt} />
))
) : (
< p > No questions asked yet .</ p >
)}
</ div >
);