edsl 0.1.39__py3-none-any.whl → 0.1.39.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- edsl/Base.py +0 -28
- edsl/__init__.py +1 -1
- edsl/__version__.py +1 -1
- edsl/agents/Agent.py +17 -9
- edsl/agents/Invigilator.py +14 -13
- edsl/agents/InvigilatorBase.py +1 -4
- edsl/agents/PromptConstructor.py +22 -42
- edsl/agents/QuestionInstructionPromptBuilder.py +1 -1
- edsl/auto/AutoStudy.py +5 -18
- edsl/auto/StageBase.py +40 -53
- edsl/auto/StageQuestions.py +1 -2
- edsl/auto/utilities.py +6 -0
- edsl/coop/coop.py +5 -21
- edsl/data/Cache.py +18 -29
- edsl/data/CacheHandler.py +2 -0
- edsl/data/RemoteCacheSync.py +46 -154
- edsl/enums.py +0 -7
- edsl/inference_services/AnthropicService.py +16 -38
- edsl/inference_services/AvailableModelFetcher.py +1 -7
- edsl/inference_services/GoogleService.py +1 -5
- edsl/inference_services/InferenceServicesCollection.py +2 -18
- edsl/inference_services/OpenAIService.py +31 -46
- edsl/inference_services/TestService.py +3 -1
- edsl/inference_services/TogetherAIService.py +3 -5
- edsl/inference_services/data_structures.py +2 -74
- edsl/jobs/AnswerQuestionFunctionConstructor.py +113 -148
- edsl/jobs/FetchInvigilator.py +3 -10
- edsl/jobs/InterviewsConstructor.py +4 -6
- edsl/jobs/Jobs.py +233 -299
- edsl/jobs/JobsChecks.py +2 -2
- edsl/jobs/JobsPrompts.py +1 -1
- edsl/jobs/JobsRemoteInferenceHandler.py +136 -160
- edsl/jobs/interviews/Interview.py +42 -80
- edsl/jobs/runners/JobsRunnerAsyncio.py +358 -88
- edsl/jobs/runners/JobsRunnerStatus.py +165 -133
- edsl/jobs/tasks/TaskHistory.py +3 -24
- edsl/language_models/LanguageModel.py +4 -59
- edsl/language_models/ModelList.py +8 -19
- edsl/language_models/__init__.py +1 -1
- edsl/language_models/registry.py +180 -0
- edsl/language_models/repair.py +1 -1
- edsl/questions/QuestionBase.py +26 -35
- edsl/questions/{question_base_gen_mixin.py → QuestionBaseGenMixin.py} +49 -52
- edsl/questions/QuestionBasePromptsMixin.py +1 -1
- edsl/questions/QuestionBudget.py +1 -1
- edsl/questions/QuestionCheckBox.py +2 -2
- edsl/questions/QuestionExtract.py +7 -5
- edsl/questions/QuestionFreeText.py +1 -1
- edsl/questions/QuestionList.py +15 -9
- edsl/questions/QuestionMatrix.py +1 -1
- edsl/questions/QuestionMultipleChoice.py +1 -1
- edsl/questions/QuestionNumerical.py +1 -1
- edsl/questions/QuestionRank.py +1 -1
- edsl/questions/{response_validator_abc.py → ResponseValidatorABC.py} +18 -6
- edsl/questions/{response_validator_factory.py → ResponseValidatorFactory.py} +1 -7
- edsl/questions/SimpleAskMixin.py +1 -1
- edsl/questions/__init__.py +1 -1
- edsl/results/DatasetExportMixin.py +119 -60
- edsl/results/Result.py +3 -109
- edsl/results/Results.py +39 -50
- edsl/scenarios/FileStore.py +0 -32
- edsl/scenarios/ScenarioList.py +7 -35
- edsl/scenarios/handlers/csv.py +0 -11
- edsl/surveys/Survey.py +20 -71
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev2.dist-info}/METADATA +1 -1
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev2.dist-info}/RECORD +78 -84
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev2.dist-info}/WHEEL +1 -1
- edsl/jobs/async_interview_runner.py +0 -138
- edsl/jobs/check_survey_scenario_compatibility.py +0 -85
- edsl/jobs/data_structures.py +0 -120
- edsl/jobs/results_exceptions_handler.py +0 -98
- edsl/language_models/model.py +0 -256
- edsl/questions/data_structures.py +0 -20
- edsl/results/file_exports.py +0 -252
- /edsl/agents/{question_option_processor.py → QuestionOptionProcessor.py} +0 -0
- /edsl/questions/{answer_validator_mixin.py → AnswerValidatorMixin.py} +0 -0
- /edsl/questions/{loop_processor.py → LoopProcessor.py} +0 -0
- /edsl/questions/{register_questions_meta.py → RegisterQuestionsMeta.py} +0 -0
- /edsl/results/{results_fetch_mixin.py → ResultsFetchMixin.py} +0 -0
- /edsl/results/{results_tools_mixin.py → ResultsToolsMixin.py} +0 -0
- /edsl/results/{results_selector.py → Selector.py} +0 -0
- /edsl/scenarios/{directory_scanner.py → DirectoryScanner.py} +0 -0
- /edsl/scenarios/{scenario_join.py → ScenarioJoin.py} +0 -0
- /edsl/scenarios/{scenario_selector.py → ScenarioSelector.py} +0 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev2.dist-info}/LICENSE +0 -0
edsl/jobs/data_structures.py
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
from typing import Optional, Literal
|
2
|
-
from dataclasses import dataclass, asdict
|
3
|
-
|
4
|
-
# from edsl.data_transfer_models import VisibilityType
|
5
|
-
from edsl.data.Cache import Cache
|
6
|
-
from edsl.jobs.buckets.BucketCollection import BucketCollection
|
7
|
-
from edsl.language_models.key_management.KeyLookup import KeyLookup
|
8
|
-
from edsl.jobs.runners.JobsRunnerStatus import JobsRunnerStatus
|
9
|
-
|
10
|
-
VisibilityType = Literal["private", "public", "unlisted"]
|
11
|
-
from edsl.Base import Base
|
12
|
-
|
13
|
-
|
14
|
-
@dataclass
|
15
|
-
class RunEnvironment:
|
16
|
-
cache: Optional[Cache] = None
|
17
|
-
bucket_collection: Optional[BucketCollection] = None
|
18
|
-
key_lookup: Optional[KeyLookup] = None
|
19
|
-
jobs_runner_status: Optional["JobsRunnerStatus"] = None
|
20
|
-
|
21
|
-
|
22
|
-
@dataclass
|
23
|
-
class RunParameters(Base):
|
24
|
-
n: int = 1
|
25
|
-
progress_bar: bool = False
|
26
|
-
stop_on_exception: bool = False
|
27
|
-
check_api_keys: bool = False
|
28
|
-
verbose: bool = True
|
29
|
-
print_exceptions: bool = True
|
30
|
-
remote_cache_description: Optional[str] = None
|
31
|
-
remote_inference_description: Optional[str] = None
|
32
|
-
remote_inference_results_visibility: Optional[VisibilityType] = "unlisted"
|
33
|
-
skip_retry: bool = False
|
34
|
-
raise_validation_errors: bool = False
|
35
|
-
disable_remote_cache: bool = False
|
36
|
-
disable_remote_inference: bool = False
|
37
|
-
job_uuid: Optional[str] = None
|
38
|
-
|
39
|
-
def to_dict(self, add_edsl_version=False) -> dict:
|
40
|
-
d = asdict(self)
|
41
|
-
if add_edsl_version:
|
42
|
-
from edsl import __version__
|
43
|
-
|
44
|
-
d["edsl_version"] = __version__
|
45
|
-
d["edsl_class_name"] = "RunConfig"
|
46
|
-
return d
|
47
|
-
|
48
|
-
@classmethod
|
49
|
-
def from_dict(cls, data: dict) -> "RunConfig":
|
50
|
-
return cls(**data)
|
51
|
-
|
52
|
-
def code(self):
|
53
|
-
return f"RunConfig(**{self.to_dict()})"
|
54
|
-
|
55
|
-
@classmethod
|
56
|
-
def example(cls) -> "RunConfig":
|
57
|
-
return cls()
|
58
|
-
|
59
|
-
|
60
|
-
@dataclass
|
61
|
-
class RunConfig:
|
62
|
-
environment: RunEnvironment
|
63
|
-
parameters: RunParameters
|
64
|
-
|
65
|
-
def add_environment(self, environment: RunEnvironment):
|
66
|
-
self.environment = environment
|
67
|
-
|
68
|
-
def add_bucket_collection(self, bucket_collection: BucketCollection):
|
69
|
-
self.environment.bucket_collection = bucket_collection
|
70
|
-
|
71
|
-
def add_cache(self, cache: Cache):
|
72
|
-
self.environment.cache = cache
|
73
|
-
|
74
|
-
def add_key_lookup(self, key_lookup: KeyLookup):
|
75
|
-
self.environment.key_lookup = key_lookup
|
76
|
-
|
77
|
-
|
78
|
-
"""This module contains the Answers class, which is a helper class to hold the answers to a survey."""
|
79
|
-
|
80
|
-
from collections import UserDict
|
81
|
-
from edsl.data_transfer_models import EDSLResultObjectInput
|
82
|
-
|
83
|
-
|
84
|
-
class Answers(UserDict):
|
85
|
-
"""Helper class to hold the answers to a survey."""
|
86
|
-
|
87
|
-
def add_answer(
|
88
|
-
self, response: EDSLResultObjectInput, question: "QuestionBase"
|
89
|
-
) -> None:
|
90
|
-
"""Add a response to the answers dictionary."""
|
91
|
-
answer = response.answer
|
92
|
-
comment = response.comment
|
93
|
-
generated_tokens = response.generated_tokens
|
94
|
-
# record the answer
|
95
|
-
if generated_tokens:
|
96
|
-
self[question.question_name + "_generated_tokens"] = generated_tokens
|
97
|
-
self[question.question_name] = answer
|
98
|
-
if comment:
|
99
|
-
self[question.question_name + "_comment"] = comment
|
100
|
-
|
101
|
-
def replace_missing_answers_with_none(self, survey: "Survey") -> None:
|
102
|
-
"""Replace missing answers with None. Answers can be missing if the agent skips a question."""
|
103
|
-
for question_name in survey.question_names:
|
104
|
-
if question_name not in self:
|
105
|
-
self[question_name] = None
|
106
|
-
|
107
|
-
def to_dict(self):
|
108
|
-
"""Return a dictionary of the answers."""
|
109
|
-
return self.data
|
110
|
-
|
111
|
-
@classmethod
|
112
|
-
def from_dict(cls, d):
|
113
|
-
"""Return an Answers object from a dictionary."""
|
114
|
-
return cls(d)
|
115
|
-
|
116
|
-
|
117
|
-
if __name__ == "__main__":
|
118
|
-
import doctest
|
119
|
-
|
120
|
-
doctest.testmod()
|
@@ -1,98 +0,0 @@
|
|
1
|
-
from typing import Optional, TYPE_CHECKING, Protocol
|
2
|
-
import sys
|
3
|
-
from edsl.scenarios.FileStore import HTMLFileStore
|
4
|
-
from edsl.config import CONFIG
|
5
|
-
from edsl.coop.coop import Coop
|
6
|
-
|
7
|
-
|
8
|
-
class ResultsProtocol(Protocol):
|
9
|
-
"""Protocol defining the required interface for Results objects."""
|
10
|
-
|
11
|
-
@property
|
12
|
-
def has_unfixed_exceptions(self) -> bool: ...
|
13
|
-
|
14
|
-
@property
|
15
|
-
def task_history(self) -> "TaskHistoryProtocol": ...
|
16
|
-
|
17
|
-
|
18
|
-
class TaskHistoryProtocol(Protocol):
|
19
|
-
"""Protocol defining the required interface for TaskHistory objects."""
|
20
|
-
|
21
|
-
@property
|
22
|
-
def indices(self) -> list: ...
|
23
|
-
|
24
|
-
def html(self, cta: str, open_in_browser: bool, return_link: bool) -> str: ...
|
25
|
-
|
26
|
-
|
27
|
-
class RunParametersProtocol(Protocol):
|
28
|
-
"""Protocol defining the required interface for RunParameters objects."""
|
29
|
-
|
30
|
-
@property
|
31
|
-
def print_exceptions(self) -> bool: ...
|
32
|
-
|
33
|
-
|
34
|
-
class ResultsExceptionsHandler:
|
35
|
-
"""Handles exception reporting and display functionality."""
|
36
|
-
|
37
|
-
def __init__(
|
38
|
-
self, results: ResultsProtocol, parameters: RunParametersProtocol
|
39
|
-
) -> None:
|
40
|
-
self.results = results
|
41
|
-
self.parameters = parameters
|
42
|
-
|
43
|
-
self.open_in_browser = self._get_browser_setting()
|
44
|
-
self.remote_logging = self._get_remote_logging_setting()
|
45
|
-
|
46
|
-
def _get_browser_setting(self) -> bool:
|
47
|
-
"""Determine if exceptions should be opened in browser based on config."""
|
48
|
-
setting = CONFIG.get("EDSL_OPEN_EXCEPTION_REPORT_URL")
|
49
|
-
if setting == "True":
|
50
|
-
return True
|
51
|
-
elif setting == "False":
|
52
|
-
return False
|
53
|
-
else:
|
54
|
-
raise Exception(
|
55
|
-
"EDSL_OPEN_EXCEPTION_REPORT_URL must be either True or False"
|
56
|
-
)
|
57
|
-
|
58
|
-
def _get_remote_logging_setting(self) -> bool:
|
59
|
-
"""Get remote logging setting from coop."""
|
60
|
-
try:
|
61
|
-
coop = Coop()
|
62
|
-
return coop.edsl_settings["remote_logging"]
|
63
|
-
except Exception as e:
|
64
|
-
# print(e)
|
65
|
-
return False
|
66
|
-
|
67
|
-
def _generate_error_message(self, indices) -> str:
|
68
|
-
"""Generate appropriate error message based on number of exceptions."""
|
69
|
-
msg = f"Exceptions were raised in {len(indices)} interviews.\n"
|
70
|
-
if len(indices) > 5:
|
71
|
-
msg += f"Exceptions were raised in the following interviews: {indices}.\n"
|
72
|
-
return msg
|
73
|
-
|
74
|
-
def handle_exceptions(self) -> None:
|
75
|
-
"""Handle exceptions by printing messages and generating reports as needed."""
|
76
|
-
if not (
|
77
|
-
self.results.has_unfixed_exceptions and self.parameters.print_exceptions
|
78
|
-
):
|
79
|
-
return
|
80
|
-
|
81
|
-
# Print error message
|
82
|
-
error_msg = self._generate_error_message(self.results.task_history.indices)
|
83
|
-
print(error_msg, file=sys.stderr)
|
84
|
-
|
85
|
-
# Generate HTML report
|
86
|
-
filepath = self.results.task_history.html(
|
87
|
-
cta="Open report to see details.",
|
88
|
-
open_in_browser=self.open_in_browser,
|
89
|
-
return_link=True,
|
90
|
-
)
|
91
|
-
|
92
|
-
# Handle remote logging if enabled
|
93
|
-
if self.remote_logging:
|
94
|
-
filestore = HTMLFileStore(filepath)
|
95
|
-
coop_details = filestore.push(description="Error report")
|
96
|
-
print(coop_details)
|
97
|
-
|
98
|
-
print("Also see: https://docs.expectedparrot.com/en/latest/exceptions.html")
|
edsl/language_models/model.py
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
import textwrap
|
2
|
-
from random import random
|
3
|
-
from typing import Optional, TYPE_CHECKING, List
|
4
|
-
|
5
|
-
from edsl.utilities.PrettyList import PrettyList
|
6
|
-
from edsl.config import CONFIG
|
7
|
-
|
8
|
-
from edsl.inference_services.InferenceServicesCollection import (
|
9
|
-
InferenceServicesCollection,
|
10
|
-
)
|
11
|
-
from edsl.inference_services.data_structures import AvailableModels
|
12
|
-
from edsl.inference_services.InferenceServiceABC import InferenceServiceABC
|
13
|
-
from edsl.enums import InferenceServiceLiteral
|
14
|
-
|
15
|
-
if TYPE_CHECKING:
|
16
|
-
from edsl.results.Dataset import Dataset
|
17
|
-
|
18
|
-
|
19
|
-
def get_model_class(model_name, registry: Optional[InferenceServicesCollection] = None):
|
20
|
-
from edsl.inference_services.registry import default
|
21
|
-
|
22
|
-
registry = registry or default
|
23
|
-
factory = registry.create_model_factory(model_name)
|
24
|
-
return factory
|
25
|
-
|
26
|
-
|
27
|
-
class Meta(type):
|
28
|
-
def __repr__(cls):
|
29
|
-
return textwrap.dedent(
|
30
|
-
f"""\
|
31
|
-
Available models: {cls.available()}
|
32
|
-
|
33
|
-
To create an instance, you can do:
|
34
|
-
>>> m = Model('gpt-4-1106-preview', temperature=0.5, ...)
|
35
|
-
|
36
|
-
To get the default model, you can leave out the model name.
|
37
|
-
To see the available models, you can do:
|
38
|
-
>>> Model.available()
|
39
|
-
"""
|
40
|
-
)
|
41
|
-
|
42
|
-
|
43
|
-
class Model(metaclass=Meta):
|
44
|
-
default_model = CONFIG.get("EDSL_DEFAULT_MODEL")
|
45
|
-
_registry: InferenceServicesCollection = None # Class-level registry storage
|
46
|
-
|
47
|
-
@classmethod
|
48
|
-
def get_registry(cls) -> InferenceServicesCollection:
|
49
|
-
"""Get the current registry or initialize with default if None"""
|
50
|
-
if cls._registry is None:
|
51
|
-
from edsl.inference_services.registry import default
|
52
|
-
|
53
|
-
cls._registry = default
|
54
|
-
return cls._registry
|
55
|
-
|
56
|
-
@classmethod
|
57
|
-
def set_registry(cls, registry: InferenceServicesCollection) -> None:
|
58
|
-
"""Set a new registry"""
|
59
|
-
cls._registry = registry
|
60
|
-
|
61
|
-
def __new__(
|
62
|
-
cls,
|
63
|
-
model_name: Optional[str] = None,
|
64
|
-
service_name: Optional[InferenceServiceLiteral] = None,
|
65
|
-
registry: Optional[InferenceServicesCollection] = None,
|
66
|
-
*args,
|
67
|
-
**kwargs,
|
68
|
-
):
|
69
|
-
"Instantiate a new language model."
|
70
|
-
# Map index to the respective subclass
|
71
|
-
if model_name is None:
|
72
|
-
model_name = (
|
73
|
-
cls.default_model
|
74
|
-
) # when model_name is None, use the default model, set in the config file
|
75
|
-
|
76
|
-
if registry is not None:
|
77
|
-
cls.set_registry(registry)
|
78
|
-
|
79
|
-
if isinstance(model_name, int): # can refer to a model by index
|
80
|
-
model_name = cls.available(name_only=True)[model_name]
|
81
|
-
|
82
|
-
factory = cls.get_registry().create_model_factory(
|
83
|
-
model_name, service_name=service_name
|
84
|
-
)
|
85
|
-
return factory(*args, **kwargs)
|
86
|
-
|
87
|
-
@classmethod
|
88
|
-
def add_model(cls, service_name, model_name) -> None:
|
89
|
-
cls.get_registry().add_model(service_name, model_name)
|
90
|
-
|
91
|
-
@classmethod
|
92
|
-
def service_classes(cls) -> List["InferenceServiceABC"]:
|
93
|
-
"""Returns a list of service classes.
|
94
|
-
|
95
|
-
>>> Model.service_classes()
|
96
|
-
[...]
|
97
|
-
"""
|
98
|
-
return [r for r in cls.services(name_only=True)]
|
99
|
-
|
100
|
-
@classmethod
|
101
|
-
def services(cls, name_only: bool = False) -> List[str]:
|
102
|
-
"""Returns a list of services, annotated with whether the user has local keys for them."""
|
103
|
-
services_with_local_keys = set(cls.key_info().select("service").to_list())
|
104
|
-
f = lambda service_name: (
|
105
|
-
"yes" if service_name in services_with_local_keys else " "
|
106
|
-
)
|
107
|
-
if name_only:
|
108
|
-
return PrettyList(
|
109
|
-
[r._inference_service_ for r in cls.get_registry().services],
|
110
|
-
columns=["Service Name"],
|
111
|
-
)
|
112
|
-
else:
|
113
|
-
return PrettyList(
|
114
|
-
[
|
115
|
-
(r._inference_service_, f(r._inference_service_))
|
116
|
-
for r in cls.get_registry().services
|
117
|
-
],
|
118
|
-
columns=["Service Name", "Local key?"],
|
119
|
-
)
|
120
|
-
|
121
|
-
@classmethod
|
122
|
-
def services_with_local_keys(cls) -> set:
|
123
|
-
"""Returns a list of services for which the user has local keys."""
|
124
|
-
return set(cls.key_info().select("service").to_list())
|
125
|
-
|
126
|
-
@classmethod
|
127
|
-
def key_info(cls, obscure_api_key: bool = True) -> "Dataset":
|
128
|
-
"""Returns a dataset of local key information."""
|
129
|
-
from edsl.language_models.key_management.KeyLookupCollection import (
|
130
|
-
KeyLookupCollection,
|
131
|
-
)
|
132
|
-
from edsl.scenarios import Scenario, ScenarioList
|
133
|
-
|
134
|
-
klc = KeyLookupCollection()
|
135
|
-
klc.add_key_lookup(fetch_order=None)
|
136
|
-
sl = ScenarioList()
|
137
|
-
for service, entry in list(klc.data.values())[0].items():
|
138
|
-
sl.append(Scenario({"service": service} | entry.to_dict()))
|
139
|
-
if obscure_api_key:
|
140
|
-
for service in sl:
|
141
|
-
service["api_token"] = (
|
142
|
-
service["api_token"][:4] + "..." + service["api_token"][-4:]
|
143
|
-
)
|
144
|
-
return sl.to_dataset()
|
145
|
-
|
146
|
-
@classmethod
|
147
|
-
def search_models(cls, search_term: str):
|
148
|
-
return cls.available(search_term=search_term)
|
149
|
-
|
150
|
-
@classmethod
|
151
|
-
def all_known_models(cls) -> "AvailableModels":
|
152
|
-
return cls.get_registry().available()
|
153
|
-
|
154
|
-
@classmethod
|
155
|
-
def available_with_local_keys(cls):
|
156
|
-
services_with_local_keys = set(cls.key_info().select("service").to_list())
|
157
|
-
return [
|
158
|
-
m
|
159
|
-
for m in cls.get_registry().available()
|
160
|
-
if m.service_name in services_with_local_keys
|
161
|
-
]
|
162
|
-
|
163
|
-
@classmethod
|
164
|
-
def available(
|
165
|
-
cls,
|
166
|
-
search_term: str = None,
|
167
|
-
name_only: bool = False,
|
168
|
-
service: Optional[str] = None,
|
169
|
-
):
|
170
|
-
# if search_term is None and service is None:
|
171
|
-
# print("Getting available models...")
|
172
|
-
# print("You have local keys for the following services:")
|
173
|
-
# print(cls.services_with_local_keys())
|
174
|
-
# print("\n")
|
175
|
-
# print("To see models by service, use the 'service' parameter.")
|
176
|
-
# print("E.g., Model.available(service='openai')")
|
177
|
-
# return None
|
178
|
-
|
179
|
-
if service is not None:
|
180
|
-
if service not in cls.services(name_only=True):
|
181
|
-
raise ValueError(
|
182
|
-
f"Service {service} not found in available services.",
|
183
|
-
f"Available services are: {cls.services()}",
|
184
|
-
)
|
185
|
-
|
186
|
-
full_list = cls.get_registry().available(service=service)
|
187
|
-
|
188
|
-
if search_term is None:
|
189
|
-
if name_only:
|
190
|
-
return PrettyList(
|
191
|
-
[m.model_name for m in full_list],
|
192
|
-
columns=["Model Name"],
|
193
|
-
)
|
194
|
-
else:
|
195
|
-
return PrettyList(
|
196
|
-
[[m.model_name, m.service_name] for m in full_list],
|
197
|
-
columns=["Model Name", "Service Name"],
|
198
|
-
)
|
199
|
-
else:
|
200
|
-
filtered_results = [
|
201
|
-
m
|
202
|
-
for m in full_list
|
203
|
-
if search_term in m.model_name or search_term in m.service_name
|
204
|
-
]
|
205
|
-
if name_only:
|
206
|
-
return PrettyList(
|
207
|
-
[m.model_name for m in filtered_results],
|
208
|
-
columns=["Model Name"],
|
209
|
-
)
|
210
|
-
else:
|
211
|
-
return PrettyList(
|
212
|
-
[[m.model_name, m.service_name] for m in full_list],
|
213
|
-
columns=["Model Name", "Service Name"],
|
214
|
-
)
|
215
|
-
|
216
|
-
@classmethod
|
217
|
-
def check_models(cls, verbose=False):
|
218
|
-
print("Checking all available models...\n")
|
219
|
-
for model in cls.available(name_only=True):
|
220
|
-
print(f"Now checking: {model}")
|
221
|
-
try:
|
222
|
-
m = cls(model)
|
223
|
-
except Exception as e:
|
224
|
-
print(f"Error creating instance of {model}: {e}")
|
225
|
-
continue
|
226
|
-
try:
|
227
|
-
results = m.hello(verbose)
|
228
|
-
if verbose:
|
229
|
-
print(f"Results from model call: {results}")
|
230
|
-
except Exception as e:
|
231
|
-
print(f"Error calling 'hello' on {model}: {e}")
|
232
|
-
continue
|
233
|
-
print("OK!")
|
234
|
-
print("\n")
|
235
|
-
|
236
|
-
@classmethod
|
237
|
-
def example(cls, randomize: bool = False) -> "Model":
|
238
|
-
"""
|
239
|
-
Returns an example Model instance.
|
240
|
-
|
241
|
-
:param randomize: If True, the temperature is set to a random decimal between 0 and 1.
|
242
|
-
"""
|
243
|
-
temperature = 0.5 if not randomize else round(random(), 2)
|
244
|
-
model_name = cls.default_model
|
245
|
-
return cls(model_name, temperature=temperature)
|
246
|
-
|
247
|
-
|
248
|
-
if __name__ == "__main__":
|
249
|
-
import doctest
|
250
|
-
|
251
|
-
doctest.testmod(optionflags=doctest.ELLIPSIS)
|
252
|
-
|
253
|
-
available = Model.available()
|
254
|
-
m = Model("gpt-4-1106-preview")
|
255
|
-
results = m.execute_model_call("Hello world")
|
256
|
-
print(results)
|
@@ -1,20 +0,0 @@
|
|
1
|
-
from typing import Any, Optional, TypedDict
|
2
|
-
from pydantic import BaseModel
|
3
|
-
|
4
|
-
|
5
|
-
class RawEdslAnswerDict(TypedDict):
|
6
|
-
answer: Any
|
7
|
-
comment: Optional[str]
|
8
|
-
generated_tokens: Optional[str]
|
9
|
-
|
10
|
-
|
11
|
-
class BaseResponse(BaseModel):
|
12
|
-
answer: Any
|
13
|
-
comment: Optional[str] = None
|
14
|
-
generated_tokens: Optional[str] = None
|
15
|
-
|
16
|
-
|
17
|
-
class EdslAnswerDict(TypedDict):
|
18
|
-
answer: Any
|
19
|
-
comment: Optional[str]
|
20
|
-
generated_tokens: Optional[str]
|