Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,54 @@
|
|
1 |
import openai
|
2 |
import requests
|
3 |
|
|
|
|
|
|
|
4 |
def interpret_prompt(prompt):
|
5 |
-
# Call GPT model
|
6 |
-
response =
|
7 |
-
model="gpt-4",
|
8 |
-
messages=[
|
|
|
|
|
9 |
)
|
10 |
-
return response.choices[0].message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def post_to_erp(accounting_entry):
|
13 |
-
#
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
response = requests.post(url, json=accounting_entry, headers=headers)
|
17 |
return response.json()
|
18 |
|
|
|
19 |
prompt = "Received $245 from Tylor Smith today"
|
|
|
|
|
20 |
interpretation = interpret_prompt(prompt)
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
result = post_to_erp(accounting_entry)
|
23 |
-
print(result)
|
|
|
1 |
import openai
|
2 |
import requests
|
3 |
|
4 |
+
# Initialize OpenAI client
|
5 |
+
client = openai.OpenAI(api_key="YOUR_API_KEY") # Replace with your real API key
|
6 |
+
|
7 |
def interpret_prompt(prompt):
|
8 |
+
# Call OpenAI GPT model
|
9 |
+
response = client.chat.completions.create(
|
10 |
+
model="gpt-4", # You can also use "gpt-3.5-turbo" if preferred
|
11 |
+
messages=[
|
12 |
+
{"role": "user", "content": prompt}
|
13 |
+
]
|
14 |
)
|
15 |
+
return response.choices[0].message.content
|
16 |
+
|
17 |
+
def map_to_journal_entry(interpretation):
|
18 |
+
"""
|
19 |
+
This is a placeholder function.
|
20 |
+
In real implementation, parse 'interpretation' to map correct accounts and amounts.
|
21 |
+
For demo, returning dummy entry.
|
22 |
+
"""
|
23 |
+
return {
|
24 |
+
"date": "2025-05-02",
|
25 |
+
"journal_id": 1, # Example journal
|
26 |
+
"lines": [
|
27 |
+
{"account_id": 101, "debit": 0, "credit": 245, "partner": "Tylor Smith"}, # AR
|
28 |
+
{"account_id": 201, "debit": 245, "credit": 0, "partner": "Tylor Smith"} # Bank/Cash
|
29 |
+
]
|
30 |
+
}
|
31 |
|
32 |
def post_to_erp(accounting_entry):
|
33 |
+
url = "https://your-odoo-instance.com/api/account.move" # Replace with your Odoo API endpoint
|
34 |
+
headers = {
|
35 |
+
"Authorization": "Bearer YOUR_ODOO_API_TOKEN",
|
36 |
+
"Content-Type": "application/json"
|
37 |
+
}
|
38 |
response = requests.post(url, json=accounting_entry, headers=headers)
|
39 |
return response.json()
|
40 |
|
41 |
+
# Example user prompt
|
42 |
prompt = "Received $245 from Tylor Smith today"
|
43 |
+
|
44 |
+
# Step 1: Interpret prompt
|
45 |
interpretation = interpret_prompt(prompt)
|
46 |
+
print("AI Interpretation:", interpretation)
|
47 |
+
|
48 |
+
# Step 2: Map to journal entry
|
49 |
+
accounting_entry = map_to_journal_entry(interpretation)
|
50 |
+
print("Mapped Entry:", accounting_entry)
|
51 |
+
|
52 |
+
# Step 3: Post to ERP
|
53 |
result = post_to_erp(accounting_entry)
|
54 |
+
print("ERP API Response:", result)
|