gutendex processing implementation

This commit is contained in:
Doar Mihai
2026-03-29 15:23:02 +03:00
parent 7be6af781b
commit 93fef1512a
7 changed files with 542 additions and 0 deletions
+173
View File
@@ -0,0 +1,173 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Ollama API URL
|--------------------------------------------------------------------------
|
| The base URL for your local Ollama API instance. By default, Ollama
| runs on localhost:11434. Update this if running on a different host.
|
*/
'api_url' => env('OLLAMA_API_URL', 'http://localhost:11434'),
/*
|--------------------------------------------------------------------------
| Default Model
|--------------------------------------------------------------------------
|
| The default Ollama model to use for generating summaries. Popular
| options include: llama3, llama2, mistral, mixtral, phi, gemma.
| Make sure the model is pulled: ollama pull <model_name>
|
*/
'model' => env('OLLAMA_MODEL', 'llama3'),
/*
|--------------------------------------------------------------------------
| Request Timeout
|--------------------------------------------------------------------------
|
| Maximum time in seconds to wait for a response from Ollama.
| Summary generation can take several minutes for long texts.
|
*/
'timeout' => env('OLLAMA_TIMEOUT', 300),
/*
|--------------------------------------------------------------------------
| Maximum Tokens
|--------------------------------------------------------------------------
|
| Maximum number of tokens to send to the model. Most models have
| context limits (e.g., 4096, 8192, 32768). Adjust based on your model.
|
*/
'max_tokens' => env('OLLAMA_MAX_TOKENS', 4000),
/*
|--------------------------------------------------------------------------
| Temperature
|--------------------------------------------------------------------------
|
| Controls randomness in generation. Lower values (0.1-0.5) are more
| deterministic and factual. Higher values (0.7-1.0) are more creative.
| For summaries, a lower temperature is recommended.
|
*/
'temperature' => env('OLLAMA_TEMPERATURE', 0.3),
/*
|--------------------------------------------------------------------------
| Retry Configuration
|--------------------------------------------------------------------------
|
| Configuration for retrying failed Ollama API requests.
| - max_attempts: Maximum number of retry attempts
| - backoff_multiplier: Multiplier for exponential backoff (in seconds)
|
*/
'retry' => [
'max_attempts' => env('OLLAMA_RETRY_MAX_ATTEMPTS', 3),
'backoff_multiplier' => env('OLLAMA_RETRY_BACKOFF', 5),
],
/*
|--------------------------------------------------------------------------
| Text Extraction
|--------------------------------------------------------------------------
|
| Configuration for extracting representative excerpts from books.
| - max_length: Maximum character length of text to send to Ollama
| - strategy: 'beginning', 'middle', 'end', or 'distributed'
|
*/
'text_extraction' => [
'max_length' => env('OLLAMA_TEXT_MAX_LENGTH', 50000),
'strategy' => env('OLLAMA_TEXT_STRATEGY', 'beginning'),
],
/*
|--------------------------------------------------------------------------
| Prompt Templates
|--------------------------------------------------------------------------
|
| Templates for prompts sent to Ollama. Available placeholders:
| {title}, {author}, {text}, {summary}
|
*/
'prompts' => [
'summary' => env('OLLAMA_PROMPT_SUMMARY',
"You are a literary expert tasked with creating comprehensive book summaries. " .
"Analyze the following excerpt from \"{title}\" by {author} and provide a detailed, " .
"engaging summary that captures the main themes, key points, and overall significance " .
"of the work. Focus on what makes this book important and valuable to readers. " .
"Keep the summary between 400-600 words.\n\n" .
"Book excerpt:\n{text}\n\n" .
"Summary:"
),
'key_insights' => env('OLLAMA_PROMPT_INSIGHTS',
"Based on the following book summary, extract 5-7 key insights, lessons, or takeaways " .
"that readers should remember. Format your response as a concise bullet list with each " .
"insight on its own line, starting with a dash (-).\n\n" .
"Book: \"{title}\" by {author}\n\n" .
"Summary:\n{summary}\n\n" .
"Key Insights:"
),
'categorize' => env('OLLAMA_PROMPT_CATEGORIZE',
"Based on the following book information, suggest the most appropriate category " .
"from this list: Fiction, Non-Fiction, Science Fiction, Fantasy, Mystery, Romance, " .
"Historical Fiction, Biography, History, Philosophy, Science, Technology, Business, " .
"Self-Help, Poetry, Drama, Children. Respond with ONLY the category name.\n\n" .
"Book: \"{title}\" by {author}\n" .
"Description: {description}\n\n" .
"Category:"
),
],
/*
|--------------------------------------------------------------------------
| Summary Quality Checks
|--------------------------------------------------------------------------
|
| Minimum quality thresholds for generated summaries.
| Summaries below these thresholds will be marked for review.
|
*/
'quality_checks' => [
'min_word_count' => env('OLLAMA_MIN_WORD_COUNT', 100),
'max_word_count' => env('OLLAMA_MAX_WORD_COUNT', 1000),
'min_sentence_count' => env('OLLAMA_MIN_SENTENCE_COUNT', 5),
],
/*
|--------------------------------------------------------------------------
| Model Options
|--------------------------------------------------------------------------
|
| Additional options to pass to the Ollama API.
| See: https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
|
*/
'options' => [
'num_predict' => env('OLLAMA_NUM_PREDICT', 1000), // Max tokens to generate
'top_k' => env('OLLAMA_TOP_K', 40),
'top_p' => env('OLLAMA_TOP_P', 0.9),
'repeat_penalty' => env('OLLAMA_REPEAT_PENALTY', 1.1),
],
];