-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: Failed to retrieve the AppProcess: running in wrong context #725
Comments
Here too. from dotenv import load_dotenv
import os
from writerai import Writer
import writer.ai
load_dotenv()
WRITER_API_KEY = os.getenv("WRITER_API_KEY")
WRITER_APP_ID = os.getenv("WRITER_APP_ID")
if not WRITER_API_KEY or not WRITER_APP_ID:
raise ValueError("failed to load env vars")
client = Writer(api_key=WRITER_API_KEY)
graph = writer.ai.create_graph(name="financial data", description="quarterly") Error message: ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[1], [line 15](vscode-notebook-cell:?execution_count=1&line=15)
[11](vscode-notebook-cell:?execution_count=1&line=11) raise ValueError("failed to load env vars")
[13](vscode-notebook-cell:?execution_count=1&line=13) client = Writer(api_key=WRITER_API_KEY)
---> [15](vscode-notebook-cell:?execution_count=1&line=15) graph = writer.ai.create_graph(name="financial data", description="quarterly")
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:622, in create_graph(name, description, config)
[599](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:599) """
[600](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:600) Creates a new graph with the given parameters.
[601](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:601)
(...)
[619](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:619) Timeout for the request.
[620](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:620) """
[621](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:621) config = config or {}
--> [622](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:622) graphs = Graph._retrieve_graphs_accessor()
[623](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:623) graph_object = graphs.create(
[624](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:624) name=name,
[625](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:625) description=description or NotGiven(),
[626](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:626) **config
[627](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:627) )
[628](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:628) converted_object = cast(SDKGraph, graph_object)
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:291, in Graph._retrieve_graphs_accessor()
[282](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:282) @staticmethod
[283](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:283) def _retrieve_graphs_accessor() -> GraphsResource:
[284](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:284) """
[285](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:285) Acquires the graphs accessor from the WriterAIManager
[286](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:286) singleton instance.
(...)
[289](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:289) :rtype: GraphsResource
[290](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:290) """
--> [291](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:291) return WriterAIManager.acquire_client().graphs
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:228, in WriterAIManager.acquire_client(cls)
[226](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:226) @classmethod
[227](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:227) def acquire_client(cls) -> Writer:
--> [228](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:228) instance = cls.acquire_instance()
[229](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:229) return instance.client
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:187, in WriterAIManager.acquire_instance(cls)
[178](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:178) """
[179](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:179) Retrieve the existing instance of WriterAIManager from
[180](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:180) the current app process.
(...)
[184](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:184) :returns: The current instance of the manager.
[185](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:185) """
[186](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:186) instance: WriterAIManager
--> [187](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:187) current_process = get_app_process()
[189](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:189) # If instance was not created explicitly, we initialize a new one
[190](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:190) try:
File c:\Notes\writer\.venv\lib\site-packages\writer\core.py:100, in get_app_process()
[97](file:///C:/Notes/writer/.venv/lib/site-packages/writer/core.py:97) if isinstance(raw_process, AppProcess):
[98](file:///C:/Notes/writer/.venv/lib/site-packages/writer/core.py:98) return raw_process
--> [100](file:///C:/Notes/writer/.venv/lib/site-packages/writer/core.py:100) raise RuntimeError( "Failed to retrieve the AppProcess: running in wrong context")
RuntimeError: Failed to retrieve the AppProcess: running in wrong context |
And here. from writer.ai import upload_file
file = upload_file(data=b"hellow world", type="application/pdf", name="TEST.pdf")
graph.add_file(file) Error message: ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[1], [line 2](vscode-notebook-cell:?execution_count=1&line=2)
[1](vscode-notebook-cell:?execution_count=1&line=1) from writer.ai import upload_file
----> [2](vscode-notebook-cell:?execution_count=1&line=2) file = upload_file(data=b"hellow world", type="application/pdf", name="TEST.pdf")
[4](vscode-notebook-cell:?execution_count=1&line=4) graph.add_file(file)
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:869, in upload_file(data, type, name, config)
[844](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:844) """
[845](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:845) Uploads a new file with the given parameters.
[846](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:846)
(...)
[866](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:866) Timeout for the request.
[867](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:867) """
[868](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:868) config = config or {}
--> [869](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:869) files = File._retrieve_files_accessor()
[871](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:871) file_name = name or f"WF-{type}-{uuid4()}"
[872](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:872) content_disposition = f'attachment; filename="{file_name}"'
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:748, in File._retrieve_files_accessor()
[740](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:740) @staticmethod
[741](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:741) def _retrieve_files_accessor() -> FilesResource:
[742](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:742) """
[743](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:743) Acquires the files client from the WriterAIManager singleton instance.
[744](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:744)
[745](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:745) :returns: The files client instance.
[746](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:746) :rtype: FilesResource
[747](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:747) """
--> [748](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:748) return WriterAIManager.acquire_client().files
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:228, in WriterAIManager.acquire_client(cls)
[226](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:226) @classmethod
[227](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:227) def acquire_client(cls) -> Writer:
--> [228](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:228) instance = cls.acquire_instance()
[229](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:229) return instance.client
File c:\Notes\writer\.venv\lib\site-packages\writer\ai.py:187, in WriterAIManager.acquire_instance(cls)
[178](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:178) """
[179](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:179) Retrieve the existing instance of WriterAIManager from
[180](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:180) the current app process.
(...)
[184](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:184) :returns: The current instance of the manager.
[185](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:185) """
[186](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:186) instance: WriterAIManager
--> [187](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:187) current_process = get_app_process()
[189](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:189) # If instance was not created explicitly, we initialize a new one
[190](file:///C:/Notes/writer/.venv/lib/site-packages/writer/ai.py:190) try:
File c:\Notes\writer\.venv\lib\site-packages\writer\core.py:100, in get_app_process()
[97](file:///C:/Notes/writer/.venv/lib/site-packages/writer/core.py:97) if isinstance(raw_process, AppProcess):
[98](file:///C:/Notes/writer/.venv/lib/site-packages/writer/core.py:98) return raw_process
--> [100](file:///C:/Notes/writer/.venv/lib/site-packages/writer/core.py:100) raise RuntimeError( "Failed to retrieve the AppProcess: running in wrong context")
RuntimeError: Failed to retrieve the AppProcess: running in wrong context |
Hello @CakeCrusher, thank you for reporting this! This error is related to the fact that currently it is, by design, not possible to use the |
Oh, that makes sense, The docs (these at least https://dev.writer.com/framework/ai-module ) did not clearly communicate that dependance |
(if you think this is solvable through the SDK alone, happy to contribute a PR, in that instance any guidance would be awesome)
To reproduce:
Error message:
The text was updated successfully, but these errors were encountered: