Hello World ExampleΒΆ

Simple chat completion example to get started:

 1#!/usr/bin/env python
 2"""
 301 Hello World - Simplest Possible Chat Call
 4
 5This is the absolute simplest way to use Lexilux.
 6Perfect for your first chat completion!
 7
 8Level: Beginner
 9"""
10
11from config_loader import get_chat_config, parse_args
12
13from lexilux import Chat
14
15
16def main():
17    """Run the simplest possible chat example."""
18    # Load configuration
19    args = parse_args()
20    try:
21        config = get_chat_config(config_path=args.config)
22    except (FileNotFoundError, KeyError) as e:
23        print(f"Configuration error: {e}")
24        print("\nUsing placeholder values. Please configure test_endpoints.json")
25        config = {
26            "base_url": "https://api.example.com/v1",
27            "api_key": "your-api-key",
28            "model": "gpt-4",
29        }
30
31    # Create a chat client
32    chat = Chat(**config)
33
34    # Make a simple chat call
35    result = chat("Hello, world!")
36
37    # Print the response
38    print("=" * 50)
39    print("Response:", result.text)
40    print("=" * 50)
41    print("Tokens used:", result.usage.total_tokens)
42    print("Finish reason:", result.finish_reason)
43
44
45if __name__ == "__main__":
46    main()