(OpenAI) Add model_name to LLMResult.llm_output (#1713)

Given that different models have very different latencies and pricings,
it's benefitial to pass the information about the model that generated
the response. Such information allows implementing custom callback
managers and track usage and price per model.

Addresses https://github.com/hwchase17/langchain/issues/1557.
This commit is contained in:
Mario Kostelac
2023-03-17 05:55:55 +01:00
committed by GitHub
parent 8a95fdaee1
commit aff44d0a98
2 changed files with 20 additions and 5 deletions

View File

@@ -35,6 +35,14 @@ def test_openai_extra_kwargs() -> None:
OpenAI(foo=3, model_kwargs={"foo": 2})
def test_openai_llm_output_contains_model_name() -> None:
"""Test llm_output contains model_name."""
llm = OpenAI(max_tokens=10)
llm_result = llm.generate(["Hello, how are you?"])
assert llm_result.llm_output is not None
assert llm_result.llm_output["model_name"] == llm.model_name
def test_openai_stop_valid() -> None:
"""Test openai stop logic on valid configuration."""
query = "write an ordered list of five items"