@fencyai/react 0.1.30 → 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.
@@ -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,17 +46,28 @@ export function useChatCompletion() {
38
46
  const jsonSchema = params.responseFormat
39
47
  ? z.toJSONSchema(params.responseFormat)
40
48
  : undefined;
49
+ const parsedJsonSchema = jsonSchema
50
+ ? JSON.stringify(jsonSchema)
51
+ : undefined;
41
52
  const chatCompletion = await createChatCompletion({
42
53
  pk: fency.fency.publishableKey,
43
54
  baseUrl: fency.fency.baseUrl,
44
55
  request: {
45
- openai: {
46
- model: params.model,
47
- responseJsonSchema: jsonSchema
48
- ? JSON.stringify(jsonSchema)
49
- : undefined,
50
- messages: [{ role: 'user', content: params.prompt }],
51
- },
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,
52
71
  },
53
72
  });
54
73
  setChatCompletions((prev) => [...prev, chatCompletion]);
@@ -85,7 +104,7 @@ export function useChatCompletion() {
85
104
  }, [completions]);
86
105
  useEffect(() => {
87
106
  if (stream) {
88
- 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}`);
89
108
  }
90
109
  }, [stream, fency.fency.publishableKey, setUrl]);
91
110
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/react",
3
- "version": "0.1.30",
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.30",
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.30",
48
+ "@fencyai/js": "^0.1.31",
48
49
  "react": ">=16.8.0"
49
50
  },
50
- "gitHead": "ee47632e633fd659d4cfdf8c07bbe8c543764973"
51
+ "gitHead": "f39a452d0e2f90f06abc307f8aa04edbb7121680"
51
52
  }