2023-09-28 10:58:58 +08:00
|
|
|
import os, sys
|
|
|
|
|
|
|
|
src_dir = os.path.join(
|
|
|
|
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
)
|
|
|
|
sys.path.append(src_dir)
|
|
|
|
|
2024-03-28 20:12:36 +08:00
|
|
|
from configs.model_config import llm_model_dict, LLM_MODEL
|
2023-09-28 10:58:58 +08:00
|
|
|
import openai
|
|
|
|
# os.environ["OPENAI_PROXY"] = "socks5h://127.0.0.1:7890"
|
|
|
|
# os.environ["OPENAI_PROXY"] = "http://127.0.0.1:7890"
|
2023-11-07 19:44:47 +08:00
|
|
|
# os.environ["OPENAI_API_KEY"] = ""
|
2023-09-28 10:58:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# print("dsadsa", os.environ.get("OPENAI_PROXY"), os.environ.get("OPENAI_API_KEY"))
|
|
|
|
from langchain import PromptTemplate, LLMChain
|
|
|
|
from langchain.prompts.chat import ChatPromptTemplate
|
|
|
|
from langchain.chat_models import ChatOpenAI
|
|
|
|
from langchain.schema import HumanMessage
|
|
|
|
|
|
|
|
# chat = ChatOpenAI(temperature=0.1, model_name="gpt-3.5-turbo")
|
|
|
|
# print(chat.predict("hi!"))
|
|
|
|
|
2024-03-28 20:12:36 +08:00
|
|
|
print(LLM_MODEL, llm_model_dict[LLM_MODEL]["api_key"], llm_model_dict[LLM_MODEL]["api_base_url"])
|
|
|
|
from langchain.chat_models import ChatOpenAI
|
|
|
|
model = ChatOpenAI(
|
|
|
|
streaming=True,
|
|
|
|
verbose=True,
|
|
|
|
openai_api_key="dsdadas",
|
|
|
|
openai_api_base=llm_model_dict[LLM_MODEL]["api_base_url"],
|
|
|
|
model_name=LLM_MODEL
|
|
|
|
)
|
|
|
|
print(model.predict("hi!"))
|
2023-12-26 11:41:53 +08:00
|
|
|
# chat_prompt = ChatPromptTemplate.from_messages([("human", "{input}")])
|
|
|
|
# chain = LLMChain(prompt=chat_prompt, llm=model)
|
|
|
|
# content = chain({"input": "hello"})
|
|
|
|
# print(content)
|
|
|
|
|
2024-03-28 20:12:36 +08:00
|
|
|
# import openai
|
|
|
|
# # openai.api_key = "EMPTY" # Not support yet
|
|
|
|
# openai.api_base = "http://127.0.0.1:8888/v1"
|
2023-12-26 11:41:53 +08:00
|
|
|
|
2024-03-28 20:12:36 +08:00
|
|
|
# model = "example"
|
2023-12-26 11:41:53 +08:00
|
|
|
|
2024-03-28 20:12:36 +08:00
|
|
|
# # create a chat completion
|
|
|
|
# completion = openai.ChatCompletion.create(
|
|
|
|
# model=model,
|
|
|
|
# messages=[{"role": "user", "content": "Hello! What is your name? "}],
|
|
|
|
# max_tokens=100,
|
|
|
|
# )
|
|
|
|
# # print the completion
|
|
|
|
# print(completion.choices[0].message.content)
|