Skip to content

Commit

Permalink
the missing [context] left out all the data
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jul 26, 2024
1 parent d86f76c commit 0e0902d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 23 deletions.
62 changes: 62 additions & 0 deletions app/Domains/Prompts/EventPageAsArrayPrompt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Domains\Prompts;

use Illuminate\Support\Facades\Log;

class EventPageAsArrayPrompt
{
public static function prompt(string $context): string
{
Log::info('[LaraChain] - EventPageAsArrayPrompt');

return <<<PROMPT
<ROLE>
You are an AI assistant tasked with extracting event data from website content.
<INSTRUCTIONS>
1. Analyze the provided website HTML content below the <CONTENT> tag.
2. Look for information about events within the content.
3. If no event data is found, respond with a single word: false
4. If event data is found, extract the following information for each event:
- Event Title
- Start Date
- End Date
- Location
- Description
- Any other relevant data
5. Format the extracted data as a JSON array according to the specifications below.
<OUTPUT_FORMAT>
If events are found, return a JSON array with the following structure:
[
{
"title": "Event Title",
"startDate": "Start Date",
"endDate": "End Date",
"location": "Location",
"description": "Description",
"additionalInfo": "Any other relevant data"
},
{
"title": "Event Title",
"startDate": "Start Date",
"endDate": "End Date",
"location": "Location",
"description": "Description",
"additionalInfo": "Any other relevant data"
}
]
If no events are found, return an empty JSON array: []
<CONTENT>
$context
</CONTENT>
Respond only with the JSON array or 'false' if no events are found. Do not include any explanations or additional text in your response.
PROMPT;
}
}
35 changes: 12 additions & 23 deletions app/Domains/Prompts/EventPagePrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,20 @@ public static function prompt(string $context): string
- Location
- Description
- Any other relevant data
5. Format the extracted data as a JSON array according to the specifications below.
5. Format the extracted data as a Markdown according to the specifications below.
<OUTPUT_FORMAT>
If events are found, return a JSON array with the following structure:
[
{
"title": "Event Title",
"startDate": "Start Date",
"endDate": "End Date",
"location": "Location",
"description": "Description",
"additionalInfo": "Any other relevant data"
},
{
"title": "Event Title",
"startDate": "Start Date",
"endDate": "End Date",
"location": "Location",
"description": "Description",
"additionalInfo": "Any other relevant data"
}
]
If no events are found, return an empty JSON array: []
If events are found, return a Markdown with the following structure for each event on the page:
"title": "Event Title",
"startDate": "Start Date",
"endDate": "End Date",
"location": "Location",
"description": "Description",
"additionalInfo": "Any other relevant data"
If no events are found, return the word false
<CONTENT>
$context
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Sources/WebPageSourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Sources;

use App\Domains\Prompts\EventPageAsArrayPrompt;
use App\Domains\Prompts\EventPagePrompt;
use App\Domains\Prompts\WebPagePrompt;
use App\Domains\Sources\SourceTypeEnum;
Expand Down Expand Up @@ -55,6 +56,7 @@ public function getPrompts(): array
return [
'web_page' => WebPagePrompt::prompt('[CONTEXT]'),
'event_data' => EventPagePrompt::prompt('[CONTEXT]'),
'event_data_as_array' => EventPageAsArrayPrompt::prompt('[CONTEXT]'),
];
}
}
3 changes: 3 additions & 0 deletions app/Jobs/GetWebContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function handle(): void
Log::info('[LaraChain] - Web Source Skipping', [
'prompt' => $prompt,
]);

return;
} else {
$promptResultsOriginal = $results->content;

Expand Down Expand Up @@ -113,6 +115,7 @@ public function handle(): void
'source_id' => $this->source->id,
'type' => TypesEnum::HTML,
'subject' => to_utf8($title),
'document_md5' => md5($promptResult),
'link' => $this->webResponseDto->url,
'collection_id' => $this->source->collection_id,
],
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function getFilter(): ?Filter

public function getPrompt(): string
{
if (! str($this->body)->contains('[CONTEXT]')) {
$this->body = str($this->body)->append('[CONTEXT]')->toString();
}

return $this->body;
}

Expand Down
1 change: 1 addition & 0 deletions database/factories/DocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function definition(): array
'link' => $this->faker->url(),
'summary' => $this->faker->text(),
'subject' => $this->faker->text(),
'document_md5' => $this->faker->uuid(),
'original_content' => $this->faker->text(),
'child_type' => StructuredTypeEnum::Narrative,
'file_path' => $this->faker->url(),
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/2024_07_25_194618_add_md5_to_documents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->string('document_md5')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('documents', function (Blueprint $table) {
//
});
}
};

0 comments on commit 0e0902d

Please sign in to comment.