I've wanted to try my hand into working with AI and opted to try OpenAI or Olama. I'm currently using Sveltekit to create my website. I've followed a few courses where they used a virual enviroment while creating a Python file, This way you run the LLM on a local machine so that you don't need to top up the amount of tokens you are using. Sadly most of it is in Python and not node.js
I normaly use sveltekit when creating projects so with that info I tried to do the same thing but with node.js. However I cannot get any type of localization to work, only a fetch to the openAI API.
I've heard about something called LM Studio that I believe runs some type of endpoint for you to connect to, something similar to a local enviroment? but i'm not entirely sure how it works or what it provides.
I've tried Using Python as a backend route but didn't make much sense using it in sveltekit,i've also tried creating a python project which works, but the idea was to get it working within a node.js project for example sveltekit.
This is the code i currently have which fetches the OpenAI API, but again would cost for each use
import { env } from '$env/dynamic/private';export const actions = { default: async ({ request }) => { const form = await request.formData(); const prompt = form.get('prompt'); const openai_key = env.OPENAI_KEY2; const body = { model: 'gpt-3.5-turbo', messages: [{ role: 'user', content: prompt }] }; const response = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: {'Content-Type': 'application/json', Authorization: `Bearer ${openai_key}` }, body: JSON.stringify(body) }); const data = await response.json(); console.log(data); }};
I feel like i've hit a wall on areas to try/research as i've only been looking into AI 2 days ago.
I'm going to try looking more into the LM Studio path, but any advice or direction would help greatly!
If there isn't a way I think maybe just topping up the OpenAI account so that I can progress might be the best option.