Probably functional. Testing
This commit is contained in:
+4
-26
@@ -5,17 +5,14 @@ import os
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from dotenv import load_dotenv
|
||||
from openai import OpenAI
|
||||
|
||||
|
||||
class LLMClient:
|
||||
def __init__(self, prompts_dir: Path):
|
||||
load_dotenv()
|
||||
|
||||
self.api_url = os.getenv('OPENAI_API_URL', 'https://api.openai.com/v1')
|
||||
self.model = os.getenv('OPENAI_MODEL', 'gpt-4')
|
||||
self.api_key = os.getenv('OPENAI_API_KEY', '')
|
||||
def __init__(self, prompts_dir: Path, api_config: dict):
|
||||
self.api_url = api_config.get('url', 'https://api.openai.com/v1')
|
||||
self.model = api_config.get('model', 'gpt-4')
|
||||
self.api_key = api_config.get('api_key', '')
|
||||
|
||||
self.client = OpenAI(
|
||||
base_url=self.api_url,
|
||||
@@ -23,25 +20,6 @@ class LLMClient:
|
||||
) if self.api_key else None
|
||||
|
||||
self.prompts_dir = prompts_dir
|
||||
if not prompts_dir.exists():
|
||||
prompts_dir.mkdir(parents=True)
|
||||
self._create_default_prompt()
|
||||
|
||||
def _create_default_prompt(self):
|
||||
"""Create default system prompt"""
|
||||
default_prompt = """You are a metadata extraction assistant for markdown documents.
|
||||
|
||||
Your task is to analyze the document content and suggest appropriate frontmatter metadata.
|
||||
|
||||
Guidelines:
|
||||
- For tags: prefer selecting from the provided existing tags list when appropriate
|
||||
- You may create new tags if they better fit the content
|
||||
- New tags must follow the rules: lowercase letters, numbers, and underscores only
|
||||
- Be concise and accurate
|
||||
- Preserve important existing metadata when present"""
|
||||
|
||||
with open(self.prompts_dir / 'default.txt', 'w', encoding='utf-8') as f:
|
||||
f.write(default_prompt)
|
||||
|
||||
def load_prompt(self, name: str = 'default') -> str:
|
||||
"""Load prompt template"""
|
||||
|
||||
Reference in New Issue
Block a user