from chatlet import Chatlet
chat = Chatlet(api_key="Your-OpenRouter-API-key")
chat("Hello, how are you?")
chat("Who are you?")
chat("What is Chatlet?")
chat("What can Chatlet do?")
These features make Chatlet a versatile and powerful tool for interacting with AI models through the OpenRouter API.
chat("Can it use tools?")
def get_weather(
location: str, # The location to get the weather for
unit: str = "celsius" # The unit to return the temperature in
) -> dict: # Get the current weather in a given location
return {"temperature": 22, "unit": unit, "condition": "Sunny"}
# Note: All comments are passed to the model via docments
chat = Chatlet()
response = chat("What's the weather like in New York City?",
tools=[get_weather])
print(chat.tool_called)
print(chat.tool_args)
print(chat.tool_result)
chat("Summarize")
chat("Can I add URLs to my request for additional context?")
chat("Summarize the article I provided",
urls=["https://example.com/article"
])
chat("That's cool! Can Chatlet handle images?")
chat("What's in this image?", images=["cat.jpg"])
chat("Does Chatlet support streaming responses?")
chat = Chatlet()
stream = chat("Tell me a story in 10 words.", stream=True)
for chunk in stream:
print(chunk, end='', flush=True)
# call `chat.cancel()` at any time to stop the streaming request
chat("Can I cancel the stream?")
chat = Chatlet()
stream = chat("Tell me a very long story.", stream=True)
for chunk in stream:
print(chunk, end='', flush=True)
if some_condition: # e.g., user input or time limit
chat.cancel()
break
You can call chat.cancel()
at any time to stop the streaming request. This allows you to interrupt the stream based on certain conditions, such as user input or a time limit.
chat("Where are the docs?")
This repository contains detailed information about Chatlet's features, usage examples, and installation instructions.