12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import json
- from langchain.chat_models import ChatOpenAI
- from langchain.prompts.chat import (
- ChatPromptTemplate,
- SystemMessagePromptTemplate,
- HumanMessagePromptTemplate,
- )
- from Evaluate_langchain import evaluate_langchain
- from event_langchain import event_langchain
- from format_langchain import format_langchain
- from global_langchain import global_model
- from value_langchain import value_langchain
- def input_langchain():
- print('[初始化]--------------------------初始化中--------------------------')
- chat = ChatOpenAI(temperature=0)
- model = global_model()
- # output_type = ""
- # for key, value in output_declare.items():
- # output_type += key + ":" + value + ","
- output_type = str(model.intro_declare)
- system_template = model.input_system_template
- system_message_prompt = SystemMessagePromptTemplate.from_template(
- system_template)
- human_template = model.input_human_template
- human_message_prompt = HumanMessagePromptTemplate.from_template(
- human_template)
- chat_prompt = ChatPromptTemplate.from_messages(
- [system_message_prompt, human_message_prompt])
- rsp = chat(
- chat_prompt.format_prompt(output_type=output_type,
- style=model.style,
- story=model.story).to_messages())
- print('[初始化]--------------------------GPT得到--------------------------')
- print(rsp.content)
- try:
- game_intro = json.loads(rsp.content)
- except:
- print('格式错误,修复中')
- game_intro = format_langchain(rsp.content, output_type)
- print(
- '[初始化]--------------------------json.loads得到--------------------------'
- )
- print(game_intro)
- model.input_init(game_intro["故事简介"], game_intro["角色设定"],
- game_intro["数值系统"], game_intro["游戏通关所需条件"])
- value_langchain()
- return game_intro
|