forked from Archives/langchain
Compare commits
1 Commits
main
...
harrison/a
Author | SHA1 | Date | |
---|---|---|---|
|
5ba897a802 |
@ -3,6 +3,8 @@
|
|||||||
import time
|
import time
|
||||||
from sys import platform
|
from sys import platform
|
||||||
|
|
||||||
|
from playwright.sync_api import sync_playwright
|
||||||
|
|
||||||
black_listed_elements = {
|
black_listed_elements = {
|
||||||
"html",
|
"html",
|
||||||
"head",
|
"head",
|
||||||
@ -21,13 +23,6 @@ black_listed_elements = {
|
|||||||
|
|
||||||
class Crawler:
|
class Crawler:
|
||||||
def __init__(self):
|
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 = (
|
self.browser = (
|
||||||
sync_playwright()
|
sync_playwright()
|
||||||
.start()
|
.start()
|
||||||
|
@ -7,6 +7,7 @@ import sys
|
|||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
from pydantic import BaseModel, Extra, root_validator
|
from pydantic import BaseModel, Extra, root_validator
|
||||||
|
from serpapi import GoogleSearch
|
||||||
|
|
||||||
from langchain.chains.base import Chain
|
from langchain.chains.base import Chain
|
||||||
|
|
||||||
@ -38,7 +39,6 @@ class SerpAPIChain(Chain, BaseModel):
|
|||||||
serpapi = SerpAPIChain()
|
serpapi = SerpAPIChain()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
search_engine: Any #: :meta private:
|
|
||||||
input_key: str = "search_query" #: :meta private:
|
input_key: str = "search_query" #: :meta private:
|
||||||
output_key: str = "search_result" #: :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"
|
"Did not find SerpAPI API key, please add an environment variable"
|
||||||
" `SERPAPI_API_KEY` which contains it."
|
" `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
|
return values
|
||||||
|
|
||||||
def _run(self, inputs: Dict[str, Any]) -> Dict[str, str]:
|
def _run(self, inputs: Dict[str, Any]) -> Dict[str, str]:
|
||||||
@ -92,7 +83,7 @@ class SerpAPIChain(Chain, BaseModel):
|
|||||||
"hl": "en",
|
"hl": "en",
|
||||||
}
|
}
|
||||||
with HiddenPrints():
|
with HiddenPrints():
|
||||||
search = self.search_engine(params)
|
search = GoogleSearch(params)
|
||||||
res = search.get_dict()
|
res = search.get_dict()
|
||||||
|
|
||||||
if "answer_box" in res.keys() and "answer" in res["answer_box"].keys():
|
if "answer_box" in res.keys() and "answer" in res["answer_box"].keys():
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
"""Wrapper around Cohere APIs."""
|
"""Wrapper around Cohere APIs."""
|
||||||
import os
|
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 pydantic import BaseModel, Extra, root_validator
|
||||||
|
|
||||||
from langchain.llms.base import LLM
|
from langchain.llms.base import LLM
|
||||||
@ -28,7 +29,6 @@ class Cohere(BaseModel, LLM):
|
|||||||
cohere = Cohere(model="gptd-instruct-tft")
|
cohere = Cohere(model="gptd-instruct-tft")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
client: Any #: :meta private:
|
|
||||||
model: str = "gptd-instruct-tft"
|
model: str = "gptd-instruct-tft"
|
||||||
"""Model name to use."""
|
"""Model name to use."""
|
||||||
|
|
||||||
@ -63,15 +63,6 @@ class Cohere(BaseModel, LLM):
|
|||||||
"Did not find Cohere API key, please add an environment variable"
|
"Did not find Cohere API key, please add an environment variable"
|
||||||
" `COHERE_API_KEY` which contains it."
|
" `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
|
return values
|
||||||
|
|
||||||
def __call__(self, prompt: str, stop: Optional[List[str]] = None) -> str:
|
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 = cohere("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
response = self.client.generate(
|
client = cohere.Client(os.environ["COHERE_API_KEY"])
|
||||||
|
response = client.generate(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
max_tokens=self.max_tokens,
|
max_tokens=self.max_tokens,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
from typing import Any, Dict, List, Mapping, Optional
|
from typing import Any, Dict, List, Mapping, Optional
|
||||||
|
|
||||||
|
import openai
|
||||||
from pydantic import BaseModel, Extra, root_validator
|
from pydantic import BaseModel, Extra, root_validator
|
||||||
|
|
||||||
from langchain.llms.base import LLM
|
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"
|
"Did not find OpenAI API key, please add an environment variable"
|
||||||
" `OPENAI_API_KEY` which contains it."
|
" `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
|
return values
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -90,7 +82,7 @@ class OpenAI(BaseModel, LLM):
|
|||||||
|
|
||||||
response = openai("Tell me a joke.")
|
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
|
model=self.model_name, prompt=prompt, stop=stop, **self._default_params
|
||||||
)
|
)
|
||||||
return response["choices"][0]["text"]
|
return response["choices"][0]["text"]
|
||||||
|
@ -4,6 +4,3 @@ isort
|
|||||||
mypy
|
mypy
|
||||||
flake8
|
flake8
|
||||||
flake8-docstrings
|
flake8-docstrings
|
||||||
cohere
|
|
||||||
openai
|
|
||||||
google-search-results
|
|
||||||
|
8
setup.py
8
setup.py
@ -14,7 +14,13 @@ setup(
|
|||||||
version=__version__,
|
version=__version__,
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
description="Building applications with LLMs through composability",
|
description="Building applications with LLMs through composability",
|
||||||
install_requires=["pydantic"],
|
install_requires=[
|
||||||
|
"pydantic",
|
||||||
|
"cohere",
|
||||||
|
"openai",
|
||||||
|
"google-search-results",
|
||||||
|
"playwright",
|
||||||
|
],
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
license="MIT",
|
license="MIT",
|
||||||
url="https://github.com/hwchase17/langchain",
|
url="https://github.com/hwchase17/langchain",
|
||||||
|
Loading…
Reference in New Issue
Block a user