我使用的是llamaindex聊天引擎,运行正常但是系统提示不起作用。 我也将其更改为 context_prompt 。 但它没有生效。 如果我能得到一些我错的方向。
llm = Anthropic(model="claude-3-5-sonnet-20240620")
query = request.json.get('query')
memory = ChatMemoryBuffer.from_defaults(token_limit=5000)
session = request.json.get('session_id')
customer_data = request.json.get('customer_data')
host = "mongodb+srv://y?
retryWrites=true&w=majority"
port = 27017
db_name = "data-entry"
collection_name = "experience"
query_dict = {}
field_names = ["_id", "title", "description", "address", "price", "duration",
"availableTime", "links",
"termsAndConditions", "storyLineKeywords", "linkWithOtherExperience"]
reader = SimpleMongoReader(host, port)
documents = reader.load_data(
db_name, collection_name, field_names, query_dict=query_dict
)
index = SummaryIndex.from_documents(documents)
chat_engine = index.as_chat_engine(
memory=memory,
llm=llm,
similarity_top_k=2,
system_prompt=(
"Only return the suggested experience '_id' and 'title'"
),
verbose=False,
)
response = chat_engine.chat(query)
print(response)
我认为您的问题可能是您正在使用一个模型创建索引并使用另一个模型创建聊天引擎。
如果未指定 llm,Llama Index 默认使用 OpenAI。
因此,在您的代码中,您似乎可能正在使用 OpenAI 创建索引,然后为聊天引擎设置 Anthropic。
我会尝试在创建索引之前设置 llm,如下所示:
Settings.llm = llm