Commit 237fd0be by Jonathan Thomas

Improving LLM unit tests, adding Rate Limiter, and checking for + and - friendship.

parent a119149f
Pipeline #13250 passed with stages
in 2 minutes 8 seconds
......@@ -6,6 +6,13 @@ All notable changes to **CreatureChat** are documented in this file. The format
## Unreleased
### Added
- Rate limiter for LLM unit tests (to prevent rate limit issues from certain providers when running all tests)
- Check friendship direction (+ or -) in LLM unit tests (to verify friendship is output correctly)
### Changed
- Improved LLM unit tests to check for both a positive and negative behaviors (i.e. FOLLOW and not LEAD, ATTACK and not FLEE, etc...)
### Fixed
- Changing death message timestamp output to use DEBUG log level
......
package com.owlmaddie.utils;
import java.util.concurrent.Semaphore;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* The {@code RateLimiter} class is used to slow down LLM unit tests so we don't hit any rate limits accidentally.
*/
public class RateLimiter {
private final Semaphore semaphore;
public RateLimiter(int requestsPerSecond) {
semaphore = new Semaphore(requestsPerSecond);
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
semaphore.release(requestsPerSecond - semaphore.availablePermits());
}, 0, 1, TimeUnit.SECONDS);
}
public void acquire() throws InterruptedException {
semaphore.acquire();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment