makes statements work.

This commit is contained in:
2024-06-07 10:51:38 -07:00
parent 6ea21f7d87
commit 6b3d076e12
4 changed files with 65 additions and 56 deletions

View File

@@ -9,7 +9,7 @@ def slurp_file(filename):
data = file.read()
return data
BASE_PROMPT="""You extract invoice details from pdfs. Always follow this json schema. Do not respond with anything except the raw json response. Do not respond in code blocks(```).
BASE_PROMPT="""You extract invoice details from pdfs. Some pdfs are invoices, some are credits, and some are statements that may contain statements or credits. Numbers in parenthesis typically indicate credits. Always follow this json schema. Do not respond with anything except the raw json response. Do not respond in code blocks(```).
```
{}
```
@@ -22,6 +22,7 @@ import sys
client = openai.OpenAI(api_key= "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")
client.api_key = "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"
def handler(event, context):
print(event)
assistant = client.beta.assistants.create(
name="pdf-reader",
instructions=BASE_PROMPT,
@@ -30,8 +31,9 @@ def handler(event, context):
)
import urllib.request
url = event.url
with urllib.request.urlopen(url) as response:
url = event['url']
print ("URL IS", url)
with urllib.request.urlopen(event['url']) as response:
data = response.read()
with open("/tmp/test.pdf", "wb") as f:
f.write(data)
@@ -46,7 +48,7 @@ def handler(event, context):
messages=[
{
"role": "user",
"content": "extract the details from this invoice",
"content": "extract the invoice(s) and/or credit(s) details from this invoice or statement",
# Attach the new file to the message.
"attachments": [
{ "file_id": message_file.id, "tools": [{"type": "file_search"}] }