Skip to content
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

Jupyter async error #32

Closed
austinmw opened this issue May 30, 2023 · 1 comment
Closed

Jupyter async error #32

austinmw opened this issue May 30, 2023 · 1 comment
Assignees

Comments

@austinmw
Copy link
Contributor

Hi, I tried running the following in a Jupyter notebook (in VS Code):

elif mode == "chain_with_guardrails":
  history = [
    {"role": "user", "content": query}
  ]
  result = app.generate(messages=history)

However I got the following error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[79], line 15
     11 elif mode == "chain_with_guardrails":
     12   history = [
     13     {"role": "user", "content": query}
     14   ]
---> 15   result = app.generate(messages=history)
     19 print(result)

File [~/anaconda3/envs/nemo/lib/python3.10/site-packages/nemoguardrails/rails/llm/llmrails.py:157](https://vscode-remote+ssh-002dremote-002bsagemaker-002dnotebook.vscode-resource.vscode-cdn.net/home/ec2-user/SageMaker/NeMo-Guardrails/rag-demo/~/anaconda3/envs/nemo/lib/python3.10/site-packages/nemoguardrails/rails/llm/llmrails.py:157), in LLMRails.generate(self, prompt, messages)
    154     loop = None
    156 if loop and loop.is_running():
--> 157     raise RuntimeError(
    158         "You are using the sync `generate` inside async code. "
    159         "You should replace with `await generate_async(...)."
    160     )
    162 return asyncio.run(self.generate_async(prompt=prompt, messages=messages))

RuntimeError: You are using the sync `generate` inside async code. You should replace with `await generate_async(...).
@drazvan drazvan self-assigned this May 30, 2023
@drazvan
Copy link
Collaborator

drazvan commented May 30, 2023

Hi @austinmw! The sample code that you're referring to is not meant to be run in an async environment (which Jupyter creates), but rather as a standalone script. To make it work, replace the generate call with await generate_async as suggested by the error message.

@drazvan drazvan closed this as completed in 8f789c4 Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants