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
You can install the required dependencies using pip:
pip install requestsThen download or clone this repository and import the StringableInference class in your project.
Initialize the client
from stringable_inference import StringableInference
# Create a client with your chosen model
client = StringableInference(model="your_model_id")models = client.get_models()
print(models)messages = [
{"role": "user", "content": "Hello, can you explain Python classes?"}
]
response = client.chat_completion(messages=messages)
print(response)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)Currently, the API does not support chat completion with images. A method exists in the client for future support:
client.chat_completion_with_images()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})