claude fixes
This commit is contained in:
parent
3ffc8bdbc2
commit
92900f4806
3 changed files with 124 additions and 15 deletions
|
|
@ -9,8 +9,8 @@ from providers import get_provider
|
|||
config = toml.load("config.toml")
|
||||
|
||||
NATS_URL = config["nats"]["url"]
|
||||
TOPIC_IN = config["nats"]["topic_in"]
|
||||
TOPIC_OUT = config["nats"]["topic_out"]
|
||||
INCOMING_TOPIC = config["nats"]["incoming_topic"]
|
||||
RESPONSE_TOPIC = config["nats"]["response_topic"]
|
||||
|
||||
provider = get_provider(
|
||||
config["llm"]["provider"],
|
||||
|
|
@ -25,6 +25,7 @@ async def message_handler(msg):
|
|||
|
||||
try:
|
||||
data = json.loads(msg.data.decode())
|
||||
request_id = data.get("request_id")
|
||||
user_id = data.get("user_id")
|
||||
text = data.get("text")
|
||||
if not text:
|
||||
|
|
@ -34,12 +35,14 @@ async def message_handler(msg):
|
|||
response = await provider.chat([{"role": "user", "content": text}])
|
||||
|
||||
reply = {
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
"response": response
|
||||
"response": response,
|
||||
"service": "LLM-Service"
|
||||
}
|
||||
|
||||
await msg.respond(json.dumps(reply).encode())
|
||||
logger.success(f"Ответ отправлен в {TOPIC_OUT} для {user_id}")
|
||||
await nc.publish(RESPONSE_TOPIC, json.dumps(reply).encode())
|
||||
logger.success(f"Ответ опубликован в {RESPONSE_TOPIC} для request_id: {request_id}")
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Error handling message")
|
||||
|
|
@ -47,8 +50,9 @@ async def message_handler(msg):
|
|||
|
||||
async def main():
|
||||
logger.info("Connecting to NATS...")
|
||||
global nc
|
||||
nc = await nats.connect(servers=[NATS_URL])
|
||||
await nc.subscribe(TOPIC_IN, cb=message_handler)
|
||||
await nc.subscribe(INCOMING_TOPIC, cb=message_handler)
|
||||
await nc.flush()
|
||||
logger.info(f"Subscribed to {TOPIC_IN}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue