Caching and replaying man-in-the-middle proxy for OpenAI APIs
Project description
Rechat
Rechat is a caching and replaying man-in-the-middle proxy for OpenAI's APIs, it provides inspection and debugging layer, particularly useful for quick inspection of interactions of existing clients, developing multi-request workflows, and benchmarks.
Rechat is for you, if you ever wanted to:
- speed up your code that makes repeated calls to OpenAI APIs
- quickly inspect what is being sent to OpenAI APIs
- emulate an endpoint with pre-recorded (or pre-defined) responses
Quickstart
pip install rechat(dev:pip install git+https://gitlab-master.nvidia.com/dchichkov/rechat.git)- Run
rechat, it will listen on eight-nine-ten port (http://localhost:8910/v1) and use OpenAI's endpoint by default as upstream. - Configure your OpenAI client to use it
export OPENAI_BASE_URL=http://localhost:8910/v1and run your requests as usual.
You can specify a different upstream endpoint by providing it as an argument, e.g. rechat https://api.openai.com/v1.
By default, rechat outputs intercepted chat content onto the console:
And it records the session to flows_<timestamp>.dump file in the current directory. During subsequent runs, if a -f/--flow [dump_file] argument is provided, rechat would attempt to load flows_[timestamp].dump files, or the specified dump file. It always tries to use cached responses for any matching requests.
Inspection and Debugging
Rechat provides http://localhost:8910 web UI for inspecting the current session, with search and filtering capabilities.
By default, rechat will output chat content to the console. Use --quiet flag to reduce verbosity. Use --verbose flag to include cache hits. Any markdown editor, for example VSCode or GitHub/GitLab web UI, can be used to view and edit the logs, and these modified logs can be loaded into rechat, to emulate model's responses.
Example
Example markdown snippet, in markdown format. Note <blockquote> tags. See more details in sample.md.
### user
<blockquote>
What is the capital of France?
</blockquote>
### assistant
<blockquote>
Paris.
</blockquote>
Intercepting traffic to existing OpenAI endpoints
Rechat can intercept traffic to existing OpenAI endpoints, without changing the client code, by using mitmproxy as a transparent proxy. For example, to use mitmproxy local proxy mode and intercept traffic to https://api.openai.com/v1, run:
mitmproxy --mode local --scripts rechat.py
Routing and Load Balancing
Rechat supports multiple endpoints, using <endpoint>:[local_port]:[model_name] arguments, e.g. https://api.openai.com/v1:8910:gpt-5. It would route the requests to the appropriate endpoint based on the model name in the request, and it'd balance the load between endpoints for the same model.
Miscellaneous
- Replaying queries against an endpoint
- Multiple responses for the same request
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rechat-0.1.4.tar.gz.
File metadata
- Download URL: rechat-0.1.4.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0f59d361680249c43506f835f1e2a2b224eb48f6cd562fac885577b99aa67d2
|
|
| MD5 |
0aa2aa7deb6a45fd3053e3500f834c6e
|
|
| BLAKE2b-256 |
90e198d712eeebfe01fe0060b6577def0076d9b7cf5f744e23fe7fe43c8eddba
|
File details
Details for the file rechat-0.1.4-py3-none-any.whl.
File metadata
- Download URL: rechat-0.1.4-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab39865249d0efd52de628f0bbd02e36744939e85e30da43bcdbda424f5b8dd5
|
|
| MD5 |
af74e33280ead246335c4511b4f7aea8
|
|
| BLAKE2b-256 |
3931d091c44110e1af3e2d529f736b364043b58fe7f2f9f785cba80effb0e279
|