Skip to content

Instantly share code, notes, and snippets.

@hwchase17
Last active December 5, 2023 16:10
Show Gist options
  • Save hwchase17/af2230cfc648078e1c4925c9fc183ed1 to your computer and use it in GitHub Desktop.
Save hwchase17/af2230cfc648078e1c4925c9fc183ed1 to your computer and use it in GitHub Desktop.

Revisions

  1. hwchase17 revised this gist Dec 5, 2022. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions langchain_chat_gpt.py
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,19 @@
    from langchain.llms.base import LLM
    from typing import Optional, List, Mapping, Any
    import requests
    from langchain.llms.utils import enforce_stop_tokens

    class CustomLLM(LLM):

    def __init__(self, url: str):
    self.url = url

    def __call__(self, prompt: str, stop: Optional[List[str]] = None) -> str:
    if stop is not None:
    raise ValueError("stop kwargs are not permitted.")
    res = requests.get(self.url, params={"q": prompt})
    return res.content.decode()


    text = res.content.decode()
    if stop is not None:
    text = enforce_stop_tokens(text, stop)
    return text


    llm = CustomLLM("http://127.0.0.1:5001/chat")
  2. hwchase17 revised this gist Dec 5, 2022. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions langchain_chat_gpt.py
    Original file line number Diff line number Diff line change
    @@ -10,5 +10,8 @@ def __init__(self, url: str):
    def __call__(self, prompt: str, stop: Optional[List[str]] = None) -> str:
    if stop is not None:
    raise ValueError("stop kwargs are not permitted.")
    res = requests.get("http://127.0.0.1:5001/chat", params={"q": prompt})
    return res.content.decode()
    res = requests.get(self.url, params={"q": prompt})
    return res.content.decode()


    llm = CustomLLM("http://127.0.0.1:5001/chat")
  3. hwchase17 created this gist Dec 5, 2022.
    14 changes: 14 additions & 0 deletions langchain_chat_gpt.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    from langchain.llms.base import LLM
    from typing import Optional, List, Mapping, Any
    import requests

    class CustomLLM(LLM):

    def __init__(self, url: str):
    self.url = url

    def __call__(self, prompt: str, stop: Optional[List[str]] = None) -> str:
    if stop is not None:
    raise ValueError("stop kwargs are not permitted.")
    res = requests.get("http://127.0.0.1:5001/chat", params={"q": prompt})
    return res.content.decode()