Aplicación RAG (Generación de la recuperación de la recuperación) para ofrecer preguntas y respuestas en un texto de formato largo utilizando OpenAI y Elasticsearch. Aquí estamos
python -m venv venv source venv/bin/activatepip install -r requirements.txtpython -m spacy download en_core_web_smbin/elasticsearch (o binelasticsearch.bat en Windows)curl -X GET "localhost:9200/" en la terminal Antes de ejecutar la aplicación, cree el archivo .env usando .env-template y agregue la tecla API OpenAI y las credenciales de Elasticsearch.
python run.py La aplicación comenzará en localhost en el puerto 8081 . Verificación de cordura al ejecutar en la terminal. Debería devolver el mensaje Hello .
curl -X GET " localhost:8081 " curl --location --request PUT ' http://localhost:9200/first-index '
--header ' Content-Type: application/json '
--data-raw ' {
"mappings": {
"properties": {
"text": {
"type": "text"
},
"embedding": {
"type": "dense_vector",
"dims": 1536
}
}
}
} 'Si desea eliminar el índice para un inicio limpio, use el siguiente comando.
curl --location --request DELETE ' http://localhost:9200/first-index ' Para indexar datos, use el siguiente comando curl . Este comando envía una solicitud de publicación al punto final especificado con una carga útil JSON que contiene el texto que se indexará y el nombre del índice.
Asegúrese de que el servidor se ejecute en localhost en el puerto 8081 .
curl --location --request POST ' localhost:8081/api/index '
--header ' Content-Type: application/json '
--data-raw ' {
"text": "Ajeet is an engineer turned product entrepreneur with experience in AI, SaaS, HealthTech and EdTech. He is a technology enthusiast and loves to work on new technologies. He was a founding member of leading health-tech startups HealthKart and TATA 1mg in India. He was the founder of Joe Hukum, a chatbot platform which was acquired by Freshworks. After Freshworks, he founded Seekho.ai to solve for the skill gap in Indian higher education. Currently, he is on a break and is exploring GenAI to solve for the next meaningful problem. He is passionate about solving zero to one problems and building products that can impact millions of lives.",
"index_name": "first-index"
} 'Ejemplo 1:
curl --location --request POST ' localhost:8081/api/query '
--header ' Content-Type: application/json '
--data-raw ' {
"question": "Who is Ajeet?",
"index_name": "first-index"
} 'Ejemplo 2:
curl --location --request POST ' localhost:8081/api/query '
--header ' Content-Type: application/json '
--data-raw ' {
"question": "Joe Hukum was acquired by which company?",
"index_name": "first-index"
} '