mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 21:33:31 -04:00
ba0cbb4a41
Add `finish_reason` to `Generation` as well as extend `BaseOpenAI._generate` to include it in the output. This can be useful for usage in downstream tasks when we need to filter for only generations that finished because of `"stop"` for example. Maybe we should add this to `LLMChain` as well? For more details, see https://beta.openai.com/docs/guides/completion/best-practices Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
41 lines
990 B
Python
41 lines
990 B
Python
"""Common schema objects."""
|
|
|
|
from typing import Any, Dict, List, NamedTuple, Optional
|
|
|
|
|
|
class AgentAction(NamedTuple):
|
|
"""Agent's action to take."""
|
|
|
|
tool: str
|
|
tool_input: str
|
|
log: str
|
|
|
|
|
|
class AgentFinish(NamedTuple):
|
|
"""Agent's return value."""
|
|
|
|
return_values: dict
|
|
log: str
|
|
|
|
|
|
class Generation(NamedTuple):
|
|
"""Output of a single generation."""
|
|
|
|
text: str
|
|
"""Generated text output."""
|
|
|
|
generation_info: Optional[Dict[str, Any]] = None
|
|
"""Raw generation info response from the provider"""
|
|
"""May include things like reason for finishing (e.g. in OpenAI)"""
|
|
# TODO: add log probs
|
|
|
|
|
|
class LLMResult(NamedTuple):
|
|
"""Class that contains all relevant information for an LLM Result."""
|
|
|
|
generations: List[List[Generation]]
|
|
"""List of the things generated. This is List[List[]] because
|
|
each input could have multiple generations."""
|
|
llm_output: Optional[dict] = None
|
|
"""For arbitrary LLM provider specific output."""
|