Skip to content

cognitivecomputations/chat-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chat-logger

Chat Logger

This proxy allows you to record your chats to create datasets based on your conversations with any Chat LLM.

Features

  • Maintains OpenAI API compatibility
  • Supports both streaming and non-streaming responses
  • Automatic request logging to JSONL format
  • Configurable model selection
  • Error handling with detailed responses
  • Request/response logging with thread-safe implementation

Setup

  1. Clone the repository
  2. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file based on .env.local:
OPENAI_API_KEY=your_api_key_here
OPENAI_ENDPOINT=https://api.openai.com/v1
OPENAI_MODEL=gpt-4

Usage

  1. Start the server:
python proxy.py
  1. The server will run on port 5001 by default (configurable via PORT environment variable)

  2. Use the proxy exactly as you would use the OpenAI API, but point your requests to your local server:

curl http://localhost:5001/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key" \
  -d '{
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key
  • OPENAI_ENDPOINT: The base URL for the OpenAI API
  • OPENAI_MODEL: The default model to use for requests
  • PORT: Server port (default: 5001)

Logging

All requests and responses are automatically logged to logs.jsonl in JSONL format. The logging is thread-safe and includes both request and response content.

Error Handling

The proxy includes comprehensive error handling that:

  • Preserves original OpenAI error messages when available
  • Provides detailed error information for debugging
  • Maintains proper HTTP status codes

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages