mirror of https://github.com/hwchase17/langchain
A fix for Jupyter environment variable issue (#135)
- fixes the Jupyter environment variable issues mentioned in issue #134 - fixes format/lint issues in some unrelated files (from make format/lint) ![image](https://user-images.githubusercontent.com/347398/201599322-090af858-362d-4d69-bf59-208aea65419a.png)pull/138/head
parent
ced29b816b
commit
76cecf8165
@ -1,8 +1,16 @@
|
||||
"""Common utility functions for working with LLM APIs."""
|
||||
import os
|
||||
import re
|
||||
from typing import List
|
||||
from typing import Any, Dict, List
|
||||
|
||||
|
||||
def enforce_stop_tokens(text: str, stop: List[str]) -> str:
|
||||
"""Cut off the text as soon as any stop words occur."""
|
||||
return re.split("|".join(stop), text)[0]
|
||||
|
||||
|
||||
def get_from_dict_or_env(data: Dict[str, Any], key: str, env_key: str) -> Any:
|
||||
"""Get a value from a dictionary or an environment variable."""
|
||||
if key in data:
|
||||
return data[key]
|
||||
return os.environ.get(env_key, None)
|
||||
|
Loading…
Reference in New Issue