@truedat/ai 6.3.0 → 6.3.2

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.
@@ -0,0 +1,77 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<Providers /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui segment"
7
+ >
8
+ <h2
9
+ class="ui header"
10
+ >
11
+ <i
12
+ aria-hidden="true"
13
+ class="map signs circular icon"
14
+ />
15
+ <div
16
+ class="content"
17
+ >
18
+ providers.header
19
+ <div
20
+ class="sub header"
21
+ >
22
+ providers.subheader
23
+ </div>
24
+ </div>
25
+ </h2>
26
+ <div
27
+ class="ui grid"
28
+ >
29
+ <div
30
+ class="four wide column"
31
+ >
32
+ <button
33
+ class="ui fluid button"
34
+ >
35
+ providers.action.new
36
+ </button>
37
+ <div
38
+ class="ui divided selection list"
39
+ role="list"
40
+ >
41
+ <div
42
+ class="item"
43
+ role="listitem"
44
+ >
45
+ <div
46
+ class="content"
47
+ >
48
+ <div
49
+ class="header"
50
+ >
51
+ rm1
52
+ </div>
53
+ </div>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ <div
58
+ class="eleven wide column"
59
+ >
60
+ <h2
61
+ class="ui icon center aligned header"
62
+ >
63
+ <i
64
+ aria-hidden="true"
65
+ class="hand pointer outline icon"
66
+ />
67
+ <div
68
+ class="sub header"
69
+ >
70
+ providers.no_selection
71
+ </div>
72
+ </h2>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>
77
+ `;
@@ -0,0 +1,125 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl";
3
+ import { Controller, useFormContext } from "react-hook-form";
4
+ import { Form } from "semantic-ui-react";
5
+
6
+ export default function AzureOpenai() {
7
+ const { formatMessage } = useIntl();
8
+ const { control } = useFormContext();
9
+
10
+ return (
11
+ <>
12
+ <Controller
13
+ control={control}
14
+ name="properties.resource_name"
15
+ rules={{
16
+ required: formatMessage(
17
+ { id: "form.validation.required" },
18
+ {
19
+ prop: formatMessage({
20
+ id: "providerProperties.form.resourceName",
21
+ }),
22
+ }
23
+ ),
24
+ }}
25
+ render={({
26
+ field: { onBlur, onChange, value },
27
+ fieldState: { error },
28
+ }) => (
29
+ <Form.Input
30
+ autoComplete="off"
31
+ placeholder={formatMessage({
32
+ id: "providerProperties.form.resourceName",
33
+ })}
34
+ error={error?.message}
35
+ label={formatMessage({
36
+ id: "providerProperties.form.resourceName",
37
+ })}
38
+ onBlur={onBlur}
39
+ onChange={(_e, { value }) => onChange(value)}
40
+ value={value}
41
+ required
42
+ />
43
+ )}
44
+ />
45
+ <Controller
46
+ control={control}
47
+ name="properties.deployment"
48
+ rules={{
49
+ required: formatMessage(
50
+ { id: "form.validation.required" },
51
+ {
52
+ prop: formatMessage({
53
+ id: "providerProperties.form.deployment",
54
+ }),
55
+ }
56
+ ),
57
+ }}
58
+ render={({
59
+ field: { onBlur, onChange, value },
60
+ fieldState: { error },
61
+ }) => (
62
+ <Form.Input
63
+ autoComplete="off"
64
+ placeholder={formatMessage({
65
+ id: "providerProperties.form.deployment",
66
+ })}
67
+ error={error?.message}
68
+ label={formatMessage({
69
+ id: "providerProperties.form.deployment",
70
+ })}
71
+ onBlur={onBlur}
72
+ onChange={(_e, { value }) => onChange(value)}
73
+ value={value}
74
+ required
75
+ />
76
+ )}
77
+ />
78
+ <Controller
79
+ control={control}
80
+ name="properties.api_version"
81
+ render={({
82
+ field: { onBlur, onChange, value },
83
+ fieldState: { error },
84
+ }) => (
85
+ <Form.Input
86
+ autoComplete="off"
87
+ placeholder={formatMessage({
88
+ id: "providerProperties.form.apiVersion",
89
+ })}
90
+ error={error?.message}
91
+ label={formatMessage({
92
+ id: "providerProperties.form.apiVersion",
93
+ })}
94
+ onBlur={onBlur}
95
+ onChange={(_e, { value }) => onChange(value)}
96
+ value={value}
97
+ />
98
+ )}
99
+ />
100
+ <Controller
101
+ control={control}
102
+ name="properties.api_key"
103
+ render={({
104
+ field: { onBlur, onChange, value },
105
+ fieldState: { error },
106
+ }) => (
107
+ <Form.Input
108
+ type="password"
109
+ autoComplete="off"
110
+ placeholder={formatMessage({
111
+ id: "providerProperties.form.apiKey",
112
+ })}
113
+ error={error?.message}
114
+ label={formatMessage({
115
+ id: "providerProperties.form.apiKey",
116
+ })}
117
+ onBlur={onBlur}
118
+ onChange={(_e, { value }) => onChange(value)}
119
+ value={value}
120
+ />
121
+ )}
122
+ />
123
+ </>
124
+ );
125
+ }
@@ -0,0 +1,170 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl";
3
+ import { Controller, useFormContext } from "react-hook-form";
4
+ import { Form } from "semantic-ui-react";
5
+
6
+ export default function BedrockClaude() {
7
+ const { formatMessage } = useIntl();
8
+ const { control } = useFormContext();
9
+
10
+ return (
11
+ <>
12
+ <Controller
13
+ control={control}
14
+ name="properties.model"
15
+ rules={{
16
+ required: formatMessage(
17
+ { id: "form.validation.required" },
18
+ {
19
+ prop: formatMessage({
20
+ id: "providerProperties.form.model",
21
+ }),
22
+ }
23
+ ),
24
+ }}
25
+ render={({
26
+ field: { onBlur, onChange, value },
27
+ fieldState: { error },
28
+ }) => (
29
+ <Form.Input
30
+ autoComplete="off"
31
+ placeholder={formatMessage({
32
+ id: "providerProperties.form.model",
33
+ })}
34
+ error={error?.message}
35
+ label={formatMessage({
36
+ id: "providerProperties.form.model",
37
+ })}
38
+ onBlur={onBlur}
39
+ onChange={(_e, { value }) => onChange(value)}
40
+ value={value}
41
+ required
42
+ />
43
+ )}
44
+ />
45
+ <Controller
46
+ control={control}
47
+ name="properties.temperature"
48
+ render={({
49
+ field: { onBlur, onChange, value },
50
+ fieldState: { error },
51
+ }) => (
52
+ <Form.Input
53
+ autoComplete="off"
54
+ placeholder={formatMessage({
55
+ id: "providerProperties.form.temperature",
56
+ })}
57
+ error={error?.message}
58
+ label={formatMessage({
59
+ id: "providerProperties.form.temperature",
60
+ })}
61
+ onBlur={onBlur}
62
+ onChange={(_e, { value }) => onChange(value)}
63
+ value={value}
64
+ />
65
+ )}
66
+ />
67
+ <Controller
68
+ control={control}
69
+ name="properties.top_p"
70
+ render={({
71
+ field: { onBlur, onChange, value },
72
+ fieldState: { error },
73
+ }) => (
74
+ <Form.Input
75
+ autoComplete="off"
76
+ placeholder={formatMessage({
77
+ id: "providerProperties.form.topP",
78
+ })}
79
+ error={error?.message}
80
+ label={formatMessage({
81
+ id: "providerProperties.form.topP",
82
+ })}
83
+ onBlur={onBlur}
84
+ onChange={(_e, { value }) => onChange(value)}
85
+ value={value}
86
+ />
87
+ )}
88
+ />
89
+ <Controller
90
+ control={control}
91
+ name="properties.access_key_id"
92
+ render={({
93
+ field: { onBlur, onChange, value },
94
+ fieldState: { error },
95
+ }) => (
96
+ <Form.Input
97
+ type="password"
98
+ autoComplete="off"
99
+ placeholder={formatMessage({
100
+ id: "providerProperties.form.accessKeyId",
101
+ })}
102
+ error={error?.message}
103
+ label={formatMessage({
104
+ id: "providerProperties.form.accessKeyId",
105
+ })}
106
+ onBlur={onBlur}
107
+ onChange={(_e, { value }) => onChange(value)}
108
+ value={value}
109
+ />
110
+ )}
111
+ />
112
+ <Controller
113
+ control={control}
114
+ name="properties.secret_access_key"
115
+ render={({
116
+ field: { onBlur, onChange, value },
117
+ fieldState: { error },
118
+ }) => (
119
+ <Form.Input
120
+ type="password"
121
+ autoComplete="off"
122
+ placeholder={formatMessage({
123
+ id: "providerProperties.form.secretAccessKey",
124
+ })}
125
+ error={error?.message}
126
+ label={formatMessage({
127
+ id: "providerProperties.form.secretAccessKey",
128
+ })}
129
+ onBlur={onBlur}
130
+ onChange={(_e, { value }) => onChange(value)}
131
+ value={value}
132
+ />
133
+ )}
134
+ />
135
+ <Controller
136
+ control={control}
137
+ name="properties.aws_region"
138
+ rules={{
139
+ required: formatMessage(
140
+ { id: "form.validation.required" },
141
+ {
142
+ prop: formatMessage({
143
+ id: "providerProperties.form.organizationKey",
144
+ }),
145
+ }
146
+ ),
147
+ }}
148
+ render={({
149
+ field: { onBlur, onChange, value },
150
+ fieldState: { error },
151
+ }) => (
152
+ <Form.Input
153
+ autoComplete="off"
154
+ placeholder={formatMessage({
155
+ id: "providerProperties.form.awsRegion",
156
+ })}
157
+ error={error?.message}
158
+ label={formatMessage({
159
+ id: "providerProperties.form.awsRegion",
160
+ })}
161
+ onBlur={onBlur}
162
+ onChange={(_e, { value }) => onChange(value)}
163
+ value={value}
164
+ required
165
+ />
166
+ )}
167
+ />
168
+ </>
169
+ );
170
+ }
@@ -0,0 +1,103 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl";
3
+ import { Controller, useFormContext } from "react-hook-form";
4
+ import { Form } from "semantic-ui-react";
5
+
6
+ export default function Openai() {
7
+ const { formatMessage } = useIntl();
8
+ const { control } = useFormContext();
9
+
10
+ return (
11
+ <>
12
+ <Controller
13
+ control={control}
14
+ name="properties.model"
15
+ rules={{
16
+ required: formatMessage(
17
+ { id: "form.validation.required" },
18
+ {
19
+ prop: formatMessage({
20
+ id: "providerProperties.form.model",
21
+ }),
22
+ }
23
+ ),
24
+ }}
25
+ render={({
26
+ field: { onBlur, onChange, value },
27
+ fieldState: { error },
28
+ }) => (
29
+ <Form.Input
30
+ autoComplete="off"
31
+ placeholder={formatMessage({
32
+ id: "providerProperties.form.model",
33
+ })}
34
+ error={error?.message}
35
+ label={formatMessage({
36
+ id: "providerProperties.form.model",
37
+ })}
38
+ onBlur={onBlur}
39
+ onChange={(_e, { value }) => onChange(value)}
40
+ value={value}
41
+ required
42
+ />
43
+ )}
44
+ />
45
+ <Controller
46
+ control={control}
47
+ name="properties.organization_key"
48
+ rules={{
49
+ required: formatMessage(
50
+ { id: "form.validation.required" },
51
+ {
52
+ prop: formatMessage({
53
+ id: "providerProperties.form.organizationKey",
54
+ }),
55
+ }
56
+ ),
57
+ }}
58
+ render={({
59
+ field: { onBlur, onChange, value },
60
+ fieldState: { error },
61
+ }) => (
62
+ <Form.Input
63
+ autoComplete="off"
64
+ placeholder={formatMessage({
65
+ id: "providerProperties.form.organizationKey",
66
+ })}
67
+ error={error?.message}
68
+ label={formatMessage({
69
+ id: "providerProperties.form.organizationKey",
70
+ })}
71
+ onBlur={onBlur}
72
+ onChange={(_e, { value }) => onChange(value)}
73
+ value={value}
74
+ required
75
+ />
76
+ )}
77
+ />
78
+ <Controller
79
+ control={control}
80
+ name="properties.api_key"
81
+ render={({
82
+ field: { onBlur, onChange, value },
83
+ fieldState: { error },
84
+ }) => (
85
+ <Form.Input
86
+ type="password"
87
+ autoComplete="off"
88
+ placeholder={formatMessage({
89
+ id: "providerProperties.form.apiKey",
90
+ })}
91
+ error={error?.message}
92
+ label={formatMessage({
93
+ id: "providerProperties.form.apiKey",
94
+ })}
95
+ onBlur={onBlur}
96
+ onChange={(_e, { value }) => onChange(value)}
97
+ value={value}
98
+ />
99
+ )}
100
+ />
101
+ </>
102
+ );
103
+ }
@@ -0,0 +1,5 @@
1
+ import Openai from "./Openai";
2
+ import AzureOpenai from "./AzureOpenai";
3
+ import BedrockClaude from "./BedrockClaude";
4
+
5
+ export { Openai, AzureOpenai, BedrockClaude };
@@ -0,0 +1,101 @@
1
+ import _ from "lodash/fp";
2
+ import { compile } from "path-to-regexp";
3
+ import useSWR from "swr";
4
+ import useSWRMutations from "swr/mutation";
5
+ import { renderHook } from "@testing-library/react-hooks";
6
+ import {
7
+ apiJson,
8
+ apiJsonPost,
9
+ apiJsonPatch,
10
+ apiJsonDelete,
11
+ } from "@truedat/core/services/api";
12
+ import { API_PROVIDERS, API_PROVIDER } from "../../api";
13
+ import {
14
+ useProviders,
15
+ useProviderCreate,
16
+ useProviderUpdate,
17
+ useProviderDelete,
18
+ } from "../useProviders";
19
+
20
+ jest.mock("swr", () => ({
21
+ __esModule: true,
22
+ ...jest.requireActual("swr"),
23
+ default: jest.fn(() => ({
24
+ data: { data: "data" },
25
+ error: null,
26
+ mutate: jest.fn(),
27
+ })),
28
+ }));
29
+
30
+ jest.mock("swr/mutation", () => ({
31
+ __esModule: true,
32
+ ...jest.requireActual("swr/mutation"),
33
+ default: jest.fn(),
34
+ }));
35
+
36
+ jest.mock("@truedat/core/services/api", () => ({
37
+ __esModule: true,
38
+ ...jest.requireActual("@truedat/core/services/api"),
39
+ apiJsonPost: jest.fn(),
40
+ apiJsonPatch: jest.fn(),
41
+ apiJsonDelete: jest.fn(),
42
+ }));
43
+
44
+ describe("useProviders", () => {
45
+ it("useProviders calls useSWR with correct api route", () => {
46
+ const { result } = renderHook(() => useProviders());
47
+
48
+ expect(result.current).toMatchObject({
49
+ data: "data",
50
+ error: null,
51
+ loading: false,
52
+ });
53
+
54
+ expect(useSWR).toHaveBeenCalledWith(API_PROVIDERS, apiJson);
55
+ });
56
+ it("useProviderCreate calls useSWRMutations with correct api route", () => {
57
+ renderHook(() => useProviderCreate());
58
+ const [url, func] = _.last(useSWRMutations.mock.calls);
59
+ const arg = { some: "arg" };
60
+ expect(url).toBe(API_PROVIDERS);
61
+ func(url, { arg });
62
+
63
+ expect(apiJsonPost).toHaveBeenCalledWith(url, arg);
64
+ });
65
+ it("useProviderUpdate calls useSWRMutations with correct api route", () => {
66
+ const id = 8;
67
+ renderHook(() => useProviderUpdate({ id }));
68
+ const [url, func] = _.last(useSWRMutations.mock.calls);
69
+ const arg = { some: "arg" };
70
+ expect(url).toBe(compile(API_PROVIDER)({ id }));
71
+ func(url, { arg });
72
+
73
+ expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
74
+ });
75
+ it("useProviderUpdate without args will render id 0", () => {
76
+ renderHook(() => useProviderUpdate());
77
+ const [url, func] = _.last(useSWRMutations.mock.calls);
78
+ const arg = { some: "arg" };
79
+ expect(url).toBe(compile(API_PROVIDER)({ id: 0 }));
80
+ func(url, { arg });
81
+ expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
82
+ });
83
+ it("useProviderDelete calls useSWRMutations with correct api route", () => {
84
+ const id = 8;
85
+ renderHook(() => useProviderDelete({ id }));
86
+ const [url, func] = _.last(useSWRMutations.mock.calls);
87
+ const arg = { some: "arg" };
88
+ expect(url).toBe(compile(API_PROVIDER)({ id }));
89
+ func(url, { arg });
90
+
91
+ expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
92
+ });
93
+ it("useProviderDelete without args will render id 0", () => {
94
+ renderHook(() => useProviderDelete());
95
+ const [url, func] = _.last(useSWRMutations.mock.calls);
96
+ const arg = { some: "arg" };
97
+ expect(url).toBe(compile(API_PROVIDER)({ id: 0 }));
98
+ func(url, { arg });
99
+ expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
100
+ });
101
+ });
@@ -0,0 +1,38 @@
1
+ import { compile } from "path-to-regexp";
2
+ import useSWR from "swr";
3
+ import useSWRMutations from "swr/mutation";
4
+ import {
5
+ apiJson,
6
+ apiJsonPost,
7
+ apiJsonPatch,
8
+ apiJsonDelete,
9
+ } from "@truedat/core/services/api";
10
+ import { API_PROVIDERS, API_PROVIDER, API_PROVIDER_CHAT } from "../api";
11
+
12
+ export const useProviders = () => {
13
+ const { data, error, mutate } = useSWR(API_PROVIDERS, apiJson);
14
+ return { data: data?.data, error, loading: !error && !data, mutate };
15
+ };
16
+
17
+ export const useProviderCreate = () => {
18
+ return useSWRMutations(API_PROVIDERS, (url, { arg }) =>
19
+ apiJsonPost(url, arg)
20
+ );
21
+ };
22
+
23
+ export const useProviderUpdate = (payload) => {
24
+ const id = payload?.id || 0;
25
+ const url = compile(API_PROVIDER)({ id });
26
+ return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
27
+ };
28
+
29
+ export const useProviderChatCompletion = (id) => {
30
+ const url = compile(API_PROVIDER_CHAT)({ id });
31
+ return useSWRMutations(url, (url, { arg }) => apiJsonPost(url, arg));
32
+ };
33
+
34
+ export const useProviderDelete = (payload) => {
35
+ const id = payload?.id || 0;
36
+ const url = compile(API_PROVIDER)({ id });
37
+ return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
38
+ };