You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

aicat

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.1 to 5.0.1

fns.js

26

aicat.js

@@ -6,2 +6,3 @@ #!/usr/bin/env node

import askChat from './askchat.js'
import {textOut, getDefinitions} from './fns.js'

@@ -34,8 +35,25 @@ const OPENAI_API_KEY = process.env.OPENAI_API_KEY;

const note = `
IMPORTANT: This will be used in scripts, raw file output only, no header, separators, or filename!
const sysinfo = `
You are an advaned AI software engineer, taking the place of the Linux cat command.
You MUST Use the stdOut() function with the {out} parameter.
Output ONLY what is requested, with no extra example files.
DO NOT include a filename header since there is only one file being output.
`
askChat([{role:'system', content: 'You are an advanced AI-based software engineer.',
role:'user', content: inputText + note}], model)
const note = `output raw text only: `
let {function_call} = await askChat([{role:'system', content: sysinfo,
role:'user', content: inputText}], getDefinitions(), model)
try {
let cleaned = function_call.arguments.replace(/[\x00-\x1F]+/g, '');
textOut(JSON.parse(cleaned))
} catch (e) {
console.error(e)
console.log(function_call.arguments)
}

72

askchat.js

@@ -1,34 +0,70 @@

import {yieldStream} from 'yield-stream'
import { OpenAI } from "openai-streams/node"
function getDeltas(ev) {
let deltas = []
for (let ch of ev.choices) {
deltas.push(ch.delta)
function decodeJSON(jsonStr) {
try {
// Try to parse the JSON string
const parsed = JSON.parse(jsonStr);
// If parsing succeeded, stringify the parsed object
// to handle escaped characters and return it as a string
return JSON.stringify(parsed);
} catch (err) {
// If parsing failed, handle escape characters manually and return the string
// Replacing Unicode escape sequences
const replacedUnicode = jsonStr.replace(/\\u([\d\w]{4})/gi, (match, grp) => {
return String.fromCharCode(parseInt(grp, 16));
});
// Replacing other escape sequences
const replacedEscapes = replacedUnicode
.replace(/\\b/g, '\b')
.replace(/\\f/g, '\f')
.replace(/\\n/g, '\n')
.replace(/\\r/g, '\r')
.replace(/\\t/g, '\t')
.replace(/\\\\/g, '\\')
.replace(/\\\"/g, '\"')
.replace(/\\\'/g, '\'');
return replacedEscapes;
}
if (deltas.length > 1) {
throw new Error('Received multiple deltas in an event')
}
return deltas[0]
}
async function askChat(messages, model='gpt-3.5-turbo-16k') {
let cfg = { model, messages,
temperature: 0.0, n: 1,
async function askChat(messages, functions=null, model='gpt-3.5-turbo-16k') {
const cfg = { model, messages,
temperature: 0.0, n: 1,
function_call: { name: 'textOut' },
presence_penalty: 0.6 }
if (functions) cfg.functions = functions
const stream = await OpenAI("chat", cfg, {mode: 'raw'} )
let decoder = new TextDecoder()
let content = '', function_call = {}
let lastout = ''
try {
for await (const chunk_ of stream) {
let chunk = JSON.parse(decoder.decode(chunk_))
const chunk = JSON.parse(new TextDecoder().decode(chunk_))
if (chunk.error) {
throw new Error(JSON.stringify(chunk))
return
}
chunk = getDeltas(chunk)
if (chunk?.content) process.stdout.write(chunk.content)
const deltas = chunk.choices[0].delta
for (const key in deltas) {
if (key === 'function_call') {
for (const key2 in deltas[key]) {
if (deltas[key][key2])
function_call[key2] = (function_call[key2] || '') + deltas[key][key2]
//process.stderr.write('' + deltas[key][key2] + '')
process.stderr.write(decodeJSON(deltas[key][key2]))
}
} else if (key === 'content') {
content += deltas.content
if (deltas.content) process.stderr.write(deltas.content)
}
}
}
return {content, function_call}
} catch (e) {
console.error(e)
throw e
}

@@ -35,0 +71,0 @@ }

{
"name": "aicat",
"version": "4.0.1",
"version": "5.0.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "aicat",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc