@7-docs/edge
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -5,2 +5,3 @@ import type { MetaData } from '@7-docs/shared'; | ||
query: (vector: number[]) => Promise<MetaData[]>; | ||
system?: string; | ||
prompt?: string; | ||
@@ -7,0 +8,0 @@ } |
@@ -1,3 +0,2 @@ | ||
import { uniqueByProperty } from '@7-docs/shared'; | ||
import { getPrompt } from '@7-docs/shared'; | ||
import { uniqueByProperty, getPrompt } from '@7-docs/shared'; | ||
import { OpenAI } from './openai/v1/client.js'; | ||
@@ -8,3 +7,3 @@ import { isChatCompletionModel } from './openai/v1/util.js'; | ||
export const getCompletionHandler = (options) => { | ||
const { OPENAI_API_KEY, query, prompt } = options; | ||
const { OPENAI_API_KEY, system, query, prompt } = options; | ||
if (!OPENAI_API_KEY) | ||
@@ -14,3 +13,3 @@ throw new Error('OPENAI_API_KEY required'); | ||
return async (req) => { | ||
const { query: input, embedding_model, completion_model } = await getParams(req); | ||
const { query: input, previousQueries = [], previousResponses = [], embedding_model, completion_model } = await getParams(req); | ||
if (!input) | ||
@@ -22,3 +21,6 @@ throw new Error('input required'); | ||
throw new Error('completion_model required'); | ||
const { embeddings } = await client.createEmbeddings({ model: embedding_model, input }); | ||
const { embeddings } = await client.createEmbeddings({ | ||
model: embedding_model, | ||
input: input + (previousQueries ? ' ' + previousQueries.join(' ') : '') | ||
}); | ||
const [vector] = embeddings; | ||
@@ -33,2 +35,22 @@ const queryResults = await query(vector); | ||
const messages = []; | ||
if (system) { | ||
messages.push({ | ||
role: 'system', | ||
content: system | ||
}); | ||
} | ||
if (previousQueries && previousQueries.length > 0) { | ||
previousQueries.forEach((previousQuery, index) => { | ||
messages.push({ | ||
role: 'user', | ||
content: previousQuery | ||
}); | ||
if (previousResponses && previousResponses[index]) { | ||
messages.push({ | ||
role: 'assistant', | ||
content: previousResponses[index] | ||
}); | ||
} | ||
}); | ||
} | ||
messages.push({ | ||
@@ -35,0 +57,0 @@ role: 'user', |
export * from './completion.js'; | ||
export { getDelta } from './util.js'; | ||
export type { MetaData, Params, EventData, ChatCompletionEventData, CompletionEventData, Usage } from '@7-docs/shared'; | ||
export { splitTextIntoSentences } from '@7-docs/shared'; | ||
export type { MetaData, StreamMetaData, Params, EventData, ChatCompletionEventData, CompletionEventData, Usage } from '@7-docs/shared'; |
export * from './completion.js'; | ||
export { getDelta } from './util.js'; | ||
export { splitTextIntoSentences } from '@7-docs/shared'; |
@@ -6,5 +6,13 @@ export const getParams = async (req) => { | ||
const query = url.searchParams.get('query') ?? ''; | ||
const embedding_model = url.searchParams.get('embedding_model'); | ||
const completion_model = url.searchParams.get('completion_model'); | ||
return { query: decodeURIComponent(query), embedding_model, completion_model }; | ||
const previousQueries = url.searchParams.getAll('previousQueries'); | ||
const previousResponses = url.searchParams.getAll('previousResponses'); | ||
const embedding_model = url.searchParams.get('embedding_model') ?? undefined; | ||
const completion_model = url.searchParams.get('completion_model') ?? undefined; | ||
return { | ||
query: decodeURIComponent(query), | ||
previousQueries: previousQueries.map(decodeURIComponent), | ||
previousResponses: previousResponses.map(decodeURIComponent), | ||
embedding_model, | ||
completion_model | ||
}; | ||
} | ||
@@ -11,0 +19,0 @@ else { |
{ | ||
"name": "@7-docs/edge", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Package to use 7-docs from edge functions", | ||
@@ -34,3 +34,3 @@ "homepage": "https://github.com/7-docs/7-docs", | ||
"dependencies": { | ||
"@7-docs/shared": "0.0.3" | ||
"@7-docs/shared": "0.0.4" | ||
}, | ||
@@ -37,0 +37,0 @@ "publishConfig": { |
20200
488
+ Added@7-docs/shared@0.0.4(transitive)
- Removed@7-docs/shared@0.0.3(transitive)
Updated@7-docs/shared@0.0.4