Closed beddows closed 1 year ago
Hello @beddows - a couple of questions?
which python version are you using? And which version of arcee-py?
And would you let us know which method you are trying to hit? Thanks!
Hey @beddows I think the issue comes from you likely being on python < 3.10. I just updated the repo to support 3.8+, and cut a release.
Can you try installing pip install --upgrade 'arcee-py>=0.1.0'
? Thanks!
@beddows that fixed a bug that I had replicated of yours - so hopefully it works! Thanks for surfacing this for us
It works, thanks for the quick fix!
@metric-space found this is still broken for CLI
pip install arcee-py
# installs `arcee-py 0.1.0`
export ARCEE_API_KEY=****
2. created a context in dashboard at app.arcee.ai/\<org\>/contexts named 'music_therapy'
3. copied heading and some text from [this source](https://pubmed.ncbi.nlm.nih.gov/37250411/)
```python dev.py
import arcee
doc_name = "<copied heading>"
doc_text = """<copied content>"""
arcee.upload_doc("music_therapy", doc_name=doc_name, doc_text=doc_text)
python dev.py
Throws:
(venv) shwu@Shubhams-MacBook-Pro temp % python dev.py
Traceback (most recent call last):
File "/Users/shwu/temp/dev.py", line 17, in <module>
arcee.upload_doc("music_therapy", doc_name=doc_name, doc_text=doc_text)
File "/Users/shwu/temp/venv/lib/python3.11/site-packages/arcee/api.py", line 23, in upload_doc
return make_request("post", Route.contexts, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shwu/temp/venv/lib/python3.11/site-packages/arcee/api_handler.py", line 29, in decorator
raise Exception(exception)
Exception: Failed to make request. Response: {"detail":"Method Not Allowed"}
I added a print statement to check the url to which the request was being made:
call: ====> https://api.arcee.ai/v2/Route.contexts {'context_name': 'music_therapy', 'documents': [{'name': 'The effect and mechanisms of music therapy on the autonomic nervous system and brain networks of patients of minimal conscious states: a randomized controlled trial', 'document': "Introduction: Music therapy has been employed as an alternative treatment modality for the arousal therapy of patients with disorders of consciousness (DOC) in clinical settings. However, due to the absence of continuous quantitative measurements and the...
I did some dive in and then changed this line here, from
return make_request("post", Route.contexts, data)
to
return make_request("post", Route.contexts.value, data)
and it seems to be working. Any thoughts on this?
call: ====> https://api.arcee.ai/v2/contexts {'context_name': 'music_therapy', 'documents': [{'name': 'The effect and mechanisms of music therapy on the autonomic nervous system and brain networks of patients of minimal conscious states: a randomized controlled trial', ...
my thoughts
the Route(str, Enum)
enumeration is not being resolved into the value by default (❗️this is in Python 3.11.6
)
I tried a few combinations for Python 3.11.6
Route Definition | Behavior | Notes |
---|---|---|
Route(str, Enum) | ✅ (with Route.\<key>.value) | Requires .value |
Route(StrEnum) | ✅ works as is | No additional step |
Route(Enum) | ✅ (with Route.\<key>.value) | Requires .value |
A few discussions branching from this stack overflow answer do suggest different resolutions of enums.
Edit: more reference
I'm hitting the same issue, and I'm also on python 3.11. I think it's related to the fact that Python 3.11 changed things so that string enums are no longer literal strings
@EricLiclair Thank you for digging into this! Here's a PR with a fix https://github.com/arcee-ai/arcee-python/pull/20 - it uses the same approach as your suggested workaround.
@tleyden thanks for the pr. while the explicit usage is absolutely correct, I was wondering if we could somehow maintain the implicit resolution of the enums to values. it seems StrEnum
(along with other enums) were introduced in 3.11 with these limitations for otherwise the normal mixed enums;
To make it work across versions, most probably, we'll have to override the __format__
method;
Would like to know @Ben-Epstein's opinion on this.
Also, @tleyden if you have any opinions on this 🤔
Hey folks! It looks like this was a temporary python bug in 3.11.2 which had been reverted. https://github.com/python/cpython/issues/103479 (comment)
@EricLiclair would you be willing to do a quick test on python (>=3.11.3, >3.12)?
If that works (as I think it should, based on that issue) I'd actually recommend keeping the behavior and just pinning against 3.11.2 in pyproject.
I'm seeing the error on Python 3.11.6
@Ben-Epstein I'm not a big fan of banning recent versions of python. I think that should only be done as a last resort. This seems pretty easy to workaround in a way that will work on all versions of python.
According to Enum with str
or int
Mixin Breaking Change in Python 3.11 this is a known breaking change rather than a bug in a particular patch version of python 3.11. The recommendation is to use the built-in StrEnum
on Python 3.11, and the StrEnum
package for older versions of python.
Using .value
is a also a valid workaround, but as the blog post author points out: "But knowing when to use .value is inconvenient."
Sounds good, I don't like the use of .value, because like you say, it's confusing.
StrEnum is a good workaround
Hey everyone,
I'm following the arcee-python instructions, but keep getting the error: Exception: Failed to make request. Response: {"detail":"Method Not Allowed"}
I'm getting this message both in Python and via CLI. Any ideas what could be happening?
Thanks, Michael