feat: add support for using previous messages for query generation

This commit is contained in:
Jun Siang Cheah
2024-05-12 20:45:44 +08:00
parent 654cc09128
commit 466b3e3637
4 changed files with 27 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
import { OPENAI_API_BASE_URL } from '$lib/constants';
import { promptTemplate } from '$lib/utils';
import { type Model, models, settings } from '$lib/stores';
export const getOpenAIUrls = async (token: string = '') => {
let error = null;
@@ -322,15 +323,14 @@ export const generateTitle = async (
export const generateSearchQuery = async (
token: string = '',
// template: string,
model: string,
previousMessages: string[],
prompt: string,
url: string = OPENAI_API_BASE_URL
): Promise<string | undefined> => {
let error = null;
// TODO: Allow users to specify the prompt
// template = promptTemplate(template, prompt);
// Get the current date in the format "January 20, 2024"
const currentDate = new Intl.DateTimeFormat('en-US', {
@@ -344,8 +344,6 @@ export const generateSearchQuery = async (
day: '2-digit'
}).format(new Date());
// console.log(template);
const res = await fetch(`${url}/chat/completions`, {
method: 'POST',
headers: {
@@ -409,7 +407,10 @@ Current Question: Where is it being hosted?`
},
{
role: 'user',
content: `Current Question: ${prompt}`
content:
(previousMessages.length > 0
? `Previous Questions:\n${previousMessages.join('\n')}\n\n`
: '') + `Current Question: ${prompt}`
}
],
stream: false,

View File

@@ -39,7 +39,7 @@ export const showSidebar = writable(false);
export const showSettings = writable(false);
export const showChangelog = writable(false);
type Model = OpenAIModel | OllamaModel;
export type Model = OpenAIModel | OllamaModel;
type OpenAIModel = {
id: string;