explosion / explosion/spacy-llm
Anthropic error : API failed prompt must start with "\n\nHuman:" turn
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 110
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I'm trying to use spacy-llm for ner task using different models.
When I want to use Claude-2-v1 or Claude-1-v1, I get the same error :
Traceback (most recent call last):
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\model.py", line 73, in _request
r.raise_for_status()
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.anthropic.com/v1/complete
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\alexis\Desktop\git-repo\ner-benchmark\spacy-llm-test.py", line 23, in
nlp = assemble("fewshot.cfg")
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\util.py", line 48, in assemble
return assemble_from_config(config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\util.py", line 28, in assemble_from_config
nlp = load_model_from_config(config, auto_fill=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy\util.py", line 587, in load_model_from_config
nlp = lang_cls.from_config(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy\language.py", line 1864, in from_config
nlp.add_pipe(
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy\language.py", line 821, in add_pipe
pipe_component = self.create_pipe(
^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy\language.py", line 709, in create_pipe
resolved = registry.resolve(cfg, validate=validate)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\confection\__init__.py", line 756, in resolve
resolved, _ = cls._make(
^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\confection\__init__.py", line 805, in _make
filled, _, resolved = cls._fill(
^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\confection\__init__.py", line 860, in _fill
filled[key], validation[v_key], final[key] = cls._fill(
^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\confection\__init__.py", line 877, in _fill
getter_result = getter(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\registry.py", line 33, in anthropic_claude_2
return Anthropic(
^^^^^^^^^^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\base.py", line 64, in __init__
self._verify_auth()
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\model.py", line 51, in _verify_auth
raise err
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\model.py", line 43, in _verify_auth
self(["test"])
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\model.py", line 97, in __call__
responses = [
^
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\model.py", line 98, in
_request({"prompt": f"{SystemPrompt.HUMAN} {prompt}{SystemPrompt.ASST}"})
File "C:\Users\alexis\miniconda3\envs\benchmark\Lib\site-packages\spacy_llm\models\rest\anthropic\model.py", line 81, in _request
raise ValueError(error_msg) from ex
ValueError: Request to Anthropic API failed: {'type': 'invalid_request_error', 'message': 'prompt must start with "\n\nHuman:" turn'}
I am using Spacy-LLM version 0.6.4 and python 3.11.5.
My code is :
```
from spacy_llm.util import assemble
# load the model settings from the config file
nlp = assemble("fewshot.cfg")
doc = nlp("In most patients with isolated unilateral retinoblastoma , tumor development is initiated by somatic inactivation of both alleles of the RB1 gene .")
# print the llm output
print([(ent.text, ent.label_) for ent in doc.ents])
```
My config file is :
```
[paths]
examples = null
[nlp]
lang = "en"
pipeline = ["llm"]
[components]
[components.llm]
factory = "llm"
[components.llm.task]
@llm_tasks = "spacy.NER.v3"
labels = ["DISEASE", "GENE", "CHEMICAL"]
description = Entities related to biomedical text,
specifically focusing on diseases, genes, and chemicals.
Adjectives, verbs, adverbs are not entities.
Pronouns are not entities.
Entities should represent concrete entities within the biomedical domain.
[components.llm.task.label_definitions]
DISEASE = "Known diseases or medical conditions, e.g., diabetes, cancer. Entities should refer to specific diseases rather than general health conditions."
GENE = "Genes or genetic elements mentioned in the text. Entities should represent specific genes or genetic elements, and not general terms related to genetics. For example, 'BRCA1' is an entity, while 'genetic' is not."
CHEMICAL = "Chemicals or substances, e.g., drugs, molecules. Entities should represent specific chemical compounds or substances. General terms related to chemistry, such as 'chemical' or 'substance,' are not entities."
[components.llm.task.examples]
@misc = "spacy.FewShotReader.v1"
path = "examples.json"
[components.llm.model]
@llm_models = "spacy.Claude-2.v1"
config = {"max_tokens_to_sample": 1024}
```
I tried with the ner v2 with and without examples.
I still get the same error.
My API key is also set up as env variable.
I don't know if I miss something or if it's an error.
Thanks in advence for the help.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.