Skip to content

SusanBhattarai/StringableInference-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

StringableInference Python Client

A free Python client for the StringableInference API, allowing you to interact with models for chat completions and retrieve available models.

Official website and docs: https://stringableinf.com/docs


Installation

You can install the required dependencies using pip:

pip install requests

Then download or clone this repository and import the StringableInference class in your project.

Usage

Initialize the client

from stringable_inference import StringableInference

# Create a client with your chosen model
client = StringableInference(model="your_model_id")

Get available models

models = client.get_models()
print(models)

Chat completion

messages = [
    {"role": "user", "content": "Hello, can you explain Python classes?"}
]

response = client.chat_completion(messages=messages)
print(response)

Streaming Chat Completion

The chat_completion method also supports streaming responses. You can iterate over the streamed data to get partial outputs in real time. Here is an example:

from stringable_inference import StringableInference
import json

client = StringableInference(model="your_model_id")

messages = [
    {"role": "user", "content": "Explain the concept of recursion in Python."}
]

# Enable streaming
response = client.chat_completion(messages=messages, stream=True)

for line in response.iter_lines():
    if line:
        line = line.decode('utf-8')
        if line.startswith('data: '):
            data = line[6:]
            if data == '[DONE]':
                break
            chunk = json.loads(data)
            content = chunk['choices'][0]['delta'].get('content')
            if content:
                print(content, end='', flush=True)

Placeholder for image support

Currently, the API does not support chat completion with images. A method exists in the client for future support:

client.chat_completion_with_images()

Example Project

Here is an example of a simple interactive chatbot using this client (using the gpt-oss-120b model):

from stringable_inference import StringableInference

client = StringableInference(model="gpt-oss-120b")

print("Welcome to the StringableInference chatbot. Type 'exit' to quit.")

messages = []

while True:
    user_input = input("You: ")
    if user_input.lower() == "exit":
        break

    messages.append({"role": "user", "content": user_input})
    response = client.chat_completion(messages=messages)

    # Assuming the API returns a field "content" in the response
    bot_reply = response["choices"][0]["message"]["content"]
    print("Bot:", bot_reply)

    messages.append({"role": "assistant", "content": bot_reply})

About

Free Python client for the StringableInference API, supporting chat completions and model retrieval

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages