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.
LangChain ChatGPT API Wrapper
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(self.url, params={"q": prompt})
return res.content.decode()
llm = CustomLLM("http://127.0.0.1:5001/chat")
@Syzygianinfern0
Copy link

What happens at "http://127.0.0.1:5001/chat"?

@Cdaprod
Copy link

Cdaprod commented Dec 5, 2023

It’s probably inference api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment