| import openai |
| import requests |
|
|
| |
| client = openai.OpenAI(api_key="sk-abc123xyz456YOURREALAPIKEY") |
|
|
| def interpret_prompt(prompt): |
| response = client.chat.completions.create( |
| model="gpt-4", |
| messages=[ |
| {"role": "user", "content": prompt} |
| ] |
| ) |
| return response.choices[0].message.content |
|
|
| def map_to_journal_entry(interpretation): |
| """ |
| This is a placeholder function. |
| In real implementation, parse 'interpretation' to map correct accounts and amounts. |
| For demo, returning dummy entry. |
| """ |
| return { |
| "date": "2025-05-02", |
| "journal_id": 1, |
| "lines": [ |
| {"account_id": 101, "debit": 0, "credit": 245, "partner": "Tylor Smith"}, |
| {"account_id": 201, "debit": 245, "credit": 0, "partner": "Tylor Smith"} |
| ] |
| } |
|
|
| def post_to_erp(accounting_entry): |
| url = "https://your-odoo-instance.com/api/account.move" |
| headers = { |
| "Authorization": "Bearer YOUR_ODOO_API_TOKEN", |
| "Content-Type": "application/json" |
| } |
| response = requests.post(url, json=accounting_entry, headers=headers) |
| return response.json() |
|
|
| prompt = "Received $245 from Tylor Smith today" |
|
|
| |
| interpretation = interpret_prompt(prompt) |
| print("AI Interpretation:", interpretation) |
|
|
| |
| accounting_entry = map_to_journal_entry(interpretation) |
| print("Mapped Entry:", accounting_entry) |
|
|
| |
| result = post_to_erp(accounting_entry) |
| print("ERP API Response:", result) |
|
|