@fencyai/react 0.1.40 → 0.1.41
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.
- package/lib/index.d.ts +3 -0
- package/lib/useChatCompletions/index.d.ts +6 -19
- package/lib/useChatCompletions/index.js +0 -1
- package/lib/useChatCompletions/types.d.ts +24 -0
- package/lib/useChatCompletions/types.js +1 -0
- package/lib/useChatCompletions/useStreamingChatCompletions.d.ts +8 -6
- package/lib/useChatCompletions/useStreamingChatCompletions.js +0 -3
- package/lib/useChatCompletions/useStructuredChatCompletions.d.ts +9 -7
- package/lib/useChatCompletions/useStructuredChatCompletions.js +2 -1
- package/lib/useChatCompletions/useSynchronousChatCompletions.d.ts +7 -6
- package/lib/useChatCompletions/useSynchronousChatCompletions.js +1 -1
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { useChatCompletions } from './useChatCompletions';
|
|
2
2
|
export { FencyProvider, FencyProviderProps } from './provider/FencyProvider';
|
|
3
|
+
export { CreateStreamingChatCompletionParams } from './useChatCompletions/useStreamingChatCompletions';
|
|
4
|
+
export { CreateStructuredChatCompletionParams } from './useChatCompletions/useStructuredChatCompletions';
|
|
5
|
+
export { CreateSynchronousChatCompletionParams } from './useChatCompletions/useSynchronousChatCompletions';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CreateAnthropicChatCompletionParams, CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from '@fencyai/js';
|
|
2
1
|
import { ApiError } from '@fencyai/js/lib/types/ApiError';
|
|
3
2
|
import { ZodTypeAny } from 'zod';
|
|
4
|
-
import { StreamingChatCompletion } from './useStreamingChatCompletions';
|
|
5
|
-
import { StructuredChatCompletion, StructuredChatCompletionResponse } from './useStructuredChatCompletions';
|
|
6
|
-
import { SynchronousChatCompletion, SynchronousChatCompletionResponse } from './useSynchronousChatCompletions';
|
|
3
|
+
import { CreateStreamingChatCompletionParams, StreamingChatCompletion } from './useStreamingChatCompletions';
|
|
4
|
+
import { CreateStructuredChatCompletionParams, StructuredChatCompletion, StructuredChatCompletionResponse } from './useStructuredChatCompletions';
|
|
5
|
+
import { CreateSynchronousChatCompletionParams, SynchronousChatCompletion, SynchronousChatCompletionResponse } from './useSynchronousChatCompletions';
|
|
7
6
|
type CombinedChatCompletion = {
|
|
8
7
|
type: 'synchronous';
|
|
9
8
|
chatCompletion: SynchronousChatCompletion;
|
|
@@ -21,21 +20,9 @@ interface HookResponse {
|
|
|
21
20
|
streaming: StreamingChatCompletion | null;
|
|
22
21
|
};
|
|
23
22
|
chatCompletions: CombinedChatCompletion[];
|
|
24
|
-
createChatCompletion: (params:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
28
|
-
}) => Promise<SynchronousChatCompletionResponse>;
|
|
29
|
-
createStructuredChatCompletion: <T extends ZodTypeAny>(params: {
|
|
30
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
31
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
32
|
-
responseFormat: T;
|
|
33
|
-
}) => Promise<StructuredChatCompletionResponse<T>>;
|
|
34
|
-
createStreamingChatCompletion: (params: {
|
|
35
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
36
|
-
anthropic?: CreateAnthropicChatCompletionParams;
|
|
37
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
38
|
-
}) => Promise<{
|
|
23
|
+
createChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
|
24
|
+
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
25
|
+
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
39
26
|
type: 'success';
|
|
40
27
|
chatCompletionStreamId: string;
|
|
41
28
|
chatCompletionId: string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AnthropicModel } from '@fencyai/js/lib/types/AnthropicModel';
|
|
2
|
+
import { ChatCompletionMessage } from '@fencyai/js/lib/types/ChatCompletionMessage';
|
|
3
|
+
import { GeminiModel } from '@fencyai/js/lib/types/GeminiModel';
|
|
4
|
+
import { OpenAiModel } from '@fencyai/js/lib/types/OpenAiModel';
|
|
5
|
+
export interface CreateOpenAiChatCompletionParams {
|
|
6
|
+
model: OpenAiModel;
|
|
7
|
+
messages: Array<ChatCompletionMessage>;
|
|
8
|
+
temperature?: number;
|
|
9
|
+
topP?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateGeminiChatCompletionParams {
|
|
12
|
+
model: GeminiModel;
|
|
13
|
+
content: string;
|
|
14
|
+
temperature?: number;
|
|
15
|
+
topP?: number;
|
|
16
|
+
topK?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CreateAnthropicChatCompletionParams {
|
|
19
|
+
model: AnthropicModel;
|
|
20
|
+
messages: Array<ChatCompletionMessage>;
|
|
21
|
+
temperature?: number;
|
|
22
|
+
topP?: number;
|
|
23
|
+
topK?: number;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ChatCompletionStream
|
|
1
|
+
import { ChatCompletionStream } from '@fencyai/js';
|
|
2
2
|
import { ApiError } from '@fencyai/js/lib/types/ApiError';
|
|
3
3
|
import { FencyContext } from '../provider/FencyContext';
|
|
4
4
|
import { ChatCompletionChunk } from '../useEventSource';
|
|
5
|
+
import { CreateAnthropicChatCompletionParams, CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from './types';
|
|
5
6
|
export interface StreamingChatCompletionData {
|
|
6
7
|
id: string;
|
|
7
8
|
createdAt: string;
|
|
@@ -16,13 +17,14 @@ export interface StreamingChatCompletion {
|
|
|
16
17
|
loading: boolean;
|
|
17
18
|
doneStreaming: boolean;
|
|
18
19
|
}
|
|
20
|
+
export interface CreateStreamingChatCompletionParams {
|
|
21
|
+
openai?: CreateOpenAiChatCompletionParams;
|
|
22
|
+
gemini?: CreateGeminiChatCompletionParams;
|
|
23
|
+
anthropic?: CreateAnthropicChatCompletionParams;
|
|
24
|
+
}
|
|
19
25
|
export declare const useStreamingChatCompletions: (context: FencyContext) => {
|
|
20
26
|
chatCompletions: StreamingChatCompletion[];
|
|
21
|
-
createStreamingChatCompletion: (params: {
|
|
22
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
23
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
24
|
-
anthropic?: CreateAnthropicChatCompletionParams;
|
|
25
|
-
}) => Promise<{
|
|
27
|
+
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
26
28
|
type: "success";
|
|
27
29
|
chatCompletionStreamId: string;
|
|
28
30
|
chatCompletionId: string;
|
|
@@ -39,15 +39,12 @@ export const useStreamingChatCompletions = (context) => {
|
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
const newChatCompletions = [];
|
|
41
41
|
for (const chatCompletion of chatCompletions) {
|
|
42
|
-
console.log(chatCompletion.data?.id);
|
|
43
42
|
const relevantChunks = chunks
|
|
44
43
|
.filter((chunk) => chunk.chatCompletionId === chatCompletion.data?.id)
|
|
45
44
|
.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
46
|
-
console.log(relevantChunks);
|
|
47
45
|
const fullMessage = relevantChunks
|
|
48
46
|
.map((chunk) => chunk.content)
|
|
49
47
|
.join('');
|
|
50
|
-
console.log(fullMessage);
|
|
51
48
|
newChatCompletions.push({
|
|
52
49
|
data: chatCompletion.data
|
|
53
50
|
? {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from '@fencyai/js';
|
|
2
1
|
import { ApiError } from '@fencyai/js/lib/types/ApiError';
|
|
3
2
|
import { z, ZodTypeAny } from 'zod';
|
|
4
3
|
import { FencyContext } from '../provider/FencyContext';
|
|
4
|
+
import { CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from './types';
|
|
5
5
|
export interface StructuredChatCompletionData<T extends ZodTypeAny> {
|
|
6
6
|
id: string;
|
|
7
7
|
createdAt: string;
|
|
8
|
-
response:
|
|
8
|
+
response: object;
|
|
9
|
+
structuredResponse: z.infer<T>;
|
|
9
10
|
}
|
|
10
11
|
export interface StructuredChatCompletion<T extends ZodTypeAny> {
|
|
11
12
|
triggeredAt: string;
|
|
@@ -20,11 +21,12 @@ export type StructuredChatCompletionResponse<T extends ZodTypeAny> = {
|
|
|
20
21
|
type: 'error';
|
|
21
22
|
error: ApiError;
|
|
22
23
|
};
|
|
24
|
+
export interface CreateStructuredChatCompletionParams<T extends ZodTypeAny> {
|
|
25
|
+
openai?: CreateOpenAiChatCompletionParams;
|
|
26
|
+
gemini?: CreateGeminiChatCompletionParams;
|
|
27
|
+
responseFormat: T;
|
|
28
|
+
}
|
|
23
29
|
export declare const useStructuredChatCompletions: (context: FencyContext) => {
|
|
24
30
|
chatCompletions: StructuredChatCompletion<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>[];
|
|
25
|
-
createStructuredChatCompletion: <T extends ZodTypeAny>(params:
|
|
26
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
27
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
28
|
-
responseFormat: T;
|
|
29
|
-
}) => Promise<StructuredChatCompletionResponse<T>>;
|
|
31
|
+
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
30
32
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createChatCompletion
|
|
1
|
+
import { createChatCompletion } from '@fencyai/js';
|
|
2
2
|
import { useCallback, useState } from 'react';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export const useStructuredChatCompletions = (context) => {
|
|
@@ -42,6 +42,7 @@ export const useStructuredChatCompletions = (context) => {
|
|
|
42
42
|
id: response.completion.id,
|
|
43
43
|
createdAt: response.completion.createdAt,
|
|
44
44
|
response: params.responseFormat.parse(JSON.parse(response.completion.response)),
|
|
45
|
+
structuredResponse: params.responseFormat.parse(JSON.parse(response.completion.response)),
|
|
45
46
|
};
|
|
46
47
|
const structuredChatCompletion = {
|
|
47
48
|
triggeredAt,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CreateAnthropicChatCompletionParams, CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from '@fencyai/js';
|
|
2
1
|
import { ApiError } from '@fencyai/js/lib/types/ApiError';
|
|
3
2
|
import { FencyContext } from '../provider/FencyContext';
|
|
3
|
+
import { CreateAnthropicChatCompletionParams, CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from './types';
|
|
4
4
|
export interface SynchronousChatCompletionData {
|
|
5
5
|
id: string;
|
|
6
6
|
createdAt: string;
|
|
@@ -19,11 +19,12 @@ export type SynchronousChatCompletionResponse = {
|
|
|
19
19
|
type: 'error';
|
|
20
20
|
error: ApiError;
|
|
21
21
|
};
|
|
22
|
+
export interface CreateSynchronousChatCompletionParams {
|
|
23
|
+
openai?: CreateOpenAiChatCompletionParams;
|
|
24
|
+
gemini?: CreateGeminiChatCompletionParams;
|
|
25
|
+
anthropic?: CreateAnthropicChatCompletionParams;
|
|
26
|
+
}
|
|
22
27
|
export declare const useSynchronousChatCompletions: (context: FencyContext) => {
|
|
23
28
|
chatCompletions: SynchronousChatCompletion[];
|
|
24
|
-
createSynchronousChatCompletion: (params:
|
|
25
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
26
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
27
|
-
anthropic?: CreateAnthropicChatCompletionParams;
|
|
28
|
-
}) => Promise<SynchronousChatCompletionResponse>;
|
|
29
|
+
createSynchronousChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
|
29
30
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createChatCompletion
|
|
1
|
+
import { createChatCompletion } from '@fencyai/js';
|
|
2
2
|
import { useCallback, useState } from 'react';
|
|
3
3
|
export const useSynchronousChatCompletions = (context) => {
|
|
4
4
|
const [chatCompletions, setChatCompletions] = useState([]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "staklau <steinaageklaussen@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"zod": "^4.0.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@fencyai/js": "^0.1.
|
|
39
|
+
"@fencyai/js": "^0.1.41",
|
|
40
40
|
"@types/jest": "^29.5.11",
|
|
41
41
|
"@types/node": "^20.10.5",
|
|
42
42
|
"@types/react": "^18.2.45",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"typescript": "^5.3.3"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@fencyai/js": "^0.1.
|
|
48
|
+
"@fencyai/js": "^0.1.41",
|
|
49
49
|
"react": ">=16.8.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "cfe3e77d5266d35c1d39674bdcd2cb1888789b60"
|
|
52
52
|
}
|