English | 简体中文
This project saves the cost of using the GPT-4 API by integrating the Pandora project to call the ChatGPT web version as an API and using it in conjunction with Langchain's custom language model.
from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.llms.base import LLM
import uuid
import requests
import json
from pydantic import BaseModel
import os
from tool import other_tools
class CustomChatGPT(LLM).
...
if __name__ == "__main__".
llm = CustomChatGPT(base_url="your url") # need to build the pandora application on the server itself
response = llm("This is a foobar thing")
your url
with your server URL. 3.CustomChatGPT
class. 4._call
method (also known as llm("prompt")), pass in the relevant parameters and get the returned message._call
method, make sure you pass in the correct parameters, such as prompt, stop, etc.This project not only provides integration with Pandora, but also introduces basic usage of Pandora.
The following code provides some basic Pandora usage, including
import requests
import json
import uuid
# base_url = "https://your-api-domain" # Replace with your API domain name
# List the models available for the account
def list_models().
...
# List the conversations in a paginated manner
def list_conversations(offset=1, limit=20).
...
# Delete all conversations
def delete_all_conversations().
...
# Get the details of a given session by its session ID
def get_conversation(conversation_id).
...
# Delete the specified conversation by its session ID
def delete_conversation(conversation_id).
...
# Set the specified session title by the session ID
def set_conversation_title(conversation_id, title).
...
# Automatically generate the title of the specified new session
def generate_conversation_title(conversation_id, model, message_id).
...
# Make ChatGPT regenerate replies
def regenerate_chatgpt(prompt, model, message_id, parent_message_id, conversation_id, stream=True).
...
# Let ChatGPT continue with the previous recovery
def continue_chatgpt(model, parent_message_id, conversation_id, stream=True).
...
# Ask ChatGPT a question and wait for a reply
def ask_chatgpt(prompt, model, message_id, parent_message_id, conversation_id=None, stream=False).
...
def ask().
...
def main().
...
if __name__ == "__main__".
main()
base_url
with the domain name of your API.Feel free to contribute to this project! Please submit an issue or pull request on GitHub.
Translated with www.DeepL.com/Translator (free version)