поясни каждую строку кода, функцию, как она применяется и архитектуру решение, оцени…
- User
поясни каждую строку кода, функцию, как она применяется и архитектуру решение, оцени его, мне нужно полное понимание и возможность потом повторить его, понять что зачем и почему: import asyncio import json from datetime import datetime from pathlib import Path from langchain.schema import HumanMessage, SystemMessage from langchain.chat_models.... import model import pandas as pd from tqdm.asyncio import tqdm CREDENTIALS = '...' SCOPE = "..." MODEL = '' N_WORKERS = 10 RES_FOLDER = "gen_test" SYS_PROMPT = "Прочитай задачу" g_chat = model(credentials=CREDENTIALS, model = MODEL, profanity_check=False, scope=SCOPE, verify_ssl_certs=False, temperature = 0.1) async def worker(queue, pbar, out_data): while True: msg = await queue.get() try: answer = await g_chat.ainvoke(msg["message"]) pbar.update(1) out_data.append({"i": msg["i"], "task_data": [{"type": "system", "text": msg["message"][0].content}, {"type": "question", "text": msg["message"][1].content}, {"type": "answer", "text": answer.content}]}) queue.task_done() except Exception as e: print(e) queue.put_nowait(msg) queue.task_done() async def main(): print(f"Preprocessing dataset:") queue = asyncio.Queue() for i, promt in df_test.iterrows(): queue.put_nowait({"i": i, "message": [SystemMessage(content=SYS_PROMPT), HumanMessage(content=promt["text"])]}) out_data = [] with tqdm(total=queue.qsize(), desc=f"Processing dataset") as pbar: tasks = [asyncio.create_task(worker(queue, pbar, out_data)) for _ in range(N_WORKERS)] await queue.join() out_data = [{"task_data": item["task_data"]} for item in sorted(out_data, key=lambda x: x['i'])] with open(f"{path}/results.json", 'w', encoding="utf-8") as file: json.dump(out_data, file, ensure_ascii=False, indent=2) print(f"Results saved in {path}.json") [task.cancel() for task in tasks] # await asyncio.gather(*tasks, return_exceptions=True) if == "": print("Start data preprocessing") df_test = pd.read_excel("therapy_gen_2.0.xlsx") date_prefix = datetime.now().strftime("%d_%m") folder_name = RES_FOLDER + '' + MODEL path = Path(folder_name) path.mkdir(parents=True, exist_ok=True) asyncio.run(main()) print("All Done")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.