parent
bb2dc1e41e
commit
bd75716560
@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/agentic" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/infrastructure" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/librealsense" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="WebResourcesPaths">
|
||||
<contentEntries>
|
||||
<entry url="file://$PROJECT_DIR$">
|
||||
<entryData>
|
||||
<resourceRoots>
|
||||
<path value="file://$PROJECT_DIR$/assets" />
|
||||
<path value="file://$PROJECT_DIR$/docs" />
|
||||
<path value="file://$PROJECT_DIR$/models" />
|
||||
<path value="file://$PROJECT_DIR$/librealsense" />
|
||||
</resourceRoots>
|
||||
</entryData>
|
||||
</entry>
|
||||
</contentEntries>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,42 @@
|
||||
import asyncio
|
||||
import json
|
||||
from aiokafka import AIOKafkaConsumer, AIOKafkaProducer
|
||||
|
||||
class KafkaClient:
|
||||
def __init__(self, topic: str, bootstrap_servers: str, group_id: str = None):
|
||||
self.topic = topic
|
||||
self.bootstrap_servers = bootstrap_servers
|
||||
self.group_id = group_id
|
||||
self.consumer = None
|
||||
self.producer = None
|
||||
|
||||
async def start(self):
|
||||
# init producer & consumer
|
||||
self.producer = AIOKafkaProducer(bootstrap_servers=self.bootstrap_servers)
|
||||
await self.producer.start()
|
||||
|
||||
if self.group_id:
|
||||
self.consumer = AIOKafkaConsumer(
|
||||
self.topic,
|
||||
bootstrap_servers=self.bootstrap_servers,
|
||||
group_id=self.group_id
|
||||
)
|
||||
await self.consumer.start()
|
||||
|
||||
async def stop(self):
|
||||
if self.producer:
|
||||
await self.producer.stop()
|
||||
if self.consumer:
|
||||
await self.consumer.stop()
|
||||
|
||||
async def send_message(self, message: dict):
|
||||
message_json = json.dumps(message).encode('utf-8')
|
||||
await self.producer.send_and_wait(self.topic, message_json)
|
||||
|
||||
async def consume_messages(self, callback):
|
||||
if not self.consumer:
|
||||
raise Exception("Consumer is not initialized. Ensure group_id is set and start is called.")
|
||||
|
||||
async for message in self.consumer:
|
||||
message_value = json.loads(message.value.decode('utf-8'))
|
||||
await callback(message_value)
|
@ -0,0 +1,7 @@
|
||||
# producer.Dockerfile
|
||||
FROM python:3.9
|
||||
WORKDIR /app
|
||||
COPY test_show_responses_from_llm.py .
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
CMD ["python", "test_show_responses_from_llm.py"]
|
@ -0,0 +1,46 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
kafka:
|
||||
image: 'bitnami/kafka:latest'
|
||||
environment:
|
||||
- KAFKA_BROKER_ID=1
|
||||
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
|
||||
- KAFKA_LISTENERS=INSIDE://:9092,OUTSIDE://:29092
|
||||
- KAFKA_ADVERTISED_LISTENERS=INSIDE://kafka:9092,OUTSIDE://localhost:29092
|
||||
- KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE
|
||||
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
|
||||
depends_on:
|
||||
- zookeeper
|
||||
|
||||
zookeeper:
|
||||
image: 'bitnami/zookeeper:latest'
|
||||
environment:
|
||||
- ALLOW_ANONYMOUS_LOGIN=yes
|
||||
|
||||
producer:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: producer.Dockerfile
|
||||
environment:
|
||||
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
|
||||
depends_on:
|
||||
- kafka
|
||||
|
||||
consumer:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: consumer.Dockerfile
|
||||
environment:
|
||||
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
|
||||
depends_on:
|
||||
- kafka
|
||||
|
||||
processor:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: processor.Dockerfile
|
||||
environment:
|
||||
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
|
||||
depends_on:
|
||||
- kafka
|
@ -0,0 +1,25 @@
|
||||
import asyncio
|
||||
from AgenticInterfaces.KafkaClient import KafkaClient
|
||||
|
||||
request_topic = "request_llm_topic"
|
||||
response_topic = "response_llm_topic"
|
||||
bootstrap_servers = "kafka:9092"
|
||||
|
||||
def modify_text(text):
|
||||
return text[::-1]
|
||||
|
||||
async def process_message(message):
|
||||
modified_text = modify_text(message["text"])
|
||||
response_message = {"text": modified_text}
|
||||
await kafka_client.send_message(response_message)
|
||||
|
||||
async def main():
|
||||
global kafka_client
|
||||
kafka_client = KafkaClient(topic=request_topic, bootstrap_servers=bootstrap_servers, group_id="my-group")
|
||||
await kafka_client.start()
|
||||
try:
|
||||
await kafka_client.consume_messages(process_message)
|
||||
finally:
|
||||
await kafka_client.stop()
|
||||
|
||||
asyncio.run(main())
|
@ -0,0 +1,7 @@
|
||||
# processor.Dockerfile
|
||||
FROM python:3.9
|
||||
WORKDIR /app
|
||||
COPY llm_worker.py .
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
CMD ["python", "llm_worker.py"]
|
@ -0,0 +1,7 @@
|
||||
# producer.Dockerfile
|
||||
FROM python:3.9
|
||||
WORKDIR /app
|
||||
COPY test_send_llm_requests.py .
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
CMD ["python", "test_send_llm_requests.py"]
|
@ -0,0 +1 @@
|
||||
aiokafka
|
@ -0,0 +1,19 @@
|
||||
import asyncio
|
||||
from AgenticInterfaces.KafkaClient import KafkaClient
|
||||
|
||||
bootstrap_servers = "kafka:9092"
|
||||
request_topic = "request_llm_topic"
|
||||
|
||||
async def send_periodic_messages():
|
||||
kafka_client = KafkaClient(topic=request_topic, bootstrap_servers=bootstrap_servers)
|
||||
await kafka_client.start()
|
||||
|
||||
try:
|
||||
while True:
|
||||
message = {"text": "Пример сообщения"}
|
||||
await kafka_client.send_message(message)
|
||||
await asyncio.sleep(5)
|
||||
finally:
|
||||
await kafka_client.stop()
|
||||
|
||||
asyncio.run(send_periodic_messages())
|
@ -0,0 +1,19 @@
|
||||
import asyncio
|
||||
from AgenticInterfaces.KafkaClient import KafkaClient
|
||||
|
||||
bootstrap_servers = "kafka:9092"
|
||||
response_topic = "response_llm_topic"
|
||||
|
||||
async def print_received_messages(message):
|
||||
print("Получено сообщение:", message["text"])
|
||||
|
||||
async def receive_messages():
|
||||
kafka_client = KafkaClient(topic=response_topic, bootstrap_servers=bootstrap_servers, group_id="response-group")
|
||||
await kafka_client.start()
|
||||
|
||||
try:
|
||||
await kafka_client.consume_messages(print_received_messages)
|
||||
finally:
|
||||
await kafka_client.stop()
|
||||
|
||||
asyncio.run(receive_messages())
|
Loading…
Reference in new issue