0.1.2 • Published 8 months ago

guyute v0.1.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
8 months ago

Guyute

A Helper Module for ChatGPT

Example Usage

const Chat = require('guyute');

// Load environment variables
require('dotenv').config();
// Initialize the Chat with your OpenAI API Key and Organization
Chat.init(process.env.OPENAI_API_KEY, process.env.ORGANIZATION);

var complete = (prompt) => (async function(prompt) {
    await Chat.complete(prompt);
})(prompt);

complete(`Did I connect to the ChatGPT server?`);

// Request body
// {
//   model: 'gpt-3.5-turbo-16k',
//   temperature: 0,
//   top_p: 1,
//   frequency_penalty: 0,
//   presence_penalty: 0,
//   messages: [ { role: 'user', content: 'Did I connect to the ChatGPT server?' } ]
// }

// Promise { <pending> }

// Completion
// Yes, you have successfully connected to the ChatGPT server. How can I assist you today?

// Write out the file as Markdown
Chat.saveFile('./completion.md', Chat.getLast().content);

Complete list of commands

Configuration

  • Chat.init(<apiKey: string>, <organization: string>): Initialize Chat with your OpenAI keys
  • Chat.setDefaultConfig(): Reset to the initial configuration:
    • Model: gpt-3.5-turbo
    • Temperature: 0
    • Top P: 1
    • Frequency Penalty: 0
    • Presence Penalty: 0
  • Chat.getConfig(): Print the current configurations
  • Chat.setModel(<model: string>): Set a valid model
  • Chat.setTemp(<temperature: float>): Set a valid temperature
  • Chat.setMemory(<steps: integer>): Set the number of messages from history sent with the new prompt.
  • Chat.getMemory(): Since memory is not part of the API params, this is a separate getter to return the current memory size in messages

Completions

  • await Chat.complete(<prompt: string>): Returns a completion with the current configuration.
  • Chat.getLast() -> object: Returns the last completion in history.
  • Chat.getHistory() -> object[]: Returns an array of the history of completions in reverse-chronological order.
  • Chat.saveHistory(<filePath: string>): Save all chat history to a file.
  • Chat.loadHistory(<filePath: string>): Load messages from a JSON file into the history array.
  • Chat.clearHistory(): Clear the messages in history.
  • Chat.tokenUsage(<messages: object[]) -> object: Calculates tokens used in the provided messag history array. Return an object.

Utilities

  • Chat.help(): Print the available methods on the Chat object
  • Chat.setWorkDir(<dirPath: string>): Set the working directory in the REPL
  • Chat.saveFile(<filePath: string>, <completion: string | array | object>): Save data as string to a file.
  • Chat.loadFile(<filePath: string>): Load utf8 string data (text, JSON) in from a file.
  • await Chat.fetch(<url: string>) -> string: Fetch a web page's html.
  • await Chat.extractFromHtml(<html: string>, <url: string>) -> object: Uses the npm package @extractus/article-extractor to extract content from a web page and creates stripped-down article html (like in Safari's Reader mode). Returns an object with some properties (title, description, content, etc).
  • Chat.htmlToMarkdown(<html: string>) -> string: Translates html to markdown and returns the markdown.
  • await Chat.makeDoc(<url: string>, <type: string> = 'markdown) -> string: Fetches the contents of a web page, extracts article (text content) and converts content to the specified type (i.e. markdown, text). Returns article in final format.
0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

9 months ago