Silver-Spy
Silver-Spy•17mo ago

How can i store the output from a function i am running

Hey guys im running LLama using relicate and everything is working and when i console log output i get the result back from the API using actions from convex. I want to now store this data but i cant firgure out how i can store the value in a new table. Here is my function:
// Import necessary modules
import Replicate from 'replicate';
import { action, internalAction, mutation } from './_generated/server';
import { api, internal } from './_generated/api';
import { v } from 'convex/values';

export const runLlama2 = action({
handler: async ({},{prompt,}) => {
// Initialize Replicate with your API token
const replicate = new Replicate({
auth: ,
});

try {
// Run Llama 2 with Replicate
const output = await replicate.run(
'meta/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1',
{
input: {
prompt:prompt,
},
}
);

console.log('Llama 2 output:', output);

return output;

} catch (error) {
console.error('Error running Llama 2:', error);
throw new Error('Failed to run Llama 2');
}
},
});
// Import necessary modules
import Replicate from 'replicate';
import { action, internalAction, mutation } from './_generated/server';
import { api, internal } from './_generated/api';
import { v } from 'convex/values';

export const runLlama2 = action({
handler: async ({},{prompt,}) => {
// Initialize Replicate with your API token
const replicate = new Replicate({
auth: ,
});

try {
// Run Llama 2 with Replicate
const output = await replicate.run(
'meta/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1',
{
input: {
prompt:prompt,
},
}
);

console.log('Llama 2 output:', output);

return output;

} catch (error) {
console.error('Error running Llama 2:', error);
throw new Error('Failed to run Llama 2');
}
},
});
All the mutations and actions are working i just need to store the action result into a table
2 Replies
jamwt
jamwt•17mo ago
how about: instead of return output pass the output to a mutation and that mutation will write to whatever table you'd like in addition, if your web app would update with this llama 2 result (it's bound on useQuery), it should just automatically update and show the result after this mutation runs
Silver-Spy
Silver-SpyOP•17mo ago
Thank you so much i couldnt figure it out for the longest time @jamwt 🫂

Did you find this page helpful?