تحليل المخرجات باستخدام LangChain
تعرف على كيفية تحليل إخراج LLM كمعلومات منظمة باستخدام محللات إخراج في إطار LangChain.
سنغطي ما يلي...
عادةً ما إخراج برامج ماجستير القانون سلسلة نصية. ومع ذلك، عند إنشاء تطبيق مُزوَّد ببرنامج ماجستير القانون، قد نحتاج إلى إخراج أكثر تنظيمًا وتنسيقًا، يُقدِّم معلومات مُوجزة بدلًا من مُطالبتنا بقراءة استجابة كاملًا.
محللات الإخراج
المحللات هي أدوات تساعدنا في الحصول على إخراج مُهيكلة. إذا لم نستخدم المحللات في استجاباتنا، فسيكون إخراج المتوقع نصًا عاديًا كسلسلة نصية. تُوفر لنا LangChain أنواعًا مختلفة من المحللات. جميع المحللات تأخذ إما سلسلة نصية أوMessage
إدخال.
يعتمد إخراج على نوع المُحلِّل المُستخدَم. لنستكشفه:
Parser Type | Details |
| Parses texts from message objects. Useful for handling variable formats of message content (e.g., extracting text from content blocks). |
| Returns a list of comma-separated values. |
| Parses the response into a |
| Parses response into one of the provided enum values. |
| Returns a JSON object as specified. You can specify a Pydantic model, and it will return JSON for that model. It is one of the most reliable output parsers for returning structured data without using function calls. |
| Wraps another output parser. If that output parser errors, then this will pass the error message and the bad output to an LLM and ask it to fix the output. |
| Useful for doing operations with pandas DataFrames. |
| Takes a user-defined Pydantic model and returns data in that format. |
| Wraps another output parser. If that output parser errors, then this will pass the original inputs, the bad output, and the error message to an LLM and ask it to fix it. Compared to OutputFixingParser, this one also sends the original instructions. |
| An output parser that returns structured information. It is less powerful than other output parsers since it only allows for fields to be strings. This can be useful when you are working with smaller LLMs. |
| Returns a dictionary of tags. Use when xml output is needed, and use it with models that are good at writing xml (like Anthropic's). |
| Takes a user-defined Pydantic model and returns data in that format. Uses yaml to encode it. |
تدعم معظم المحللات طريقتين شائعتين:
get_format_instructions()
تُرجع هذه الطريقة تعليمات التنسيق بصيغة سلسلة نصية . ثم يستخدم النموذج هذه المعلومات لتنسيق إخراج وفقًا لمتطلباتنا.parse()
: تقوم هذه الطريقة بتحليل إخراج السلسلة من النموذج وإرجاع كائن من النوع المطلوب.
من أجل التبسيط، سنناقش فقط المحللات Datetime وCSV وPydantic بالتفصيل.
محلل التاريخ والوقت
الDatetimeOutputParser
يحول التاريخ والوقت ...