Skip to content

Commit

Permalink
Add langchain Azure OpenAI test (#317)
Browse files Browse the repository at this point in the history
* Add langchain Azure OpenAI test.

* Update readme.
  • Loading branch information
rmitsch authored Oct 5, 2023
1 parent 8a2ea45 commit b0d3ad2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ This package integrates Large Language Models (LLMs) into [spaCy](https://spacy.
- **[OpenAI](https://platform.openai.com/docs/api-reference/)**
- **[Cohere](https://docs.cohere.com/reference/generate)**
- **[Anthropic](https://docs.anthropic.com/claude/reference/)**
- **[PaLM](https://ai.google/discover/palm2/)**
- Supports open-source LLMs hosted on Hugging Face 🤗:
- **[Falcon](https://huggingface.co/tiiuae)**
- **[Dolly](https://huggingface.co/databricks)**
- **[Llama 2](https://huggingface.co/meta-llama)**
- **[OpenLLaMA](https://huggingface.co/openlm-research)**
- **[StableLM](https://huggingface.co/stabilityai)**
- **[Mistral](https://huggingface.co/mistralai)**
- Integration with [LangChain](https://github.com/hwchase17/langchain) 🦜️🔗 - all `langchain` models and features can be used in `spacy-llm`
- Tasks available out of the box:
- Named Entity Recognition
Expand All @@ -31,6 +33,9 @@ This package integrates Large Language Models (LLMs) into [spaCy](https://spacy.
- Sentiment analysis
- Span categorization
- Summarization
- Soon:
- Entity linking
- Semantic role labeling
- Easy implementation of **your own functions** via [spaCy's registry](https://spacy.io/api/top-level#registry) for custom prompting, parsing and model integrations

## 🧠 Motivation
Expand Down
29 changes: 29 additions & 0 deletions spacy_llm/tests/models/test_langchain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

import pytest
import spacy

from spacy_llm.compat import has_langchain
from spacy_llm.tests.compat import has_azure_openai_key

PIPE_CFG = {
"model": {
Expand All @@ -21,3 +24,29 @@ def test_initialization():
nlp = spacy.blank("en")
nlp.add_pipe("llm", config=PIPE_CFG)
nlp("This is a test.")


@pytest.mark.external
@pytest.mark.skipif(has_langchain is False, reason="LangChain is not installed")
@pytest.mark.skipif(
has_azure_openai_key is False, reason="Azure OpenAI key not available"
)
def test_initialization_azure_openai():
"""Test initialization and simple run with Azure OpenAI."""
os.environ["OPENAI_API_KEY"] = os.environ["AZURE_OPENAI_KEY"]
_pipe_cfg = {
"model": {
"@llm_models": "langchain.AzureOpenAI.v1",
"name": "gpt-35-turbo",
"config": {
"deployment_name": "gpt-35-turbo",
"openai_api_version": "2023-05-15",
"openai_api_base": "https://explosion.openai.azure.com/",
},
},
"task": {"@llm_tasks": "spacy.NoOp.v1"},
}

nlp = spacy.blank("en")
nlp.add_pipe("llm", config=_pipe_cfg)
nlp("This is a test.")

0 comments on commit b0d3ad2

Please sign in to comment.