Skip to content

Commit

Permalink
Worker (#83)
Browse files Browse the repository at this point in the history
* base llm

* ;)

* base llm

* llm

* more ideas around queues

* examples

* cleanup

* napper

* querent workers

* update the querent core to handle shutdown signals

* cleanup

* worker

* handle signaling
  • Loading branch information
saraswatpuneet committed Sep 25, 2023
1 parent 58d785b commit 7407a63
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
Empty file added tests/llm_tests/__init__.py
Empty file.
41 changes: 0 additions & 41 deletions tests/llm_tests/gpt2_llm_v1_test.py

This file was deleted.

57 changes: 57 additions & 0 deletions tests/llm_tests/mock_llm_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import asyncio
import pytest
from querent.common.types.querent_queue import QuerentQueue
from querent.llm.base_llm import BaseLLM
from querent.napper.querent import Querent


# Define a simple mock LLM class for testing
class MockLLM(BaseLLM):
async def process_tokens(self, data):
return f"Processed: {data}"

def validate(self):
return True


@pytest.mark.asyncio
async def test_querent_with_base_llm():
# Create input and output queues
input_queue = QuerentQueue()
output_queue = QuerentQueue()

# Create a list of mock LLM instances
num_llms = 3
llms = [MockLLM(input_queue, output_queue) for _ in range(num_llms)]

# Create a Querent instance
querent = Querent(llms, num_workers=num_llms, resource_manager=None)

# Start the Querent
await querent.start()

# Put some input data into the input queue
input_data = ["Data 1", "Data 2", "Data 3"]
for data in input_data:
await input_queue.put(data)

# Signal the Querent to stop by putting None into the input queue
await input_queue.close()

# Wait for the Querent to finish processing
await asyncio.gather(*llms)

# Check the output queue for results and store them in a list
results = []
async for result in output_queue:
results.append(result)
await output_queue.close()

# Assert that the results match the expected output
expected_output = ["Processed: Data 1", "Processed: Data 2", "Processed: Data 3"]
assert results == expected_output


# Run the test
if __name__ == "__main__":
pytest.main()

0 comments on commit 7407a63

Please sign in to comment.