-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now get emitter through context var (#100)
* now get emitter through context var * remove unused parameter * force langchain version * make run_sync use main event loop * typing and error * param spec mport * use uvicorn event loop
- Loading branch information
1 parent
fd224e7
commit 07df51e
Showing
16 changed files
with
89 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import contextvars | ||
from typing import TYPE_CHECKING | ||
from asyncio import AbstractEventLoop | ||
|
||
if TYPE_CHECKING: | ||
from chainlit.emitter import ChainlitEmitter | ||
|
||
|
||
class ChainlitContextException(Exception): | ||
def __init__(self, msg="Chainlit context not found", *args, **kwargs): | ||
super().__init__(msg, *args, **kwargs) | ||
|
||
|
||
emitter_var = contextvars.ContextVar("emitter") | ||
loop_var = contextvars.ContextVar("loop") | ||
|
||
|
||
def get_emitter() -> "ChainlitEmitter": | ||
try: | ||
return emitter_var.get() | ||
except LookupError: | ||
raise ChainlitContextException() | ||
|
||
|
||
def get_loop() -> AbstractEventLoop: | ||
try: | ||
return loop_var.get() | ||
except LookupError: | ||
raise ChainlitContextException() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.