From 23897685f5c2941bb33bbfd7070177d12ea051bb Mon Sep 17 00:00:00 2001 From: Ethan Leifer Date: Mon, 19 Feb 2024 21:32:43 -0500 Subject: [PATCH] doc: move provider examples to hub (#449) Co-authored-by: Jason Liu Co-authored-by: Jason Liu --- docs/blog/index.md | 8 ++++---- docs/{blog/posts => hub}/anyscale.md | 7 ++++--- docs/{blog/posts => hub}/llama-cpp-python.md | 15 ++++++++------- docs/{blog/posts => hub}/ollama.md | 2 +- docs/{blog/posts => hub}/together.md | 2 +- docs/index.md | 8 ++++---- mkdocs.yml | 10 ++++++++++ poetry.lock | 19 ++++++++++++++++++- pyproject.toml | 1 + tests/openai/docs/test_hub.py | 6 ++++++ 10 files changed, 57 insertions(+), 21 deletions(-) rename docs/{blog/posts => hub}/anyscale.md (88%) rename docs/{blog/posts => hub}/llama-cpp-python.md (86%) rename docs/{blog/posts => hub}/ollama.md (91%) rename docs/{blog/posts => hub}/together.md (92%) diff --git a/docs/blog/index.md b/docs/blog/index.md index 76f1326..60530aa 100644 --- a/docs/blog/index.md +++ b/docs/blog/index.md @@ -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 diff --git a/docs/blog/posts/anyscale.md b/docs/hub/anyscale.md similarity index 88% rename from docs/blog/posts/anyscale.md rename to docs/hub/anyscale.md index c1adcf5..ebc049a 100644 --- a/docs/blog/posts/anyscale.md +++ b/docs/hub/anyscale.md @@ -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="", + 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 ``` diff --git a/docs/blog/posts/llama-cpp-python.md b/docs/hub/llama-cpp-python.md similarity index 86% rename from docs/blog/posts/llama-cpp-python.md rename to docs/hub/llama-cpp-python.md index ce0d4b5..dec7635 100644 --- a/docs/blog/posts/llama-cpp-python.md +++ b/docs/hub/llama-cpp-python.md @@ -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) diff --git a/docs/blog/posts/ollama.md b/docs/hub/ollama.md similarity index 91% rename from docs/blog/posts/ollama.md rename to docs/hub/ollama.md index dc3ae85..7fee094 100644 --- a/docs/blog/posts/ollama.md +++ b/docs/hub/ollama.md @@ -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 diff --git a/docs/blog/posts/together.md b/docs/hub/together.md similarity index 92% rename from docs/blog/posts/together.md rename to docs/hub/together.md index 577ed38..58c78f6 100644 --- a/docs/blog/posts/together.md +++ b/docs/hub/together.md @@ -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 diff --git a/docs/index.md b/docs/index.md index ffe30a8..4c8a97d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/mkdocs.yml b/mkdocs.yml index 9c5e865..ed1a333 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 diff --git a/poetry.lock b/poetry.lock index e210db8..6c867d4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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" diff --git a/pyproject.toml b/pyproject.toml index 7fe6e9f..63138d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/openai/docs/test_hub.py b/tests/openai/docs/test_hub.py index 5c982a3..0932f03 100644 --- a/tests/openai/docs/test_hub.py +++ b/tests/openai/docs/test_hub.py @@ -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)