diff --git a/README.md b/README.md index 8b58996..6b8f302 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Run Tests](https://github.com/slava-vishnyakov/chatlet/actions/workflows/run-tests.yml/badge.svg)](https://github.com/slava-vishnyakov/chatlet/actions/workflows/run-tests.yml) +![Chatlet Demo](docs/img.png) + Chatlet is a Python wrapper for the OpenRouter API, providing an easy-to-use interface for interacting with various AI models. Inspired by [Claudette](https://claudette.answer.ai/), which supports only Anthropic Claude. @@ -213,8 +215,10 @@ print(response) ### Using Tools ```python -def get_weather(location: str, unit: str = "celsius") -> dict: - """Get the current weather in a given location.""" +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"} chat = Chatlet() diff --git a/docs/img.png b/docs/img.png new file mode 100644 index 0000000..cd2856f Binary files /dev/null and b/docs/img.png differ diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..099177a --- /dev/null +++ b/docs/index.html @@ -0,0 +1,361 @@ + + + + + + + Chatlet Demo + + + + +
+

Chatlet Demo

+
+ +
+
+
+ from chatlet import Chatlet + +chat = Chatlet(api_key="Your-OpenRouter-API-key") +chat("Hello, how are you?") +
+
+
+ + +
+
+ Hello! I'm doing well, thank you for asking. How can I assist you today? +
+
+ + +
+
+
+ +chat("Who are you?") + +
+
+
+ + +
+
+ I'm Claude 3.5 Sonnet served via OpenRouter API through the use of Chatlet library. +
+
+ + +
+
+
+ +chat("What is Chatlet?") + +
+
+
+ + +
+
+ Chatlet is a Python wrapper for the OpenRouter API, designed to provide an easy-to-use interface for interacting with various AI models. + It's inspired by Claudette but offers support for multiple AI models beyond just Anthropic's Claude. +
+
+ + +
+
+
+ +chat("What can Chatlet do?") + +
+
+
+ + +
+
+ Chatlet has many other capabilities. Here's a list of some key features: +
    +
  • Support for multiple AI models
  • +
  • Image input support
  • +
  • Adding URLs to context
  • +
  • Conversation history management
  • +
  • Cost estimation
  • +
  • Tool usage (function calling)
  • +
  • Customizable parameters (temperature, max tokens, etc.)
  • +
  • Requiring JSON output
  • +
  • Custom headers support
  • +
+

These features make Chatlet a versatile and powerful tool for interacting with AI models through the OpenRouter API.

+
+
+ + +
+
+
+ +chat("Can it use tools?") + +
+
+
+ + +
+
+ Yes, Chatlet supports tool usage. You can define functions as tools and pass them to Chatlet. Here's a quick example: +
+
+ + +
+
+
+ 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]) + +
+
+
+ + +
+
+ (calling the tool...) +
+
+ + +
+
+
+ print(chat.tool_called) +
+
+
+ + +
+
+ get_weather +
+
+ + +
+
+
+ print(chat.tool_args) +
+
+
+ + +
+
+ {'location': 'New York City', 'unit': 'celsius'} +
+
+ + +
+
+
+ print(chat.tool_result) +
+
+
+ + +
+
+ {'temperature': 22, 'unit': 'celsius', 'condition': 'Sunny'} +
+
+ + +
+
+
+ chat("Summarize") +
+
+
+ + +
+
+ The weather in New York City is currently sunny with a temperature of 22°C (71.6°F). +
+
+ + +
+
+
+ +chat("Can I add URLs to my request for additional context?") + +
+
+
+ + +
+
+ Absolutely! Chatlet allows you to add URLs to your request for additional context. You can use the 'urls' parameter to provide web pages that the AI can reference. Here's an example of how you can do this: +
+ chat("Summarize the article I provided", + urls=["https://example.com/article" +]) +
+ This feature is particularly useful when you want the AI to analyze or discuss specific online content. +
+
+ + +
+
+
+ +chat("That's cool! Can Chatlet handle images?") + +
+
+
+ + +
+
+ Absolutely! Chatlet supports image input. You can easily pass images to your conversation using the 'images' parameter. +
+
+ + +
+
+
+ chat("What's in this image?", images=["cat.jpg"]) +
+
+
+ + +
+
+ Aww, how adorable! I see a cute kitty in the image. It looks like a fluffy tabby cat with big green eyes, sitting on a windowsill and gazing out at the world. What a purrfect picture! +
+
+ + +
+
+
+ +chat("Does Chatlet support streaming responses?") + +
+
+
+ + +
+
+ Yes, Chatlet supports streaming responses. Here's how you can use it: +
+ 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?") + +
+
+
+ + +
+
+ Yes, you can cancel the stream! Here's how you can do it: +
+ 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?") + +
+
+
+ + +
+
+ The documentation for Chatlet can be found on its GitHub repository. You can access it at: + https://github.com/slava-vishnyakov/chatlet +

This repository contains detailed information about Chatlet's features, usage examples, and installation instructions.

+
+
+ +
+
+ + \ No newline at end of file