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:- Open a terminal or command prompt.
- Type the following command and press Enter:
pip3 install package_nameReplace "package_name" with the actual name of the package you want to install.
- If this doesn't work, it's likely that the command has been modified for a different version. Check the documentation or the project website for guidance on how to access PyPi for your specific Python environment and version.
Example
Jinja call:
{{ "What are the benefits of Python?" | llm_complete(model="ollama/smollm2:360m", system_prompt="You are a helpful programming assistant.") }}
Python is an interpreted language that allows for easy development and deployment of web applications and data science projects. It has strong support for multiple programming paradigms, including object-oriented, functional, and procedural programming. Additionally, Python's simplicity and ease of use make it suitable for a wide range of tasks across various industries.
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 simple syntax and is easy to read and write, which makes it an attractive choice among developers. Its popularity can be attributed to this ease of use.
-
Frameworks: Libraries like NumPy (for numerical computations), pandas (for data manipulation and analysis), and scikit-learn (for machine learning) are built in Python. These libraries simplify tasks such as data cleaning, visualization, and modeling.
-
Integration with Other Libraries: Python integrates seamlessly with popular data science tools like R, Julia, and Excel. This facilitates the creation of complex analyses through a unified interface.
-
Community Support: The Python community is vast and supportive. There are numerous forums, blogs, and documentation available for learning and troubleshooting common issues.
-
Hands-On Experience: Python offers hands-on experience with data analysis using libraries like Matplotlib and Seaborn (for visualization), which can help build a portfolio of projects that showcase expertise in data science.
In summary, Python's role in data science is crucial because it simplifies the process of working with data, allows easy integration with other tools, facilitates hands-on experience through frameworks and documentation, and provides a robust ecosystem for learning, collaborating, and contributing to projects involving data analysis.`
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 |
|