npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tzap

v0.9.4

Published

Tzap Dev Tools: Code generation style transfer with GPT.

Downloads

87

Readme

Tzap: Find what you need, prompt with it! Embeddings and prompts combined!

Discord Official Page NPM Twitter Follow

What is Tzap?

Tzap is tool to make it possible for you to search just about anything from "endpoints" and "color" to full code snippets or use cases to find the most relevant files.

When you run the tzap prompt command, Tzap combines your prompt with the extracted context and generates a suitable prompt for the GPT model. This allows GPT to generate both very complex and highly specific code.

Demo (prompt: How would you expose tzap through a golang echo backend?)

prompt demo

Comparing generation to existing code:

prompt demo

Quick install

# Choose how to install. curl, npm, npx
curl https://tzap.io/sh | bash
# npm install -g tzap
# npx tzap

# Provide the apikey. env variable or .env file
export OPENAI_APIKEY=<apikey>
# echo "OPENAI_APIKEY=<apikey>" > .env

tzap init
# Adapt below to your project!
tzap search "where is the background color defined?"
tzap search "using endpoints"

tzap prompt "add a email verification regexp to the user field"

Resources

Notes:

Tzap is in a beta phase. Tzap has the power to overwrite existing files, so commit local changes first. Using embeddings will upload most files to OpenAIs servers. (Alternative solutions are being looked into) Using external APIs incurs small costs, read Cost Estimation.

Tzap provides a few commands:

  • tzap init: Initializes Tzap in your project directory, creating necessary configuration files and folders.
  • tzap prompt: Generates code suggestions based on the provided prompt and your project's context.
  • other fun commands
    • tzap commit: Makes a git commit suggestion based on diff. It does not use wide context.
    • tzap ghrelease: A bit hardcoded and undocumented, makes release notes for github.

Key Features

  • Simple CLI tool
  • Automate GPT copy-pasting tasks
  • Effortlessly build context and pull in files
  • Local vector database

How It Works

Tzap works in the following steps:

  • Init: Initializing a project is done with tzap init. In order to limit costs, Tzap requires a specification of both what to ignore and is allowed to include. .gitignore and .tzapignore is FIRST applied and removes all file matches. THEN .tzapinclude further filters out all NON-MATCHES.
  • Indexing: When you run tzap prompt, Tzap builds a cache, indexes your project directory and builds a vector database of your code files. This allows Tzap to efficiently search for relevant code snippets during the code generation process. Note: This process uploads all file matches to OpenAI.
  • Prompt Generation: Tzap takes the prompt string that describes the code you want to generate. Tzap combines your prompt with the extracted context information, such as interfaces, types, ORM, and libraries, to build a specific prompt for the GPT model.
  • Code Generation: Tzap sends the generated prompt to the GPT model, which produces code suggestions based on the provided context and the prompt. These suggestions are then presented to you for further evaluation and integration into your codebase.

By automating code generation tasks and leveraging GPT's language capabilities, Tzap simplifies the process of writing code and helps you push features consistent code styles within your project.

Tips

The typical use case for tzap prompt is when:

  1. there is some existing code (does not have to be related code to the prompt, like existing datamodels or endpoints)
  2. there is some idea of a starting point (How do I create an endpoint)
  3. there is some idea of the goal (that enables customers to change subscription)
  4. run tzap prompt "How do I create an endpoint that enables customers to change subscription"
  5. based on the prompt, GPT might provide a general non-code answer. In such case, instruct it with feedback.

Getting Started

Installation and Usage

To install and run Tzap, simply use the following commands:

npm install -g tzap

or

npx tzap

or

curl https://tzap.io/sh | bash 

Once you have installed Tzap, you can start using it immediately by typing tzap in your terminal.

Tzap Embedding Prompt CLI

The tzap prompt command allows you to generate code or content based on embedding search from your existing code. This enables GPT to incorporate your code knowledge and provide more relevant and accurate outputs. By providing additional context, GPT can generate even more accurate code snippets or content based on the provided files.

  1. Use the tzap embeddingprompt command with the following syntax:
tzap prompt "<prompt>" [--inspiration=filepath1,filepath2,...]
  • <prompt>: The text prompt you want to provide to GPT. Make your prompt as clear as possible and enclose it in double quotes.
  • -i: (Optional) A flag followed by a comma-separated list of file paths, which are used as inspiration files to enhance GPT's general understanding.
  • --temperature: Fine-tune the temperature.
  • -s searchQuery: Split the search and the prompt.
  • -f promptFile: Use a file as a prompt.

For example, you can run the following command to generate code based on a prompt:

tzap prompt "Generate a function that calculates the sum of two numbers" --inspiration=myFile.js,anotherFile.js

Feel free to customize <prompt> and provide your own inspiration files to get more accurate code snippets or content.

Cost Estimation

Using embeddings and external APIs comes with certain costs. Here's a breakdown of those costs:

Embeddings

Initialization of embeddings for this project cost: $0.04 (Run once). (200 files, 6,500 lines of code) Re-fetch when generating with new code changes: $0.0004 per 1,000 "words/tokens"

GPT Model

You can choose to use GPT-4 or GPT-3.5 (default usually).

The maximum cost per file for GPT-4 is $0.1 (8,000 "word/token" limit). The maximum cost per file for GPT-3.5 is $0.008 (4,000 "word/token" limit).

It is important to understand and manage these costs while using Tzap.