Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

langchain[major]: Remove default instantations of LLMs from VectorstoreToolkit #20794

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
)
from langchain_core.language_models import BaseLanguageModel
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.tools import BaseTool
from langchain_core.vectorstores import VectorStore

from langchain.tools import BaseTool


class VectorStoreInfo(BaseModel):
"""Information about a VectorStore."""
Expand Down
17 changes: 10 additions & 7 deletions libs/langchain/langchain/chains/flare/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any, Dict, List, Optional, Sequence, Tuple

import numpy as np
from langchain_community.llms.openai import OpenAI
from langchain_core.callbacks import (
CallbackManagerForChainRun,
)
Expand Down Expand Up @@ -56,11 +55,7 @@ def _extract_tokens_and_log_probs(
class _OpenAIResponseChain(_ResponseChain):
"""Chain that generates responses from user input and context."""

llm: OpenAI = Field(
default_factory=lambda: OpenAI(
max_tokens=32, model_kwargs={"logprobs": 1}, temperature=0
)
)
llm: BaseLanguageModel

def _extract_tokens_and_log_probs(
self, generations: List[Generation]
Expand Down Expand Up @@ -118,7 +113,7 @@ class FlareChain(Chain):

question_generator_chain: QuestionGeneratorChain
"""Chain that generates questions from uncertain spans."""
response_chain: _ResponseChain = Field(default_factory=_OpenAIResponseChain)
response_chain: _ResponseChain
"""Chain that generates responses from user input and context."""
output_parser: FinishedOutputParser = Field(default_factory=FinishedOutputParser)
"""Parser that determines whether the chain is finished."""
Expand Down Expand Up @@ -255,6 +250,14 @@ def from_llm(
Returns:
FlareChain class with the given language model.
"""
try:
from langchain_openai import OpenAI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add community backup too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so since we don't want to recommend community?

except ImportError:
raise ImportError(
"OpenAI is required for FlareChain. "
"Please install langchain-openai."
"pip install langchain-openai"
)
question_gen_chain = QuestionGeneratorChain(llm=llm)
response_llm = OpenAI(
max_tokens=max_generation_len, model_kwargs={"logprobs": 1}, temperature=0
Expand Down
Loading