llm (1)
llm_complete¶
llm_complete(prompt: str, system_prompt: str | None = None, context: str | None = None, model: str | None = None, token: str | None = None, base_url: str | None = None, **kwargs: Any) -> str
Complete a prompt using the LLM API.
Required packages: litellm
Example
Jinja call:
Result:Here's an easy-to-follow guide on how to install a package from PyPI using the following commands:
1. Open your terminal or command prompt and navigate into the directory where you want to install the package.
2. Run the following command in the terminal (on Linux, macOS, or Windows) depending on your system's package manager:
pip install package_name- Example for Python 3.x:
python3 -m pip install package_name- Example for Java or other JVM-specific packages:
java -jar path/to/package.war --exec /path/to/some/directory`
- After you've installed the package, make sure to update your system's package index by running:
pip install --upgrade pip
- To test that the installation was successful and the package is now available on PyPI, run:
python -c "import setuptools; print(setuptools.__version__)"
- You can then use Python with the package as usual by importing it in your code: `import package_name``
Example
Jinja call:
{{ "What are the benefits of Python?" | llm_complete(model="ollama/smollm2:360m", system_prompt="You are a helpful programming assistant.") }}
- Easy to learn: Python has a simple syntax and beginner-friendly codebase that makes it an ideal choice for beginners, even those without prior programming experience.
- High-performance: Python is known for its performance and efficiency in data processing tasks such as NumPy arrays and Pandas DataFrames, which are essential for big data analysis and machine learning.
- Cross-platform compatibility: Python can run on multiple operating systems including Windows, macOS, Linux, and Unix, making it a popular choice among developers working with various environments.
- Large community: The Python ecosystem is vast and has numerous libraries and frameworks available for different use cases such as web development, data analysis, artificial intelligence, and more.
- Versatile applications: Python can be used in a wide range of applications including automation, games, scientific computing, data science, machine learning, and more.
- Extensive libraries and frameworks: Python has an extensive collection of libraries and frameworks that make it easy to develop complex applications quickly. Examples include NumPy, pandas, scikit-learn, and TensorFlow for machine learning, Flask for web development, and more.
- Dynamic typing: Python is dynamically typed, which means variables do not need to be explicitly declared with a type before using them. This makes code easier to write and test.
- Extensive documentation: The official Python documentation provides comprehensive information on various topics including libraries, modules, and tutorials.
- Large number of frameworks and tools: Many popular frameworks such as Django, Flask, and NumPy are built upon top of the standard Python library, making it easier to develop applications quickly.
- Open-source and free: Python is open-source software, which means its source code is available for anyone to view and modify. This allows developers to improve the language and contribute to the project without paying a licensing fee.`
Example
Jinja call:
{{ "Explain its importance." | llm_complete(model="ollama/smollm2:360m", context="We were discussing Python's role in data science.") }}
-
Easy to Learn: Python has a vast number of libraries, frameworks, and tools that make it an excellent choice for data analysis and machine learning tasks. This ease of use allows users to quickly develop complex projects without needing to know multiple programming languages.
-
Rapid Development: Python's syntax is very concise and flexible, making it ideal for rapid prototyping and development. This is particularly useful in the data science field where projects often require a high degree of speed and agility.
-
Easy Modularity: Python offers built-in modules (like Pandas, NumPy, and scikit-learn) that allow developers to easily organize their code and reuse it across multiple projects. This modular approach makes it easier to add new features or extend existing ones without starting from scratch each time.
-
Large Community Support: The Python community is incredibly active, with a vast number of open-source projects and contributions. This means that there are many resources available for learning and troubleshooting Python code, making it easy to find help when needed.
-
Cross-Language Interoperability: Python's extensive libraries can be easily used across different programming languages. For example, the Pandas library works seamlessly with other data analysis and visualization tools like Matplotlib and Plotly in various languages.
These reasons highlight Python's importance in the field of data science, making it an essential tool for anyone working on big data projects or creating sophisticated data analysis applications.`
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The prompt to complete. |
required |
system_prompt
|
str | None
|
The system prompt to set context for the model. |
None
|
context
|
str | None
|
Additional context for the prompt. |
None
|
model
|
str | None
|
The model to use. |
None
|
token
|
str | None
|
The API token. |
None
|
base_url
|
str | None
|
The base URL of the API. |
None
|
kwargs
|
Any
|
Additional keyword arguments passed to litellm.completion. |
{}
|
Returns:
Type | Description |
---|---|
str
|
The completed text from the LLM. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API response is invalid or missing expected data. |
Source code in src/jinjarope/llmfilters.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|