Spaces:
Running
Running
File size: 806 Bytes
bf12aca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import json
from typing import Any, List, Mapping, Optional
import requests
from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.llms.base import LLM
url = "https://openai.proxy.onlyyounotothers.top/chat"
headers = {"Content-Type": "application/json"}
class ChatGLM(LLM):
@property
def _llm_type(self) -> str:
return "custom"
type = "custom"
# 重写基类方法,根据用户输入的prompt来响应用户,返回字符串
def _call(
self,
prompt: str,
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
) -> str:
payload = json.dumps({"q": prompt})
response = requests.request("POST", url, headers=headers, data=payload)
return response.text
|