Adding Ollama Support

This commit is contained in:
Lucas Bock
2024-10-12 18:44:23 -05:00
parent 1bed63a4af
commit 6e25780b25
53 changed files with 2260 additions and 1079 deletions

View File

@ -3,6 +3,8 @@
import { t } from "@lingui/macro";
import { openai } from "./client";
import { useOpenAiStore } from "@/client/stores/openai";
import { DEFAULT_MAX_TOKENS, DEFAULT_MODEL } from "@/client/constants/llm";
const PROMPT = `You are an AI writing assistant specialized in writing copy for resumes.
Do not return anything else except the text you improved. It should not begin with a newline. It should not have any prefix or suffix text.
@ -17,10 +19,12 @@ type Mood = "casual" | "professional" | "confident" | "friendly";
export const changeTone = async (text: string, mood: Mood) => {
const prompt = PROMPT.replace("{mood}", mood).replace("{input}", text);
const { model, maxTokens } = useOpenAiStore.getState();
const result = await openai().chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
max_tokens: 1024,
model: model ?? DEFAULT_MODEL,
max_tokens: maxTokens ?? DEFAULT_MAX_TOKENS,
temperature: 0.5,
stop: ['"""'],
n: 1,

View File

@ -4,7 +4,7 @@ import { OpenAI } from "openai";
import { useOpenAiStore } from "@/client/stores/openai";
export const openai = () => {
const { apiKey } = useOpenAiStore.getState();
const { apiKey, baseURL } = useOpenAiStore.getState();
if (!apiKey) {
throw new Error(
@ -12,6 +12,14 @@ export const openai = () => {
);
}
if(baseURL) {
return new OpenAI({
baseURL,
apiKey,
dangerouslyAllowBrowser: true,
});
}
return new OpenAI({
apiKey,
dangerouslyAllowBrowser: true,

View File

@ -3,6 +3,8 @@
import { t } from "@lingui/macro";
import { openai } from "./client";
import { useOpenAiStore } from "@/client/stores/openai";
import { DEFAULT_MAX_TOKENS, DEFAULT_MODEL } from "@/client/constants/llm";
const PROMPT = `You are an AI writing assistant specialized in writing copy for resumes.
Do not return anything else except the text you improved. It should not begin with a newline. It should not have any prefix or suffix text.
@ -15,10 +17,12 @@ Revised Text: """`;
export const fixGrammar = async (text: string) => {
const prompt = PROMPT.replace("{input}", text);
const { model, maxTokens } = useOpenAiStore.getState();
const result = await openai().chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
max_tokens: 1024,
model: model ?? DEFAULT_MODEL,
max_tokens: maxTokens ?? DEFAULT_MAX_TOKENS,
temperature: 0,
stop: ['"""'],
n: 1,

View File

@ -3,6 +3,8 @@
import { t } from "@lingui/macro";
import { openai } from "./client";
import { useOpenAiStore } from "@/client/stores/openai";
import { DEFAULT_MAX_TOKENS, DEFAULT_MODEL } from "@/client/constants/llm";
const PROMPT = `You are an AI writing assistant specialized in writing copy for resumes.
Do not return anything else except the text you improved. It should not begin with a newline. It should not have any prefix or suffix text.
@ -15,10 +17,12 @@ Revised Text: """`;
export const improveWriting = async (text: string) => {
const prompt = PROMPT.replace("{input}", text);
const { model, maxTokens } = useOpenAiStore.getState();
const result = await openai().chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
max_tokens: 1024,
model: model ?? DEFAULT_MODEL,
max_tokens: maxTokens ?? DEFAULT_MAX_TOKENS,
temperature: 0,
stop: ['"""'],
n: 1,