Silver-SpyS
Convex Community3y ago
4 replies
Silver-Spy

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');
    }
  },
});

All the mutations and actions are working i just need to store the action result into a table
Was this page helpful?