Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ docker run -d -p 8000:8000 -e GEMINI_API_KEY=api_key_here <IMAGE-ID>
curl -X POST "http://<IP>:8000/ask-ai" -H "Content-Type: application/json" -d '{\"query\": \"<QUESTION>\"}'

curl -X POST "http://<IP>:8000/ask-ai" -H "Content-Type: application/json" -d "{\"query\": \"<QUESTION>\"}"

curl -X POST "http://127.0.0.1:8000/ask-ai" -H "Content-Type: application/json" -d "{\"query\": \"what is SnapDragon?\", \"user_ID\": \"0001\", \"context\": [\"nothing\"]}"
11 changes: 7 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ def run_script():
@app.post("/ask-ai")
def ask_ai(data: InputData):
try:
docs = list(users_collection.find({"user_id": data.user_ID}))
docs = list(users_collection.find({"user_id": data.user_ID}).sort("_id", -1).limit(5))
if docs:
history = []
for doc in docs:
for doc in docs[::-1]:
history.append({
"user_prompt": doc.get("user_promt", ""),
"AI": doc.get("AI", "")
})
print("History loaded from MongoDB:", history)
print("Last five history loaded from MongoDB:", history)
else:
history = []

if data.context:
joined_context = "\n\n".join(data.context)
if isinstance(data.context, list):
joined_context = "\n\n".join(data.context)
else:
joined_context = str(data.context)
payload = json.dumps({"query": data.query, "context": joined_context, "history": history})
else:
payload = json.dumps({"query": data.query, "history": history})
Expand Down