doc: move provider examples to hub (#449)

Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: Jason Liu <jason@jxnl.co>
This commit is contained in:
Ethan Leifer
2024-02-19 21:32:43 -05:00
committed by GitHub
parent 62919b2cf2
commit 23897685f5
10 changed files with 57 additions and 21 deletions
+4 -4
View File
@@ -18,10 +18,10 @@ The goal of the blog is to capture some content that does not neatly fit within
## Integrations
- [Ollama](posts/ollama.md)
- [llama-cpp-python](posts/llama-cpp-python.md)
- [Anyscale](posts/anyscale.md)
- [Together Compute](posts/together.md)
- [Ollama](./../hub/ollama.md)
- [llama-cpp-python](./../hub/llama-cpp-python.md)
- [Anyscale](./../hub/anyscale.md)
- [Together Compute](./../hub/together.md)
## Media
@@ -27,7 +27,7 @@ Instructor's patch enhances a openai api it with the following features:
!!! note "Learn More"
To learn more, please refer to the [docs](../../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../../why.md) page.
To learn more, please refer to the [docs](../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../why.md) page.
## Anyscale
@@ -42,7 +42,7 @@ Let's explore one of the models available in Anyscale's extensive collection!
```python
from openai import OpenAI
from pydantic import BaseModel
import os
import instructor
@@ -55,7 +55,7 @@ class UserDetails(BaseModel):
client = instructor.patch(
OpenAI(
base_url="https://api.endpoints.anyscale.com/v1",
api_key="<YOUR_ANYSCALE_API_KEY>",
api_key=os.environ["ANYSCALE_API_KEY"],
),
# This uses Anyscale's json schema output mode
mode=instructor.Mode.JSON_SCHEMA,
@@ -70,6 +70,7 @@ resp = client.chat.completions.create(
response_model=UserDetails,
)
print(resp)
#> name='Jason' age=20
# # > name='Jason' age=20
```
@@ -23,7 +23,7 @@ Instructor's patch enhances an create call it with the following features:
!!! note "Learn More"
To learn more, please refer to the [docs](../../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../../why.md) page. If you want to check out examples of using Pydantic with Instructor, visit the [examples](../../examples/index.md) page.
To learn more, please refer to the [docs](../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../why.md) page. If you want to check out examples of using Pydantic with Instructor, visit the [examples](../examples/index.md) page.
## llama-cpp-python
@@ -47,14 +47,15 @@ llama = llama_cpp.Llama(
n_gpu_layers=-1,
chat_format="chatml",
n_ctx=2048,
draft_model=LlamaPromptLookupDecoding(num_pred_tokens=2), #(1)!
draft_model=LlamaPromptLookupDecoding(num_pred_tokens=2), # (1)!
logits_all=True,
verbose=False
verbose=False,
)
create = instructor.patch(
create=llama.create_chat_completion_openai_v1, mode=instructor.Mode.JSON_SCHEMA #(2)!
create=llama.create_chat_completion_openai_v1,
mode=instructor.Mode.JSON_SCHEMA, # (2)!
)
@@ -92,7 +93,7 @@ class MeetingInfo(BaseModel):
extraction_stream = create(
response_model=instructor.Partial[MeetingInfo], #(3)!
response_model=instructor.Partial[MeetingInfo], # (3)!
messages=[
{
"role": "user",
@@ -107,7 +108,7 @@ console = Console()
for extraction in extraction_stream:
obj = extraction.model_dump()
console.clear() #(4)!
console.clear() # (4)!
console.print(obj)
```
@@ -116,4 +117,4 @@ We use LlamaPromptLookupDecoding to speed up structured output generation using
3. We use `instructor.Partial` to stream out partial models.
4. This is just a simple example of how to stream out partial models and clear the console.
![](../../img/partial.gif)
![](../img/partial.gif)
@@ -26,7 +26,7 @@ Instructor's patch enhances a openai api it with the following features:
!!! note "Learn More"
To learn more, please refer to the [docs](../../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../../why.md) page.
To learn more, please refer to the [docs](../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../why.md) page.
## Ollama
@@ -31,7 +31,7 @@ Instructor's patch enhances the openai api it with the following features:
!!! note "Learn More"
To learn more, please refer to the [docs](../../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../../why.md) page.
To learn more, please refer to the [docs](../index.md). To understand the benefits of using Pydantic with Instructor, visit the tips and tricks section of the [why use Pydantic](../why.md) page.
## Together AI
+4 -4
View File
@@ -21,10 +21,10 @@ Check us out in [Typescript](https://instructor-ai.github.io/instructor-js/) and
Including but not limited to:
- [Together](./blog/posts/together.md)
- [Ollama](./blog/posts/ollama.md)
- [AnyScale](./blog/posts/anyscale.md)
- [llama-cpp-python](./blog/posts/llama-cpp-python.md)
- [Together](./hub/together.md)
- [Ollama](./hub/ollama.md)
- [AnyScale](./hub/anyscale.md)
- [llama-cpp-python](./hub/llama-cpp-python.md)
## Usage
+10
View File
@@ -168,6 +168,10 @@ nav:
- Introducing Instructor Hub: 'hub/index.md'
- Single Classification Model: 'hub/single_classification.md'
- Multiple Classification Model: 'hub/multiple_classification.md'
- Ollama: 'hub/ollama.md'
- Llama CPP: 'hub/llama-cpp-python.md'
- Together: 'hub/together.md'
- Anyscale: 'hub/anyscale.md'
- Tutorials:
- Tutorials (Notebooks): 'tutorials/1-introduction.ipynb'
- Tips and Tricks: 'tutorials/2-tips.ipynb'
@@ -216,6 +220,12 @@ plugins:
- categories
- tags
enabled: !ENV [CI, false]
- redirects:
redirect_maps:
'blog/posts/ollama.md': 'hub/ollama.md'
'blob/posts/llama-cpp-python.md': 'hub/llama-cpp-python.md'
'blog/posts/together.md': 'hub/together.md'
'blog/posts/anyscale.md': 'hub/anyscale.md'
extra:
analytics:
provider: google
Generated
+18 -1
View File
@@ -1563,6 +1563,24 @@ htmlmin2 = ">=0.1.13"
jsmin = ">=3.0.1"
mkdocs = ">=1.4.1"
[[package]]
name = "mkdocs-redirects"
version = "1.2.1"
description = "A MkDocs plugin for dynamic page redirects to prevent broken links."
optional = false
python-versions = ">=3.6"
files = [
{file = "mkdocs-redirects-1.2.1.tar.gz", hash = "sha256:9420066d70e2a6bb357adf86e67023dcdca1857f97f07c7fe450f8f1fb42f861"},
]
[package.dependencies]
mkdocs = ">=1.1.1"
[package.extras]
dev = ["autoflake", "black", "isort", "pytest", "twine (>=1.13.0)"]
release = ["twine (>=1.13.0)"]
test = ["autoflake", "black", "isort", "pytest"]
[[package]]
name = "mkdocs-rss-plugin"
version = "1.12.0"
@@ -3427,4 +3445,3 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "8a8af75e70138f0eb799bbb22def7e4d69e29a3b85b66f7d5b50c1096114cf79"
+1
View File
@@ -36,6 +36,7 @@ pytest-examples = "^0.0.10"
mkdocs-jupyter = "^0.24.6"
mkdocs-rss-plugin = "^1.12.0"
mkdocs-minify-plugin = "^0.8.0"
mkdocs-redirects = "^1.2.1"
[tool.poetry.group.test-docs.dependencies]
fastapi = "^0.109.2"
+6
View File
@@ -4,6 +4,12 @@ from pytest_examples import find_examples, CodeExample, EvalExample
@pytest.mark.parametrize("example", find_examples("docs/hub"), ids=str)
def test_format_blog(example: CodeExample, eval_example: EvalExample):
if "ollama" in example.source:
return
if "llama_cpp" in example.source:
return
if eval_example.update_examples:
eval_example.format(example)
eval_example.run_print_update(example)