-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from monocle2ai/kshitiz/add_traces_updates_1
improvement in traces
- Loading branch information
Showing
7 changed files
with
348 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from langchain_core.language_models.llms import LLM | ||
from typing import Optional | ||
|
||
from typing import Any, List, Mapping | ||
|
||
|
||
class FakeListLLM(LLM): | ||
"""Fake LLM for testing purposes.""" | ||
|
||
responses: List[str] | ||
"""List of responses to return in order.""" | ||
# This parameter should be removed from FakeListLLM since | ||
# it's only used by sub-classes. | ||
sleep: Optional[float] = None | ||
"""Sleep time in seconds between responses. | ||
Ignored by FakeListLLM, but used by sub-classes. | ||
""" | ||
i: int = 0 | ||
"""Internally incremented after every model invocation. | ||
Useful primarily for testing purposes. | ||
""" | ||
api_base = "" | ||
|
||
@property | ||
def _llm_type(self) -> str: | ||
"""Return type of llm.""" | ||
return "fake-list" | ||
|
||
def _call( | ||
self, | ||
prompt: str, | ||
stop: Optional[List[str]] = None, | ||
run_manager = None, | ||
**kwargs: Any, | ||
) -> str: | ||
"""Return next response""" | ||
response = self.responses[self.i] | ||
if self.i < len(self.responses) - 1: | ||
self.i += 1 | ||
else: | ||
self.i = 0 | ||
return response | ||
|
||
async def _acall( | ||
self, | ||
prompt: str, | ||
stop: Optional[List[str]] = None, | ||
run_manager = None, | ||
**kwargs: Any, | ||
) -> str: | ||
"""Return next response""" | ||
response = self.responses[self.i] | ||
if self.i < len(self.responses) - 1: | ||
self.i += 1 | ||
else: | ||
self.i = 0 | ||
return response | ||
|
||
@property | ||
def _identifying_params(self) -> Mapping[str, Any]: | ||
return {"responses": self.responses} |
Oops, something went wrong.