Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

share.ts 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  1. import { fetchWithProxy } from './fetch';
  2. import { REMOTE_API_BASE_URL, REMOTE_APP_BASE_URL } from './constants';
  3. import type { EvaluateSummary, SharedResults, UnifiedConfig } from './types';
  4. export async function createShareableUrl(
  5. results: EvaluateSummary,
  6. config: Partial<UnifiedConfig>,
  7. ): Promise<string> {
  8. const sharedResults: SharedResults = {
  9. data: {
  10. version: 2,
  11. // TODO(ian): Take date from results, if applicable.
  12. createdAt: new Date().toISOString(),
  13. results,
  14. config,
  15. },
  16. };
  17. const apiBaseUrl =
  18. typeof config.sharing === 'object' ? config.sharing.apiBaseUrl : REMOTE_API_BASE_URL;
  19. const response = await fetchWithProxy(`${apiBaseUrl}/api/eval`, {
  20. method: 'POST',
  21. headers: {
  22. 'Content-Type': 'application/json',
  23. },
  24. body: JSON.stringify(sharedResults),
  25. });
  26. const responseJson = (await response.json()) as { id?: string; error?: string };
  27. if (responseJson.error) {
  28. throw new Error(`Failed to create shareable URL: ${responseJson.error}`);
  29. }
  30. const appBaseUrl =
  31. typeof config.sharing === 'object' ? config.sharing.appBaseUrl : REMOTE_APP_BASE_URL;
  32. return `${appBaseUrl}/eval/${responseJson.id}`;
  33. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...