Compare commits

...

1 Commits

Author SHA1 Message Date
Harrison Chase 5ba897a802 add dependencies for easier install 2 years ago

@ -3,6 +3,8 @@
import time
from sys import platform
from playwright.sync_api import sync_playwright
black_listed_elements = {
"html",
"head",
@ -21,13 +23,6 @@ black_listed_elements = {
class Crawler:
def __init__(self):
try:
from playwright.sync_api import sync_playwright
except ImportError:
raise ValueError(
"Could not import playwright python package. "
"Please it install it with `pip install playwright`."
)
self.browser = (
sync_playwright()
.start()

@ -7,6 +7,7 @@ import sys
from typing import Any, Dict, List
from pydantic import BaseModel, Extra, root_validator
from serpapi import GoogleSearch
from langchain.chains.base import Chain
@ -38,7 +39,6 @@ class SerpAPIChain(Chain, BaseModel):
serpapi = SerpAPIChain()
"""
search_engine: Any #: :meta private:
input_key: str = "search_query" #: :meta private:
output_key: str = "search_result" #: :meta private:
@ -71,15 +71,6 @@ class SerpAPIChain(Chain, BaseModel):
"Did not find SerpAPI API key, please add an environment variable"
" `SERPAPI_API_KEY` which contains it."
)
try:
from serpapi import GoogleSearch
values["search_engine"] = GoogleSearch
except ImportError:
raise ValueError(
"Could not import serpapi python package. "
"Please it install it with `pip install google-search-results`."
)
return values
def _run(self, inputs: Dict[str, Any]) -> Dict[str, str]:
@ -92,7 +83,7 @@ class SerpAPIChain(Chain, BaseModel):
"hl": "en",
}
with HiddenPrints():
search = self.search_engine(params)
search = GoogleSearch(params)
res = search.get_dict()
if "answer_box" in res.keys() and "answer" in res["answer_box"].keys():

@ -1,7 +1,8 @@
"""Wrapper around Cohere APIs."""
import os
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
import cohere
from pydantic import BaseModel, Extra, root_validator
from langchain.llms.base import LLM
@ -28,7 +29,6 @@ class Cohere(BaseModel, LLM):
cohere = Cohere(model="gptd-instruct-tft")
"""
client: Any #: :meta private:
model: str = "gptd-instruct-tft"
"""Model name to use."""
@ -63,15 +63,6 @@ class Cohere(BaseModel, LLM):
"Did not find Cohere API key, please add an environment variable"
" `COHERE_API_KEY` which contains it."
)
try:
import cohere
values["client"] = cohere.Client(os.environ["COHERE_API_KEY"])
except ImportError:
raise ValueError(
"Could not import cohere python package. "
"Please it install it with `pip install cohere`."
)
return values
def __call__(self, prompt: str, stop: Optional[List[str]] = None) -> str:
@ -89,7 +80,8 @@ class Cohere(BaseModel, LLM):
response = cohere("Tell me a joke.")
"""
response = self.client.generate(
client = cohere.Client(os.environ["COHERE_API_KEY"])
response = client.generate(
model=self.model,
prompt=prompt,
max_tokens=self.max_tokens,

@ -2,6 +2,7 @@
import os
from typing import Any, Dict, List, Mapping, Optional
import openai
from pydantic import BaseModel, Extra, root_validator
from langchain.llms.base import LLM
@ -51,15 +52,6 @@ class OpenAI(BaseModel, LLM):
"Did not find OpenAI API key, please add an environment variable"
" `OPENAI_API_KEY` which contains it."
)
try:
import openai
values["client"] = openai.Completion
except ImportError:
raise ValueError(
"Could not import openai python package. "
"Please it install it with `pip install openai`."
)
return values
@property
@ -90,7 +82,7 @@ class OpenAI(BaseModel, LLM):
response = openai("Tell me a joke.")
"""
response = self.client.create(
response = openai.Completion.create(
model=self.model_name, prompt=prompt, stop=stop, **self._default_params
)
return response["choices"][0]["text"]

@ -4,6 +4,3 @@ isort
mypy
flake8
flake8-docstrings
cohere
openai
google-search-results

@ -14,7 +14,13 @@ setup(
version=__version__,
packages=find_packages(),
description="Building applications with LLMs through composability",
install_requires=["pydantic"],
install_requires=[
"pydantic",
"cohere",
"openai",
"google-search-results",
"playwright",
],
long_description=long_description,
license="MIT",
url="https://github.com/hwchase17/langchain",

Loading…
Cancel
Save