Socket
Socket
Sign inDemoInstall

@axflow/models

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@axflow/models - npm Package Compare versions

Comparing version 0.0.19 to 0.0.20

27

dist/openai/chat.d.ts

@@ -11,13 +11,26 @@ type SharedRequestOptions = {

type RequestOptions = SharedRequestOptions;
type Function = {
name: string;
parameters: Record<string, unknown>;
description?: string;
};
type Request = {
model: string;
messages: Message[];
functions?: Array<{
functions?: Array<Function>;
tools?: Array<{
type: 'function';
function: Function;
}>;
tool_choice?: 'none' | 'auto' | {
type: 'function';
name: string;
parameters: Record<string, unknown>;
description?: string;
}>;
};
function_call?: 'none' | 'auto' | {
name: string;
};
response_format?: {
type: 'text' | 'json_object';
};
seed?: number | null;
temperature?: number | null;

@@ -34,3 +47,3 @@ top_p?: number | null;

type Message = {
role: 'system' | 'user' | 'assistant' | 'function';
role: 'system' | 'user' | 'assistant' | 'function' | 'tool';
name?: string;

@@ -42,2 +55,3 @@ content: string | null;

};
tool_call_id?: string;
};

@@ -49,5 +63,6 @@ type Response = {

model: string;
system_fingerprint: string;
choices: Array<{
index: number;
finish_reason: 'stop' | 'length' | 'function_call' | null;
finish_reason: 'stop' | 'length' | 'function_call' | 'content_filter' | 'tool_calls' | null;
message: Message;

@@ -54,0 +69,0 @@ }>;

@@ -24,2 +24,8 @@ import { MessageType, FunctionType, JSONValueType } from '@axflow/models/shared';

/**
* A function to create unique ids assigned to each message.
*
* Defaults to UUID v4 via `crypto.randomUUID`.
*/
createMessageId?: () => string;
/**
* Customize the request body sent to the API using this value. It accepts

@@ -26,0 +32,0 @@ * either a function or object.

@@ -30,6 +30,6 @@ "use strict";

var import_shared = require("@axflow/models/shared");
function uuid() {
function uuidv4() {
return crypto.randomUUID();
}
async function handleStreamingResponse(response, messagesRef, setMessages, accessor, functionCallAccessor, onNewMessage) {
async function handleStreamingResponse(response, messagesRef, setMessages, accessor, functionCallAccessor, onNewMessage, createMessageId) {
const responseBody = response.body;

@@ -47,3 +47,3 @@ if (responseBody === null) {

if (!id) {
id = uuid();
id = createMessageId();
messages = messages.concat({

@@ -65,3 +65,3 @@ id,

if (!id) {
id = uuid();
id = createMessageId();
const message = {

@@ -100,3 +100,3 @@ id,

}
async function handleJsonResponse(response, messagesRef, setMessages, accessor, functionCallAccessor, onNewMessage) {
async function handleJsonResponse(response, messagesRef, setMessages, accessor, functionCallAccessor, onNewMessage, createMessageId) {
const responseBody = await response.json();

@@ -106,3 +106,3 @@ const content = accessor(responseBody);

const newMessage = {
id: uuid(),
id: createMessageId(),
role: "assistant",

@@ -122,3 +122,3 @@ content: content ?? "",

}
async function request(prepare, messagesRef, setMessages, url, headers, accessor, functionCallAccessor, loadingRef, setLoading, setError, onError, onNewMessage, onSuccess) {
async function request(prepare, messagesRef, setMessages, url, headers, accessor, functionCallAccessor, loadingRef, setLoading, setError, onError, onNewMessage, onSuccess, createMessageId) {
if (loadingRef.current) {

@@ -139,3 +139,11 @@ return;

const handler = isStreaming ? handleStreamingResponse : handleJsonResponse;
await handler(response, messagesRef, setMessages, accessor, functionCallAccessor, onNewMessage);
await handler(
response,
messagesRef,
setMessages,
accessor,
functionCallAccessor,
onNewMessage,
createMessageId
);
onSuccess();

@@ -149,3 +157,3 @@ } catch (error) {

}
async function stableAppend(message, messagesRef, setMessages, url, headers, body, accessor, functionCallAccessor, loadingRef, setLoading, setError, onError, onNewMessage, setFunctions) {
async function stableAppend(message, messagesRef, setMessages, url, headers, body, accessor, functionCallAccessor, loadingRef, setLoading, setError, onError, onNewMessage, setFunctions, createMessageId) {
function prepare() {

@@ -171,7 +179,8 @@ const history = messagesRef.current;

onNewMessage,
() => setFunctions([])
() => setFunctions([]),
// Clear functions after each request (similar to clearing user input)
createMessageId
);
}
async function stableReload(messagesRef, setMessages, url, headers, body, accessor, functionCallAccessor, loadingRef, setLoading, setError, onError, onNewMessage) {
async function stableReload(messagesRef, setMessages, url, headers, body, accessor, functionCallAccessor, loadingRef, setLoading, setError, onError, onNewMessage, createMessageId) {
function prepare() {

@@ -213,6 +222,8 @@ const messages = messagesRef.current;

() => {
}
},
createMessageId
);
}
var DEFAULT_URL = "/api/chat";
var DEFAULT_CREATE_MESSAGE_ID = uuidv4;
var DEFAULT_ACCESSOR = (value) => {

@@ -248,2 +259,3 @@ return typeof value === "string" ? value : void 0;

const url = options.url ?? DEFAULT_URL;
const createMessageId = options.createMessageId ?? DEFAULT_CREATE_MESSAGE_ID;
const accessor = options.accessor ?? DEFAULT_ACCESSOR;

@@ -283,3 +295,3 @@ const functionCallAccessor = options.functionCallAccessor ?? DEFAULT_FUNCTION_CALL_ACCESSOR;

const newMessage = {
id: uuid(),
id: createMessageId(),
role: "user",

@@ -306,3 +318,4 @@ content: input,

onNewMessage,
setFunctions
setFunctions,
createMessageId
);

@@ -324,3 +337,4 @@ setInput("");

onError,
onNewMessage
onNewMessage,
createMessageId
);

@@ -327,0 +341,0 @@ }

{
"name": "@axflow/models",
"version": "0.0.19",
"version": "0.0.20",
"description": "Zero-dependency, modular SDK for building robust natural language applications",

@@ -199,3 +199,3 @@ "author": "Axflow (https://axflow.dev)",

},
"gitHead": "0ed2872a94807feb61d4741d928373b79cfe610a"
"gitHead": "8f059eb48c58fbd48ca0e552f4642eff7b209760"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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