freeplay 0.3.24__tar.gz → 0.3.25__tar.gz

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.
Files changed (22) hide show
  1. {freeplay-0.3.24 → freeplay-0.3.25}/PKG-INFO +1 -1
  2. {freeplay-0.3.24 → freeplay-0.3.25}/pyproject.toml +1 -1
  3. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/freeplay_cli.py +49 -4
  4. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/prompts.py +3 -0
  5. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/support.py +33 -0
  6. {freeplay-0.3.24 → freeplay-0.3.25}/LICENSE +0 -0
  7. {freeplay-0.3.24 → freeplay-0.3.25}/README.md +0 -0
  8. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/__init__.py +0 -0
  9. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/api_support.py +0 -0
  10. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/errors.py +0 -0
  11. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/freeplay.py +0 -0
  12. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/llm_parameters.py +0 -0
  13. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/model.py +0 -0
  14. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/py.typed +0 -0
  15. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/__init__.py +0 -0
  16. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/adapters.py +0 -0
  17. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/customer_feedback.py +0 -0
  18. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/recordings.py +0 -0
  19. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/sessions.py +0 -0
  20. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/test_cases.py +0 -0
  21. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/resources/test_runs.py +0 -0
  22. {freeplay-0.3.24 → freeplay-0.3.25}/src/freeplay/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: freeplay
3
- Version: 0.3.24
3
+ Version: 0.3.25
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: FreePlay Engineering
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "freeplay"
3
- version = "0.3.24"
3
+ version = "0.3.25"
4
4
  description = ""
5
5
  authors = ["FreePlay Engineering <engineering@freeplay.ai>"]
6
6
  license = "MIT"
@@ -50,7 +50,53 @@ def download(project_id: str, environment: str, output_dir: str) -> None:
50
50
  click.echo(f"Found {len(prompts.prompt_templates)} prompt templates")
51
51
 
52
52
  for prompt in prompts.prompt_templates:
53
- __write_single_file(environment, output_dir, project_id, prompt)
53
+ __write_single_file(environment, output_dir, prompt)
54
+ except FreeplayClientError as e:
55
+ print(f"Error downloading templates: {e}.\nIs your project ID correct?", file=sys.stderr)
56
+ exit(1)
57
+ except FreeplayServerError as e:
58
+ print(f"Error on Freeplay's servers downloading templates: {e}.\nTry again after a short wait.",
59
+ file=sys.stderr)
60
+ exit(2)
61
+ except Exception as e:
62
+ print(f"Error downloading templates: {e}", file=sys.stderr)
63
+ exit(3)
64
+
65
+
66
+ @cli.command()
67
+ @click.option("--environment", required=True, help="The environment from which the prompts will be pulled.", default="latest")
68
+ @click.option("--output-dir", required=True, help="The directory where the prompts will be saved.")
69
+ def download_all(environment: str, output_dir: str) -> None:
70
+ if "FREEPLAY_API_KEY" not in os.environ:
71
+ print("FREEPLAY_API_KEY is not set. It is required to run the freeplay command.", file=sys.stderr)
72
+ exit(4)
73
+
74
+ if "FREEPLAY_SUBDOMAIN" not in os.environ:
75
+ print("FREEPLAY_SUBDOMAIN is not set. It is required to run the freeplay command.", file=sys.stderr)
76
+ exit(4)
77
+
78
+ FREEPLAY_API_KEY = os.environ["FREEPLAY_API_KEY"]
79
+ freeplay_api_url = f'https://{os.environ["FREEPLAY_SUBDOMAIN"]}.freeplay.ai/api'
80
+
81
+ if "FREEPLAY_API_URL" in os.environ:
82
+ freeplay_api_url = f'{os.environ["FREEPLAY_API_URL"]}/api'
83
+ click.echo("Using URL override for Freeplay specified in the FREEPLAY_API_URL environment variable")
84
+
85
+ click.echo(
86
+ f"Downloading prompts for environment {environment}, "
87
+ f"to directory {output_dir} from {freeplay_api_url}")
88
+
89
+ fp_client = Freeplay(
90
+ freeplay_api_key=FREEPLAY_API_KEY,
91
+ api_base=freeplay_api_url
92
+ )
93
+
94
+ try:
95
+ prompts: PromptTemplates = fp_client.prompts.get_all_for_environment(environment=environment)
96
+ click.echo(f"Found {len(prompts.prompt_templates)} prompt templates")
97
+
98
+ for prompt in prompts.prompt_templates:
99
+ __write_single_file(environment, output_dir, prompt)
54
100
  except FreeplayClientError as e:
55
101
  print(f"Error downloading templates: {e}.\nIs your project ID correct?", file=sys.stderr)
56
102
  exit(1)
@@ -66,10 +112,9 @@ def download(project_id: str, environment: str, output_dir: str) -> None:
66
112
  def __write_single_file(
67
113
  environment: str,
68
114
  output_dir: str,
69
- project_id: str,
70
115
  prompt: PromptTemplate
71
116
  ) -> None:
72
- directory = __root_dir(environment, output_dir, project_id)
117
+ directory = __root_dir(environment, output_dir, prompt.project_id)
73
118
  basename = f'{prompt.prompt_template_name}'
74
119
  prompt_path = directory / f'{basename}.json'
75
120
  click.echo("Writing prompt file: %s" % prompt_path)
@@ -87,6 +132,6 @@ def __write_single_file(
87
132
 
88
133
 
89
134
  def __root_dir(environment: str, output_dir: str, project_id: str) -> Path:
90
- directory = Path(output_dir) / "freeplay" / "prompts" / project_id / environment
135
+ directory = Path(output_dir).resolve() / "freeplay" / "prompts" / project_id / environment
91
136
  os.makedirs(directory, exist_ok=True)
92
137
  return directory
@@ -557,6 +557,9 @@ class Prompts:
557
557
 
558
558
  return TemplatePrompt(prompt_info, prompt.content, prompt.tool_schema)
559
559
 
560
+ def get_all_for_environment(self, environment: str) -> PromptTemplates:
561
+ return self.call_support.get_prompts_for_environment(environment=environment)
562
+
560
563
  def get_by_version_id(self, project_id: str, template_id: str, version_id: str) -> TemplatePrompt:
561
564
  prompt = self.template_resolver.get_prompt_version_id(project_id, template_id, version_id)
562
565
 
@@ -76,6 +76,17 @@ class SummaryStatistics:
76
76
  human_evaluation: Dict[str, Any]
77
77
 
78
78
 
79
+ @dataclass
80
+ class ProjectInfo:
81
+ id: str
82
+ name: str
83
+
84
+
85
+ @dataclass
86
+ class ProjectInfos:
87
+ projects: List[ProjectInfo]
88
+
89
+
79
90
  class PromptTemplateEncoder(JSONEncoder):
80
91
  def default(self, prompt_template: PromptTemplate) -> Dict[str, Any]:
81
92
  return prompt_template.__dict__
@@ -89,6 +100,7 @@ class TestCaseTestRunResponse:
89
100
  self.history: Optional[List[Dict[str, Any]]] = test_case.get('history')
90
101
  self.custom_metadata: Optional[Dict[str, str]] = test_case.get('custom_metadata')
91
102
 
103
+
92
104
  class TraceTestCaseTestRunResponse:
93
105
  def __init__(self, test_case: Dict[str, Any]):
94
106
  self.id: str = test_case['test_case_id']
@@ -96,6 +108,7 @@ class TraceTestCaseTestRunResponse:
96
108
  self.output: Optional[str] = test_case.get('output')
97
109
  self.custom_metadata: Optional[Dict[str, str]] = test_case.get('custom_metadata')
98
110
 
111
+
99
112
  class TestRunResponse:
100
113
  def __init__(
101
114
  self,
@@ -185,6 +198,26 @@ class CallSupport:
185
198
 
186
199
  return maybe_prompts
187
200
 
201
+ def get_prompts_for_environment(self, environment: str) -> PromptTemplates:
202
+ projects_response = api_support.get_raw(
203
+ api_key=self.freeplay_api_key,
204
+ url=f'{self.api_base}/v2/projects/all'
205
+ )
206
+ if projects_response.status_code != 200:
207
+ raise freeplay_response_error("Error getting prompt templates", projects_response)
208
+
209
+ maybe_projects: Optional[ProjectInfos] = try_decode(ProjectInfos, projects_response.content)
210
+ if maybe_projects is None:
211
+ raise FreeplayServerError('Failed to parse list of projects from server')
212
+
213
+ prompt_templates = PromptTemplates([])
214
+ for project in maybe_projects.projects:
215
+ prompt_templates.prompt_templates.extend(
216
+ self.get_prompts(project.id, environment).prompt_templates
217
+ )
218
+
219
+ return prompt_templates
220
+
188
221
  def get_prompt(self, project_id: str, template_name: str, environment: str) -> PromptTemplate:
189
222
  response = api_support.get_raw(
190
223
  api_key=self.freeplay_api_key,
File without changes
File without changes