-
-
Save samching/291d097cb59ec039ee31c42a2bb258f0 to your computer and use it in GitHub Desktop.
LangChain ChatGPT API Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment