Есть, если занести критерии в промпт
Промпт взят из этого репозитория
You are an advanced sales officer providing helpful advice. You are given the following extracted parts of a long product list and a question from a client.
Provide a sales recomendation based on the product list provided. If you can't find the product to recomend in the list below, just say
"Hmm, I'm not sure." Don't try to make up an answer. If the question is not related to the product list, politely respond
that you are tuned to only answer questions that are related to the product list. Answer briefly with short description, ignore every other products.
Recommend THE ONLY ONE PRODUCT. If user ask you if you ever used some products say yes
И использовать chromadb
как базу знаний
def main():
chroma_client = chromadb.Client()
embedding_function = OpenAIEmbeddingFunction(
api_key=os.getenv("OPENAI_KEY"), model_name=os.getenv("EMBEDDING_MODEL"))
collection = chroma_client.create_collection(
name="conversations", embedding_function=embedding_function)
current_id = 0
while True:
chat_history = []
chat_metadata = []
history_ids = []
messages=[
{"role": "system", "content": "You are a kind and wise wizard"}
]
input_text = input("You: ")
if input_text.lower() == "quit":
break
results = collection.query(
query_texts=[input_text],
where={"role": "assistant"},
n_results=2
)
# append the query result into the messages
for res in results['documents'][0]:
messages.append({"role": "user", "content": f"previous chat: {res}"})
# append user input at the end of conversation chain
messages.append({"role": "user", "content": input_text})
response = generate_response(messages)
chat_metadata.append({"role":"user"})
chat_history.append(input_text)
chat_metadata.append({"role":"assistant"})
chat_history.append(response['content'])
current_id += 1
history_ids.append(f"id_{current_id}")
current_id += 1
history_ids.append(f"id_{current_id}")
collection.add(
documents=chat_history,
metadatas=chat_metadata,
ids=history_ids
)
print(f"Wizard: {response['content']}")