diff --git a/chatgpt2api/chatgpt2api.py b/chatgpt2api/chatgpt2api.py index 82726819..fa39fd26 100644 --- a/chatgpt2api/chatgpt2api.py +++ b/chatgpt2api/chatgpt2api.py @@ -64,6 +64,7 @@ def __init__( self.source_api_url: str = api_url parsed_url = urlparse(self.source_api_url) self.base_url: str = urlunparse(parsed_url[:2] + ("",) * 4) + self.v1_url: str = urlunparse(parsed_url[:2] + ("/v1",) + ("",) * 3) self.chat_url: str = urlunparse(parsed_url[:2] + ("/v1/chat/completions",) + ("",) * 3) self.image_url: str = urlunparse(parsed_url[:2] + ("/v1/images/generations",) + ("",) * 3) @@ -545,8 +546,8 @@ def search_summary( chatllm = EducationalLLM(callback_manager=CallbackManager([chainStreamHandler])) chainllm = EducationalLLM() else: - chatllm = ChatOpenAI(streaming=True, callback_manager=CallbackManager([chainStreamHandler]), temperature=config.temperature, openai_api_base=config.API_URL.split("chat")[0], model_name=self.engine, openai_api_key=config.API) - chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=config.API_URL.split("chat")[0], model_name=config.GPT_ENGINE, openai_api_key=config.API) + chatllm = ChatOpenAI(streaming=True, callback_manager=CallbackManager([chainStreamHandler]), temperature=config.temperature, openai_api_base=bot_api_url.v1_url, model_name=self.engine, openai_api_key=config.API) + chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=bot_api_url.v1_url, model_name=config.GPT_ENGINE, openai_api_key=config.API) if config.SEARCH_USE_GPT: gpt_search_thread = ThreadWithReturnValue(target=gptsearch, args=(prompt, chainllm,)) diff --git a/test/test.py b/test/test.py index db76fd09..ece1770d 100644 --- a/test/test.py +++ b/test/test.py @@ -42,9 +42,10 @@ def __init__( self.source_api_url: str = api_url parsed_url = urlparse(self.source_api_url) self.base_url: str = urlunparse(parsed_url[:2] + ("",) * 4) + self.v1_url: str = urlunparse(parsed_url[:2] + ("/v1",) + ("",) * 3) self.chat_url: str = urlunparse(parsed_url[:2] + ("/v1/chat/completions",) + ("",) * 3) self.image_url: str = urlunparse(parsed_url[:2] + ("/v1/images/generations",) + ("",) * 3) a = openaiAPI() -print(a.chat_url) \ No newline at end of file +print(a.v1_url) \ No newline at end of file diff --git a/utils/agent.py b/utils/agent.py index 9dfea331..5e5fa2e8 100644 --- a/utils/agent.py +++ b/utils/agent.py @@ -36,6 +36,7 @@ from langchain.utilities import WikipediaAPIWrapper from utils.googlesearch import GoogleSearchAPIWrapper from langchain.document_loaders import UnstructuredPDFLoader +from chatgpt2api.chatgpt2api import bot_api_url def getmd5(string): import hashlib @@ -95,8 +96,8 @@ def get_chain(store, llm): return chain async def docQA(docpath, query_message, persist_db_path="db", model = "gpt-3.5-turbo"): - chatllm = ChatOpenAI(temperature=0.5, openai_api_base=config.API_URL.split("chat")[0], model_name=model, openai_api_key=config.API) - embeddings = OpenAIEmbeddings(openai_api_base=config.API_URL.split("chat")[0], openai_api_key=config.API) + chatllm = ChatOpenAI(temperature=0.5, openai_api_base=bot_api_url.v1_url, model_name=model, openai_api_key=config.API) + embeddings = OpenAIEmbeddings(openai_api_base=bot_api_url.v1_url, openai_api_key=config.API) sitemap = "sitemap.xml" match = re.match(r'^(https?|ftp)://[^\s/$.?#].[^\s]*$', docpath) @@ -135,7 +136,7 @@ def get_doc_from_url(url): return filename def persist_emdedding_pdf(docurl, persist_db_path): - embeddings = OpenAIEmbeddings(openai_api_base=config.API_URL.split("chat")[0], openai_api_key=os.environ.get('API', None)) + embeddings = OpenAIEmbeddings(openai_api_base=bot_api_url.v1_url, openai_api_key=os.environ.get('API', None)) filename = get_doc_from_url(docurl) docpath = os.getcwd() + "/" + filename loader = UnstructuredPDFLoader(docpath) @@ -150,8 +151,8 @@ def persist_emdedding_pdf(docurl, persist_db_path): return vector_store async def pdfQA(docurl, docpath, query_message, model="gpt-3.5-turbo"): - chatllm = ChatOpenAI(temperature=0.5, openai_api_base=config.API_URL.split("chat")[0], model_name=model, openai_api_key=os.environ.get('API', None)) - embeddings = OpenAIEmbeddings(openai_api_base=config.API_URL.split("chat")[0], openai_api_key=os.environ.get('API', None)) + chatllm = ChatOpenAI(temperature=0.5, openai_api_base=bot_api_url.v1_url, model_name=model, openai_api_key=os.environ.get('API', None)) + embeddings = OpenAIEmbeddings(openai_api_base=bot_api_url.v1_url, openai_api_key=os.environ.get('API', None)) persist_db_path = getmd5(docpath) if not os.path.exists(persist_db_path): vector_store = persist_emdedding_pdf(docurl, persist_db_path) @@ -163,8 +164,8 @@ async def pdfQA(docurl, docpath, query_message, model="gpt-3.5-turbo"): return result['result'] def pdf_search(docurl, query_message, model="gpt-3.5-turbo"): - chatllm = ChatOpenAI(temperature=0.5, openai_api_base=config.API_URL.split("chat")[0], model_name=model, openai_api_key=os.environ.get('API', None)) - embeddings = OpenAIEmbeddings(openai_api_base=config.API_URL.split("chat")[0], openai_api_key=os.environ.get('API', None)) + chatllm = ChatOpenAI(temperature=0.5, openai_api_base=bot_api_url.v1_url, model_name=model, openai_api_key=os.environ.get('API', None)) + embeddings = OpenAIEmbeddings(openai_api_base=bot_api_url.v1_url, openai_api_key=os.environ.get('API', None)) filename = get_doc_from_url(docurl) docpath = os.getcwd() + "/" + filename loader = UnstructuredPDFLoader(docpath) @@ -319,7 +320,7 @@ def get_google_search_results(prompt: str, context_max_tokens: int): if config.USE_G4F: chainllm = EducationalLLM() else: - chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=config.API_URL.split("chat")[0], model_name=config.GPT_ENGINE, openai_api_key=config.API) + chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=bot_api_url.v1_url, model_name=config.GPT_ENGINE, openai_api_key=config.API) if config.SEARCH_USE_GPT: gpt_search_thread = ThreadWithReturnValue(target=gptsearch, args=(prompt, chainllm,))