#trpc
1 messages · Page 1 of 1 (latest)
Based on the knowledge sources provided, there are several issues reported on the Next.js GitHub repository related to the fetch function failing. However, none of these issues specifically mention tRPC.
The error message "fetch failed" could be due to various reasons such as network issues, server-side errors, or incorrect usage of the fetch function. It's also possible that the error is related to the specific configuration or usage of tRPC in your application.
Unfortunately, without more specific information about your issue and the context in which it's occurring, it's difficult to provide a more precise answer.
I would recommend checking the following:
- Ensure that your server is running and accessible when you're making the fetch request.
- Check the network tab in your browser's developer tools to see if there's more information about the failed request.
- Make sure you're correctly using the
useMutationfunction from tRPC.
If you're still having trouble, consider creating an issue on the Next.js GitHub repository (https://github.com/vercel/next.js/issues) or the tRPC repository, providing as much detail as possible about your issue.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@brazen parcel kapa.ai is still learning and improving, please let us know how it did by reacting below
@obtuse dew citations.tsx
export const Citations = () => {
const [buttonLoading, setButtonLoading] = useState(false);
const [citation, setCitation] = useState<string>("");
const mutate = api.citations.createCitationPromptThingy.useMutation();
const createCitation = async () => {
if (buttonLoading) return;
setButtonLoading(true);
if (!citation) {
setButtonLoading(false);
return;
}
console.log(citation);
const d = await mutate.mutateAsync({
roblox: "vapqrr",
whattheydo: citation,
});
console.log(d);
setButtonLoading(false);
};
citation.ts (trpc)
export const citationRouter = createTRPCRouter({
createCitationPromptThingy: protectedProcedure
.input(
z.object({
roblox: z.string(),
whattheydo: z.string(),
}),
)
.mutation(async ({ ctx, input }) => {
const client = new OpenAI({
apiKey: "",
baseURL: "http://localhost:1234/v1",
});
const { roblox, whattheydo } = input;
// const completion = await client.chat.completions.create({
// model: "gemma-2-9b-it-GGUF",
// messages: [
// {
// role: "system",
// content: ai.prompt,
// },
// {
// role: "user",
// content: whattheydo,
// },
// ],
// });
// const response = completion.choices[0]?.message.content;
const req = await fetch("http://localhost:1234/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
messages: [
{
role: "system",
content: `Only respond with what you think the fine or consequence should be from the message provided. For example:
User: Reckless Driving 5+ MPH over the speed limit
Your Response: ...
You should keep the answer to JUST what you think should happen:
e.g.: $000 fine or a 60 second jail, or a vehicle impounding
Keep the time durations to a max of 360 seconds. Community service isn't an option. It's either a Fine, Jailing, or Impoundment or Death Penalty
Verbal warnings will be used for simple stuff, like 2-5mph over.
Instead of a 24h impoundment, just say one session, that should be the only duration.
Act as human, as possible Be strict.
Don't add these comments like Let me know etc. Quit it.
STOP RESPONDING WITH THAT BULLSHIT.`,
},
{
role: "user",
content: "Reckless Driving",
},
],
}),
});
const response = await req.json();
console.log(response);
return response;
}),
});
Let me check the knowledge base for you. One moment! :books:
Based on the code snippets you've provided, it seems like you're using tRPC to create a mutation that makes a fetch request to an AI endpoint.
In your Citations component, you're using the useMutation hook from tRPC to call the createCitationPromptThingy mutation. When the createCitation function is called, it checks if a citation exists and if the button isn't already loading. If these conditions are met, it calls the mutation with the roblox and whattheydo parameters.
In your citationRouter, you've defined the createCitationPromptThingy mutation. This mutation takes an input object with roblox and whattheydo properties, both of which are strings. It then makes a fetch request to the AI endpoint with a specific message structure.
If you're encountering issues with this setup, here are a few things you could check:
- Ensure that your server is running and accessible when you're making the fetch request.
- Check the network tab in your browser's developer tools to see if there's more information about the failed request.
- Make sure you're correctly using the
useMutationfunction from tRPC. - Check the console logs for any errors or unexpected values.
- Ensure that the
robloxandwhattheydovalues are being correctly passed to the mutation.