• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A reverse engineered Python API wrapper for the Vercel AI Playground, which provides free access to many large language models without needing an account.

Python Vercel LLM API

PyPi Version

This is a reverse engineered API wrapper for the Vercel AI Playground, which allows for free access to many LLMs, including OpenAI's ChatGPT, Cohere's Command Nightly, as well as some open source models.

Table of Contents:

Table of contents generated with markdown-toc.

Features:

  • Download the available models
  • Generate text
  • Generate chat messages
  • Set custom parameters
  • Stream the responses

Limitations:

  • User-agent is hardcoded
  • No auth support
  • Can't use "pro" or "hobby" models

Installation:

You can install this library by running the following command:

pip3 install vercel-llm-api

Documentation:

Examples can be found in the /examples directory. To run these examples, simply execute the included Python files from your terminal.

python3 examples/generate.py

Using the Client:

To use this library, simply import vercel_ai and create a vercel_ai.Client instance. You can specify a proxy using the proxy keyword argument.

Normal example:

import vercel_ai
client = vercel_ai.Client()

Proxied example:

import vercel_ai
client = vercel_ai.Client(proxy="socks5h://193.29.62.48:11003")

Note that the following examples assume client is the name of your vercel_ai.Client instance.

Downloading the Available Models:

The client downloads the available models upon initialization, and stores them in client.models.

>>> print(json.dumps(client.models, indent=2))

{
  "anthropic:claude-instant-v1": { 
    "id": "anthropic:claude-instant-v1", #the model's id
    "provider": "anthropic",             #the model's provider
    "providerHumanName": "Anthropic",    #the provider's display name
    "makerHumanName": "Anthropic",       #the maker of the model
    "minBillingTier": "hobby",           #the minimum billing tier needed to use the model
    "parameters": {                      #a dict of optional parameters that can be passed to the generate function
      "temperature": {                   #the name of the parameter
        "value": 1,                      #the default value for the parameter
        "range": [0, 1]                  #a range of possible values for the parameter
      },
      ...
    }
    ...
  }
}

Note that, since there is no auth yet, if a model has the "minBillingTier" property present, it can't be used.

A list of model IDs is also available in client.model_ids.

>>> print(json.dumps(client.model_ids, indent=2))
[
  "anthropic:claude-instant-v1", #locked to hobby tier; unusable
  "anthropic:claude-v1",         #locked to hobby tier; unusable
  "replicate:replicate/alpaca-7b",
  "replicate:stability-ai/stablelm-tuned-alpha-7b",
  "huggingface:bigscience/bloom",
  "huggingface:bigscience/bloomz",
  "huggingface:google/flan-t5-xxl",
  "huggingface:google/flan-ul2",
  "huggingface:EleutherAI/gpt-neox-20b",
  "huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
  "huggingface:bigcode/santacoder",
  "cohere:command-medium-nightly",
  "cohere:command-xlarge-nightly",
  "openai:gpt-4",                #locked to pro tier; unusable
  "openai:code-cushman-001",
  "openai:code-davinci-002",
  "openai:gpt-3.5-turbo",
  "openai:text-ada-001",
  "openai:text-babbage-001",
  "openai:text-curie-001",
  "openai:text-davinci-002",
  "openai:text-davinci-003"
]

A dict of default parameters for each model can be found at client.model_params.

>>> print(json.dumps(client.model_defaults, indent=2))
{
  "anthropic:claude-instant-v1": {
    "temperature": 1,
    "maximumLength": 200,
    "topP": 1,
    "topK": 1,
    "presencePenalty": 1,
    "frequencyPenalty": 1,
    "stopSequences": [
      "\n\nHuman:"
    ]
  },
  ...
}

Generating Text:

To generate some text, use the client.generate function, which accepts the following arguments:

  • model - The ID of the model you want to use.
  • prompt - Your prompt.
  • params = {} - A dict of optional parameters. See the previous section for how to find these.

The function is a generator which returns the newly generated text as a string.

Streamed Example:

for chunk in client.generate("openai:gpt-3.5-turbo", "Summarize the GNU GPL v3"):
  print(chunk, end="", flush=True)

Non-Streamed Example:

result = ""
for chunk in client.generate("openai:gpt-3.5-turbo", "Summarize the GNU GPL v3"):
  result += chunk
print(result)

Generating Chat Messages:

To generate chat messages, use the client.chat function, which accepts the following arguments:

  • model - The ID of the model you want to use.
  • messages - A list of messages. The format for this is identical to how you would use the official OpenAI API.
  • params = {} - A dict of optional parameters. See the "Downloading the Available Models" section for how to find these.

The function is a generator which returns the newly generated text as a string.

messages = [
  {"role": "system", "content": "You are a helpful assistant."},
  {"role": "user", "content": "Who won the world series in 2020?"},
  {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
  {"role": "user", "content": "Where was it played?"}
]
for chunk in client.chat("openai:gpt-3.5-turbo", messages):
  print(chunk, end="", flush=True)
print()

Misc:

Changing the Logging Level:

If you want to show the debug messages, simply call vercel_ai.logger.setLevel.

import vercel_ai
import logging
vercel_ai.logger.setLevel(logging.INFO)

Copyright:

This program is licensed under the GNU GPL v3. All code has been written by me, ading2210.

Copyright Notice:

ading2210/vercel-llm-api: a reverse engineered API wrapper for the Vercel AI Playground
Copyright (C) 2023 ading2210

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

More Repositories

1

poe-api

[UNMAINTAINED] A reverse engineered Python API wrapper for Quora's Poe, which provides free access to ChatGPT, GPT-4, and Claude.
Python
2,502
star
2

edpuzzle-answers

A Javascript bookmarklet that can get the answers for Edpuzzle assignments, skip the video, change the video speed, and automatically answer the questions.
JavaScript
197
star
3

openai-key-scraper

A Python script to scrape OpenAI API keys that are exposed on public Replit projects.
Python
100
star
4

openplayground-api

A reverse engineered Python API wrapper for OpenPlayground (nat.dev)
Python
78
star
5

shimboot

Boot a desktop Linux distribution from a Chrome OS RMA shim.
Shell
71
star
6

dextensify

An exploit which lets you disable most admin-installed Chrome extensions from any webpage.
HTML
53
star
7

snake-cli

Snake in the terminal, made with python and curses.
Python
30
star
8

libcurl.js

A port of libcurl to WebAssembly, for proxying HTTPS requests from the browser with full TLS encryption
JavaScript
27
star
9

video2git

A Python script that can convert a video into commits on the Github contributions graph.
Python
11
star
10

edulastic-tools

A collection of scripts for screwing around with the online testing software Edulastic.
JavaScript
11
star
11

policyedit

A Python program which is able to modify the device policies on a Chrome OS system. (WIP)
Python
9
star
12

python-static

A set of scripts to compile a static Python binary that's only 5.1MB in size, inlcuding the entire standard library.
Python
8
star
13

quickview

QuickView is a universal Chrome OS webview exploit which utilizes the QuickOffice component extension.
JavaScript
8
star
14

passmark-scraper

A Python library that can scrape various websites owned by Passmark for their benchmark results.
Python
7
star
15

ext-watcher

A Python script which provides update notifications for Chrome extensions, as well as automatic deobfuscation and diff generation.
Python
6
star
16

ascii-art

A simple program to convert images to braille unicode characters.
Python
6
star
17

chromeos-systemd

Patched systemd for Chrome OS kernels.
Shell
5
star
18

webhook-fs

turning discord into a cloud storage service (wip)
JavaScript
5
star
19

sheepy-web-port

An unofficial port of the game Sheepy: A Short Adventure to the web.
JavaScript
5
star
20

shimboot-repo

Debian repositories for Shimboot
Shell
5
star
21

lklfuse-static

Scripts for building lklfuse as a single static binary. Mount any Linux filesystem without root.
Shell
5
star
22

freedns-client

A Python API wrapper for FreeDNS.afraid.org
Python
5
star
23

youtube-comments-viewer

Shows the comments and replies for a Youtube video. Useful for bypassing restricted mode.
Python
4
star
24

openq

An open-source frontend for Q Student Connection. (abandoned)
Python
4
star
25

chatlink

Chatlink - A Minecraft to Discord chat integration script written in Python
Python
3
star
26

factorio-blahaj

A Factorio mod that replaces all fish with BLΓ…HAJ.
Lua
3
star
27

xorg-wasm

An attempt to get the X.org server running on the browser via WebAssembly. See wasm/README.md for more info.
C
3
star
28

libwisp

An implementation of a Wisp client, written in C++. (WIP)
C++
3
star
29

reviews-squared

A Chrome extension which uses an LLM to analyze product reviews. (AP Computer Science A final project)
Python
3
star
30

mcutils

A collection of utilities for interacting with Minecraft servers.
Python
2
star
31

shimboot-binaries

Scripts for building statically compiled binaries for use in the Shimboot bootloader.
Shell
2
star
32

chatresponder

A Minecraft mod that automatically runs certain commands or says things in chat.
Java
2
star
33

echoanywhere

A Chrome OS exploit demonstrating the (limited) use of chrome.echoPrivate on any webpage.
HTML
2
star
34

ti84pce-html5

A standalone version of the official TI-84 Plus CE HTML5 emulator. Emulator assets are not hosted here.
HTML
1
star
35

advent-of-code-2023

My solutions for the 2023 Advent of Code.
Python
1
star
36

uavs-entrance-assignment

My submission for the 2022 AmadorUAVs software division entrance assignment
Python
1
star
37

Hypixel-Discord-Bot

Currently a work in progress
Python
1
star
38

Discord-Unblocker

Shell
1
star
39

website-rewrite

Source code for my personal website.
HTML
1
star