Skip to content

Commit

Permalink
chore: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 29, 2024
1 parent 5553fbf commit 96e2f1a
Showing 1 changed file with 83 additions and 16 deletions.
99 changes: 83 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,97 @@ The function will be automatically converted into a prompt with:
- Enum values from Literal types
- Default values preserved

#### Dynamic Registration
> [!TIP]
> Function-based prompts make it easy to create well-documented, type-safe prompts directly from your Python code. The automatic conversion handles argument validation, documentation, and template generation
## Custom Autocompletion

LLMling provides flexible autocompletion for prompt arguments, combining multiple sources of suggestions and allowing custom completion functions.

### Automatic Completions

Register function-based prompts programmatically:
Arguments automatically get completions based on:

1. Type hints:
```python
def analyze_code(
language: Literal["python", "javascript", "rust"],
style: bool = True,
level: Literal["basic", "detailed"] | None = None,
) -> str:
"""Analyze code."""
pass
```

2. Description hints:
```python
from llmling.prompts import PromptRegistry, create_prompt_from_callable
def analyze_text(
text: str,
format: str = "md"
) -> str:
"""Analyze text.
Args:
text: Input text
format: Output format (one of: md, txt, rst)
"""
pass
```

### Custom Completion Functions

registry = PromptRegistry()
You can provide custom completion functions either in code or via configuration:

# Register a single function
registry.register_function(analyze_code)

# Or create a prompt explicitly
prompt = create_prompt_from_callable(
analyze_code,
name_override="custom_name",
description_override="Custom description",
template_override="Custom template: {code}"
)
registry.register(prompt.name, prompt)

### Via YAML Configuration:
```yaml
prompts:
analyze_framework:
import_path: "mymodule.analysis.analyze_framework"
completions:
framework: "mymodule.completions.get_framework_completions"
```
### Completion Priority
Completions are tried in this order:
1. Custom completion function (if provided)
2. Type-based completions (Literal, bool)
3. Description-based completions (from "one of:" syntax)
4. Default value (when no current input)
All completions are:
- Case-insensitive matched against current input
- Deduplicated while preserving order
- Limited to 100 results
### Writing Custom Completion Functions
Custom completion functions should:
1. Take a single string argument (current input)
2. Return a list of strings (possible completions)
3. Handle empty input appropriately
4. Be fast and handle errors gracefully
Example:
```python
def get_language_completions(current: str) -> list[str]:
"""Get programming language suggestions."""
languages = ["python", "javascript", "typescript", "rust", "go"]

# Handle empty input
if not current:
return languages

# Filter based on current input
current = current.lower()
return [
lang for lang in languages
if lang.lower().startswith(current)
]
```

> [!TIP]
> Function-based prompts make it easy to create well-documented, type-safe prompts directly from your Python code. The automatic conversion handles argument validation, documentation, and template generation
### Tools

Tools are Python functions or classes that can be called by LLMs. LLMling automatically generates OpenAI-compatible function schemas.
Expand Down

0 comments on commit 96e2f1a

Please sign in to comment.