Open dsebastien opened 3 weeks ago
Another alternative: https://github.com/nicholascelestin/replicate-js
That one also supports customizing how requests are being made:
// Example using axios instead of fetch
import axios from 'axios';
const httpClient = {
// Method arguments use object destructuring
// All arguments are optional, can be in any order, but cannot be renamed
get: async ({url, token, event}) => {
const response = await axios.get(url, {headers: {'Authorization': `Token ${token}`}})
console.log(`Handling ${event} event`); // Possible values: getModel, getPrediction
return response.data;
},
post: async ({url, body, token, event}) => {
const response = await axios.post(url, body, {headers: {'Authorization': `Token ${token}`}})
console.log(`Handling ${event} event`); // Possible values: startPrediction
return response.data;
}
}
const replicateAxios = new Replicate({pollingInterval:5000, httpClient: httpClient});
const model = await replicateAxios.models.get("replicate/hello-world") // getModel event
const prediction = await model.predict({ text: "test"});// startPrediction, getPrediction events
Currently, we use the official replicate library, which requires node (cfr https://github.com/replicate/replicate-javascript?tab=readme-ov-file#replicate-nodejs-client). This plugin is thus not compatible with mobile versions of Obsidian.
We could switch to this: https://github.com/zebreus/replicate-api Unofficial, but supposed to work both in the browser and in node.
It's possible to pass a custom FetchFunction, so we could pipe the Obsidian fetchUrl function (?): https://github.com/zebreus/replicate-api/blob/master/src/helpers/makeApiRequest.ts