Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to the LLMs to be shown in the components gallery #714

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/distilabel/llms/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,50 @@ class AnthropicLLM(AsyncLLM):
- `timeout`: the maximum time in seconds to wait for a response. Defaults to `600.0`.
- `max_retries`: the maximum number of times to retry the request before failing.
Defaults to `6`.

Examples:

Generate text:

```python
from distilabel.llms import AnthropicLLM

llm = AnthropicLLM(model="claude-3-opus-20240229", api_key="api.key")

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Hello world!"}])
```

Generate structured data:

```python
from pydantic import BaseModel
from distilabel.llms import AnthropicLLM

class User(BaseModel):
name: str
last_name: str
id: int

llm = AnthropicLLM(
model="claude-3-opus-20240229",
api_key="api.key",
structured_output={"schema": User}
)

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Create a user profile for the following marathon"}])
```
"""

model: str
Expand Down
18 changes: 18 additions & 0 deletions src/distilabel/llms/anyscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ class AnyscaleLLM(OpenAILLM):
`None` if not set.
_api_key_env_var: the name of the environment variable to use for the API key.
It is meant to be used internally.

Examples:

Generate text:

```python
from distilabel.llms import AnyscaleLLM

llm = AnyscaleLLM(model="google/gemma-7b-it", api_key="api.key")

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Hello world!"}])
```
"""

base_url: Optional[RuntimeParameter[str]] = Field(
Expand Down
63 changes: 63 additions & 0 deletions src/distilabel/llms/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,69 @@ class AzureOpenAILLM(OpenAILLM):

Icon:
`:simple-microsoftazure:`

Examples:

Generate text:

```python
from distilabel.llms import AzureOpenAILLM

llm = AzureOpenAILLM(model="gpt-4-turbo", api_key="api.key")

llm.load()

# Synchrounous request
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Hello world!"}])
```

Generate text from a custom endpoint following the OpenAI API:

```python
from distilabel.llms import AzureOpenAILLM

llm = AzureOpenAILLM(
model="prometheus-eval/prometheus-7b-v2.0",
base_url=r"http://localhost:8080/v1"
)

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Hello world!"}])
```

Generate structured data:

```python
from pydantic import BaseModel
from distilabel.llms import AzureOpenAILLM

class User(BaseModel):
name: str
last_name: str
id: int

llm = AzureOpenAILLM(
model="gpt-4-turbo",
api_key="api.key",
structured_output={"schema": User}
)

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Create a user profile for the following marathon"}])
```
"""

base_url: Optional[RuntimeParameter[str]] = Field(
Expand Down
40 changes: 40 additions & 0 deletions src/distilabel/llms/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,46 @@ class CohereLLM(AsyncLLM):
to `120`.
- `client_name`: the name of the client to use for the API requests. Defaults to
`"distilabel"`.

Examples:

Generate text:

```python
from distilabel.llms import CohereLLM

llm = CohereLLM(model="CohereForAI/c4ai-command-r-plus")

llm.load()

# Call the model
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

Generate structured data:

```python
from pydantic import BaseModel
from distilabel.llms import CohereLLM

class User(BaseModel):
name: str
last_name: str
id: int

llm = CohereLLM(
model="CohereForAI/c4ai-command-r-plus",
api_key="api.key",
structured_output={"schema": User}
)

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Create a user profile for the following marathon"}])
```
"""

model: str
Expand Down
40 changes: 40 additions & 0 deletions src/distilabel/llms/groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,46 @@ class GroqLLM(AsyncLLM):
failing. Defaults to `2`.
- `timeout`: the maximum time in seconds to wait for a response from the API. Defaults
to `120`.

Examples:

Generate text:

```python
from distilabel.llms import GroqLLM

llm = GroqLLM(model="llama3-70b-8192")

llm.load()

# Call the model
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

Generate structured data:

```python
from pydantic import BaseModel
from distilabel.llms import GroqLLM

class User(BaseModel):
name: str
last_name: str
id: int

llm = GroqLLM(
model="llama3-70b-8192",
api_key="api.key",
structured_output={"schema": User}
)

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Create a user profile for the following marathon"}])
```
"""

model: str
Expand Down
15 changes: 15 additions & 0 deletions src/distilabel/llms/huggingface/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ class TransformersLLM(LLM, CudaDevicePlacementMixin):

Icon:
`:hugging:`

Examples:

Generate text:

```python
from distilabel.llms import TransformersLLM

llm = TransformersLLM(model="microsoft/Phi-3-mini-4k-instruct")

llm.load()

# Call the model
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])
```
"""

model: str
Expand Down
40 changes: 40 additions & 0 deletions src/distilabel/llms/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,46 @@ class LiteLLM(AsyncLLM):

Runtime parameters:
- `verbose`: whether to log the LiteLLM client's logs. Defaults to `False`.

Examples:

Generate text:

```python
from distilabel.llms import LiteLLM

llm = LiteLLM(model="gpt-3.5-turbo")

llm.load()

# Call the model
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])

Generate structured data:

```python
from pydantic import BaseModel
from distilabel.llms import LiteLLM

class User(BaseModel):
name: str
last_name: str
id: int

llm = LiteLLM(
model="gpt-3.5-turbo",
api_key="api.key",
structured_output={"schema": User}
)

llm.load()

# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])

# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Create a user profile for the following marathon"}])
```
"""

model: str
Expand Down
52 changes: 52 additions & 0 deletions src/distilabel/llms/llamacpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,58 @@ class LlamaCppLLM(LLM):
References:
- [`llama.cpp`](https://github.com/ggerganov/llama.cpp)
- [`llama-cpp-python`](https://github.com/abetlen/llama-cpp-python)

Examples:

Generate text:

```python
from pathlib import Path
from distilabel.llms import LlamaCppLLM

# You can follow along this example downloading the following model running the following
# command in the terminal, that will download the model to the `Downloads` folder:
# curl -L -o ~/Downloads/openhermes-2.5-mistral-7b.Q4_K_M.gguf https://huggingface.co/TheBloke/OpenHermes-2.5-Mistral-7B-GGUF/resolve/main/openhermes-2.5-mistral-7b.Q4_K_M.gguf

model_path = "Downloads/openhermes-2.5-mistral-7b.Q4_K_M.gguf"

llm = LlamaCppLLM(
model_path=str(Path.home() / model_path),
n_gpu_layers=-1, # To use the GPU if available
n_ctx=1024, # Set the context size
)

llm.load()

# Call the model
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])
```

Generate structured data:

```python
from pathlib import Path
from distilabel.llms import LlamaCppLLM

model_path = "Downloads/openhermes-2.5-mistral-7b.Q4_K_M.gguf"

class User(BaseModel):
name: str
last_name: str
id: int

llm = LlamaCppLLM(
model_path=str(Path.home() / model_path), # type: ignore
n_gpu_layers=-1,
n_ctx=1024,
structured_output={"format": "json", "schema": Character},
)

llm.load()

# Call the model
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])
```
"""

model_path: RuntimeParameter[FilePath] = Field(
Expand Down
Loading
Loading