Spaces:
Running
Running
APi Calls#3
Browse files- nlp_service.py +16 -9
- requirements.txt +1 -1
nlp_service.py
CHANGED
@@ -666,7 +666,9 @@ def call_gemini_api(text, api_key):
|
|
666 |
# Example using Google AI Generative Language API (adjust model and endpoint as needed)
|
667 |
# Ensure you have the google-generativeai library installed (`pip install google-generativeai`)
|
668 |
# and the API key is correctly set as an environment variable.
|
669 |
-
|
|
|
|
|
670 |
headers = {
|
671 |
"Content-Type": "application/json"
|
672 |
}
|
@@ -679,17 +681,17 @@ Text: "{text}"
|
|
679 |
|
680 |
Desired JSON output format:
|
681 |
{{
|
682 |
-
"action": "add_expense" | "query_expense",
|
683 |
"status": "success" | "failed",
|
684 |
-
"message": "Confirmation or result summary",
|
685 |
-
"details": {{ // Only for add_expense
|
686 |
"amount": <float>,
|
687 |
-
"currency": "<string>",
|
688 |
-
"category": "<string>",
|
689 |
-
"merchant": "<string>",
|
690 |
"date": "YYYY-MM-DD"
|
691 |
}},
|
692 |
-
"criteria": {{ // Only for query_expense
|
693 |
"category": "<string>",
|
694 |
"merchant": "<string>",
|
695 |
"start_date": "YYYY-MM-DD",
|
@@ -697,7 +699,12 @@ Desired JSON output format:
|
|
697 |
}}
|
698 |
}}
|
699 |
|
700 |
-
If the intent is
|
|
|
|
|
|
|
|
|
|
|
701 |
Provide only the JSON output.
|
702 |
"""
|
703 |
|
|
|
666 |
# Example using Google AI Generative Language API (adjust model and endpoint as needed)
|
667 |
# Ensure you have the google-generativeai library installed (`pip install google-generativeai`)
|
668 |
# and the API key is correctly set as an environment variable.
|
669 |
+
# Use a current model and the v1 endpoint
|
670 |
+
model_name = "gemini-2.0-flash-lite" # Updated model name
|
671 |
+
api_endpoint = f"https://generativelanguage.googleapis.com/v1/models/{model_name}:generateContent?key={api_key}"
|
672 |
headers = {
|
673 |
"Content-Type": "application/json"
|
674 |
}
|
|
|
681 |
|
682 |
Desired JSON output format:
|
683 |
{{
|
684 |
+
"action": "add_expense" | "query_expense" | "unknown" | "info",
|
685 |
"status": "success" | "failed",
|
686 |
+
"message": "Confirmation or result summary or explanation",
|
687 |
+
"details": {{ // Only for add_expense if successful
|
688 |
"amount": <float>,
|
689 |
+
"currency": "<string>", // e.g., "₹", "$", "EUR"
|
690 |
+
"category": "<string>", // e.g., "food", "travel", "shopping"
|
691 |
+
"merchant": "<string>", // e.g., "Starbucks", "Amazon"
|
692 |
"date": "YYYY-MM-DD"
|
693 |
}},
|
694 |
+
"criteria": {{ // Only for query_expense if successful
|
695 |
"category": "<string>",
|
696 |
"merchant": "<string>",
|
697 |
"start_date": "YYYY-MM-DD",
|
|
|
699 |
}}
|
700 |
}}
|
701 |
|
702 |
+
- If the intent is clearly 'add_expense' and details can be extracted, use action "add_expense" and status "success". Include extracted details.
|
703 |
+
- If the intent is clearly 'query_expense' and criteria can be extracted, use action "query_expense" and status "success". Include extracted criteria.
|
704 |
+
- If the intent is unclear, details are missing for adding, or it's a general question/statement not related to adding/querying expenses, use action "unknown" or "info" and status "failed" or "success" respectively. Provide a helpful message.
|
705 |
+
- Ensure date format is YYYY-MM-DD.
|
706 |
+
- Default currency to "₹" if not specified.
|
707 |
+
- Default category to "Uncategorized" if not specified.
|
708 |
Provide only the JSON output.
|
709 |
"""
|
710 |
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
Pillow
|
2 |
flask
|
3 |
-
|
4 |
paddlepaddle
|
5 |
paddleocr
|
6 |
spacy>=3.0.0 # Added spaCy
|
|
|
1 |
Pillow
|
2 |
flask
|
3 |
+
requests # Re-added for Gemini API call
|
4 |
paddlepaddle
|
5 |
paddleocr
|
6 |
spacy>=3.0.0 # Added spaCy
|