Coder Social home page Coder Social logo

kobold-api's Introduction

KoboldAPI

A Work-In-Progress Python Module for Interfacing with KoboldAI's Console API.

To test this for Free (with certain restrictions) you can use Google Colab.

Features

  • Connects to a KoboldAI Web Interface
  • Sends & Receives Text from the AI

Setup

Install Requirements

To install requirements, you can install directly from the requirements.txt file

Linux

pip3 install -r requirements.txt

Windows

python -m pip install -r requirements.txt

Usage

The Module can be imported with import koboldapi

Create an API Controller with controller = koboldapi.Controller()

See the supplied Demo.py for an example implementation

DemoDebug.py runs the Demo in Debug Mode for additional useful runtime information


API Classes

koboldapi.Controller()

Description

Class that Controls the API

API Functions

controller.Initialise(_url, _debug=False, _reset_after_input=False)

Description

Initialises and Connects the API to KoboldAI. Returns True on Success, False on Failure

Arguments

Type Name Description
STRING _url The KoboldAI Web URL To Connect To
BOOL _debug = False Print Additional Debug Information
BOOL _reset_after_input = False Whether or not to Clear the AI's Memory of the Current Text after each Input

Returns

Type Name Description
BOOL No Name Success Boolean. Returns True on Initialisation Success, and False on Initialisation Failure

controller.Close()

Description

Closes & Cleans Up the API

Arguments

No Arguments

Returns

No Returns

controller.Generate(textin, new_only=False)

Description

Generates Text from the AI using a given Input Text. Calls "controller.GetOutput()" Afterwards to Return the Generated Output Text

Arguments

Type Name Description
STRING textin The Input Text to Generate Text After
BOOL new_only = False Only return Newly Generated Text

Returns

Type Name Description
STRING No Name The Generated Text

controller.GetOutput()

Description

Gets the Text Output from the AI

Arguments

No Arguments

Returns

Type Name Description
STRING output The Generated Text

controller.ResetStory()

Description

Clears the AI's Memory of the Current Text

Arguments

No Arguments

Returns

No Returns

controller.SetMemory(memory)

Description

Set the AI's Memory to the Given Text

Arguments

Type Name Description
STRING memory The Input Text to Set the AI's Memory to

Returns

No Returns

controller.Retry()

Description

Tells the AI to Retry it's Last Generated Chunk. Calls "controller.GetOutput()" Afterwards to Return the Generated Output Text

Arguments

No Arguments

Returns

Type Name Description
STRING No Name The Generated Text

controller.CommandParser()

Description

Runs as a Background Thread to keep the Connection Alive and Handle Incoming Commands

Arguments

No Arguments

Returns

No Returns

kobold-api's People

Contributors

epicfisher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aquobus lee-b

kobold-api's Issues

How to add readlines() option to Demo.py?

Script working with latest koboldai 1.19.1 and ubuntu 18.04 under python3.8.

It's great having python access to koboldai without having to write lua userscripts.

Attempting to edit 'Demo.py' so that a text file can be read line-by-line as prompts instead of pasting each prompt to koboldai gui.

New to python and not sure how to add this code snippet or something similar:

file = open("test_prompts.txt", "r")
Lines = file.readlines()
file.close()

for line in Lines:
sentence = f'{line.strip()}'

Assume it would be added here under # Handle Special Commands?

# Take Input
textin = input("[Input " + str(controller.inputs+1) + "]\nInput: ")

# Handle Special Commands

etc.

Would appreciate help in this matter.

Thanks

Doesn't work after 1st generation

Can successfully send an input, and receive an output, once, but sending a second input hangs the API and the second output is never received.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.