New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@7-docs/shared

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@7-docs/shared - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

2

dist/index.d.ts

@@ -5,2 +5,2 @@ export * from './array.js';

export * from './string.js';
export type * from './types.js';
export type { MetaData, Params, EventData, ChatCompletionEventData, CompletionEventData, Usage } from './types.js';

@@ -1,1 +0,7 @@

export declare const getPrompt: (content: string[], query: string) => string;
type GetPrompt = (options: {
context: string[];
query: string;
prompt?: string;
}) => string;
export declare const getPrompt: GetPrompt;
export {};
import { OPENAI_MAX_COMPLETION_TOKENS, OPENAI_TOKENS_FOR_COMPLETION } from './constants.js';
const intro = `Answer the question as truthfully as possible using the provided context, and if the answer is not contained within the text below, say "Sorry, I don't have that information.".`;
const defaultPrompt = `Answer the question as truthfully as possible using the provided context, and if the answer is not contained within the text below, say "Sorry, I don't have that information.". Context: {CONTEXT} Question: {QUERY} Answer:`;
const getEstimatedTokens = (value) => Math.round(value.length / 4);
const _getPrompt = (context, query) => {
return `${intro}\n\nContext:${context}\n\nQuestion: ${query}\n\nAnswer:`;
};
const availableTokens = OPENAI_MAX_COMPLETION_TOKENS - OPENAI_TOKENS_FOR_COMPLETION - getEstimatedTokens(_getPrompt('', ''));
const getContext = (text) => {
const _getPrompt = (context, query, prompt) => (prompt ?? defaultPrompt).replace('{CONTEXT}', context).replace('{QUERY}', query).replaceAll('\n', ' ').trim();
const getContext = (text, availableTokens) => {
const [, promptText] = text.reduce(([remainingTokens, context], text) => {

@@ -17,5 +14,5 @@ const tokens = getEstimatedTokens(text);

};
export const getPrompt = (content, query) => {
const context = getContext(content);
return _getPrompt(context, query);
export const getPrompt = ({ context, query, prompt }) => {
const availableTokens = OPENAI_MAX_COMPLETION_TOKENS - OPENAI_TOKENS_FOR_COMPLETION - getEstimatedTokens(_getPrompt('', '', prompt));
return _getPrompt(getContext(context, availableTokens), query, prompt);
};
export interface MetaData {
filePath: string;
url: string;
content: string;
title: string;
header?: string;
filePath: string;
url: string;
content: string;
title: string;
header?: string;
}
export interface Usage {
prompt_tokens: number;
completion_tokens?: number;
total_tokens: number;
prompt_tokens: number;
completion_tokens?: number;
total_tokens: number;
}
export type Params = Record<string, string | null>;
interface BaseEventData {
id: string;
created: number;
model: string;
id: string;
created: number;
model: string;
}
export interface ChatCompletionEventData extends BaseEventData {
object: 'chat.completion.chunk';
choices: {
delta: {
content: string;
};
}[];
object: 'chat.completion.chunk';
choices: {
delta: {
content: string;
};
}[];
}
export interface CompletionEventData extends BaseEventData {
object: 'text_completion';
choices: {
text: string;
index: number;
finish_reason: string;
}[];
object: 'text_completion';
choices: {
text: string;
index: number;
finish_reason: string;
}[];
}
export type EventData = CompletionEventData | ChatCompletionEventData;
export type Metadata = {
title: string;
url: string;
title: string;
url: string;
};
export {};
{
"name": "@7-docs/shared",
"version": "0.0.2",
"version": "0.0.3",
"description": "Shared utilities for 7-docs core and packages",

@@ -18,3 +18,6 @@ "homepage": "https://github.com/7-docs/7-docs",

"type": "module",
"exports": "./dist/index.js",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"files": [

@@ -21,0 +24,0 @@ "dist"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc