@fencyai/react 0.1.29 → 0.1.31

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.
@@ -10,21 +10,20 @@ export function FencyProvider({ fency, children }) {
10
10
  const [fencyInstance, setFencyInstance] = useState(null);
11
11
  const [loading, setLoading] = useState(true);
12
12
  const [error, setError] = useState(null);
13
- console.log('new fency provider');
14
13
  useEffect(() => {
15
14
  fency
16
15
  .then((instance) => {
17
- console.log('fency instance', instance);
18
16
  setFencyInstance(instance);
19
17
  setLoading(false);
20
18
  })
21
19
  .catch((err) => {
22
- console.log('fency error', err);
23
- console.error(err);
24
20
  setError(err);
25
21
  setLoading(false);
26
22
  });
27
23
  }, [fency]);
24
+ if (error) {
25
+ return _jsxs("div", { children: ["Fency error: ", error.message] });
26
+ }
28
27
  // Only render children and provide context when fency is loaded
29
28
  if (!fencyInstance) {
30
29
  return null;
@@ -34,9 +33,5 @@ export function FencyProvider({ fency, children }) {
34
33
  loading,
35
34
  error,
36
35
  };
37
- console.log('error', error);
38
- if (error) {
39
- return _jsxs("div", { children: ["Fency error: ", error.message] });
40
- }
41
36
  return (_jsx(FencyContextValue.Provider, { value: value, children: children }));
42
37
  }
@@ -1,4 +1,4 @@
1
- import { ChatCompletion } from '@fencyai/js';
1
+ import { AnthropicModel, ChatCompletion, CreateSynchronousChatCompletionParams, GeminiModel, OpenAiModel } from '@fencyai/js';
2
2
  import z, { ZodTypeAny } from 'zod';
3
3
  import { ChatCompletionChunk } from './useEventSource';
4
4
  interface Completions {
@@ -11,15 +11,17 @@ interface Completions {
11
11
  interface HookResponse {
12
12
  chatCompletions: Completions[];
13
13
  createStreamingChatCompletion: (params: {
14
- prompt: string;
15
- model: 'gpt-4o-mini' | 'gpt-4o';
14
+ openai?: CreateSynchronousChatCompletionParams<OpenAiModel>;
15
+ gemini?: CreateSynchronousChatCompletionParams<GeminiModel>;
16
+ anthropic?: CreateSynchronousChatCompletionParams<AnthropicModel>;
16
17
  }) => Promise<{
17
18
  chatCompletionStreamId: string;
18
19
  chatCompletionId: string;
19
20
  }>;
20
21
  createSynchronousChatCompletion: <T extends ZodTypeAny>(params: {
21
- prompt: string;
22
- model: 'gpt-4o-mini' | 'gpt-4o';
22
+ openai?: CreateSynchronousChatCompletionParams<OpenAiModel>;
23
+ gemini?: CreateSynchronousChatCompletionParams<GeminiModel>;
24
+ anthropic?: CreateSynchronousChatCompletionParams<AnthropicModel>;
23
25
  responseFormat?: T;
24
26
  }) => Promise<ChatCompletion & {
25
27
  structuredResponse?: z.infer<T>;
@@ -22,10 +22,18 @@ export function useChatCompletion() {
22
22
  baseUrl: fency.fency.baseUrl,
23
23
  request: {
24
24
  chatCompletionStreamId: s.chatCompletionStreamId,
25
- openai: {
26
- model: params.model,
27
- messages: [{ role: 'user', content: params.prompt }],
28
- },
25
+ openai: params.openai ? {
26
+ model: params.openai.model,
27
+ messages: params.openai.messages,
28
+ } : undefined,
29
+ gemini: params.gemini ? {
30
+ model: params.gemini.model,
31
+ messages: params.gemini.messages,
32
+ } : undefined,
33
+ anthropic: params.anthropic ? {
34
+ model: params.anthropic.model,
35
+ messages: params.anthropic.messages,
36
+ } : undefined,
29
37
  },
30
38
  });
31
39
  setChatCompletions((prev) => [...prev, chatCompletion]);
@@ -38,18 +46,28 @@ export function useChatCompletion() {
38
46
  const jsonSchema = params.responseFormat
39
47
  ? z.toJSONSchema(params.responseFormat)
40
48
  : undefined;
41
- console.log(jsonSchema);
49
+ const parsedJsonSchema = jsonSchema
50
+ ? JSON.stringify(jsonSchema)
51
+ : undefined;
42
52
  const chatCompletion = await createChatCompletion({
43
53
  pk: fency.fency.publishableKey,
44
54
  baseUrl: fency.fency.baseUrl,
45
55
  request: {
46
- openai: {
47
- model: params.model,
48
- responseJsonSchema: jsonSchema
49
- ? JSON.stringify(jsonSchema)
50
- : undefined,
51
- messages: [{ role: 'user', content: params.prompt }],
52
- },
56
+ openai: params.openai ? {
57
+ model: params.openai.model,
58
+ responseJsonSchema: parsedJsonSchema,
59
+ messages: params.openai.messages,
60
+ } : undefined,
61
+ gemini: params.gemini ? {
62
+ model: params.gemini.model,
63
+ responseJsonSchema: parsedJsonSchema,
64
+ messages: params.gemini.messages,
65
+ } : undefined,
66
+ anthropic: params.anthropic ? {
67
+ model: params.anthropic.model,
68
+ responseJsonSchema: parsedJsonSchema,
69
+ messages: params.anthropic.messages,
70
+ } : undefined,
53
71
  },
54
72
  });
55
73
  setChatCompletions((prev) => [...prev, chatCompletion]);
@@ -86,7 +104,7 @@ export function useChatCompletion() {
86
104
  }, [completions]);
87
105
  useEffect(() => {
88
106
  if (stream) {
89
- setUrl(`http://localhost:8080/v1/pub/chat-completion-streams/${stream.chatCompletionStreamId}?pk=${fency.fency.publishableKey}`);
107
+ setUrl(`${fency.fency.baseUrl}/v1/pub/chat-completion-streams/${stream.chatCompletionStreamId}?pk=${fency.fency.publishableKey}`);
90
108
  }
91
109
  }, [stream, fency.fency.publishableKey, setUrl]);
92
110
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/react",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "> TODO: description",
5
5
  "author": "staklau <steinaageklaussen@gmail.com>",
6
6
  "homepage": "",
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsc",
29
+ "build:watch": "tsc --watch",
29
30
  "test": "jest",
30
31
  "test:watch": "jest --watch",
31
32
  "dev": "tsc --watch",
@@ -35,7 +36,7 @@
35
36
  "zod": "^4.0.5"
36
37
  },
37
38
  "devDependencies": {
38
- "@fencyai/js": "^0.1.29",
39
+ "@fencyai/js": "^0.1.31",
39
40
  "@types/jest": "^29.5.11",
40
41
  "@types/node": "^20.10.5",
41
42
  "@types/react": "^18.2.45",
@@ -44,8 +45,8 @@
44
45
  "typescript": "^5.3.3"
45
46
  },
46
47
  "peerDependencies": {
47
- "@fencyai/js": "^0.1.29",
48
+ "@fencyai/js": "^0.1.31",
48
49
  "react": ">=16.8.0"
49
50
  },
50
- "gitHead": "a258f0148d6115750bf28a6828319477012517fb"
51
+ "gitHead": "f39a452d0e2f90f06abc307f8aa04edbb7121680"
51
52
  }