@fencyai/js 0.1.9 → 0.1.12
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/dist/api/createChatCompletion.js +1 -1
- package/dist/api/createChatCompletionStream.d.ts +15 -0
- package/dist/api/createChatCompletionStream.d.ts.map +1 -0
- package/dist/api/{createStream.js → createChatCompletionStream.js} +5 -5
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
- package/dist/api/createStream.d.ts +0 -15
- package/dist/api/createStream.d.ts.map +0 -1
|
@@ -9,7 +9,7 @@ import { isChatCompletion } from '../types.js';
|
|
|
9
9
|
* @throws Error if the request fails or the response is invalid
|
|
10
10
|
*/
|
|
11
11
|
export async function createChatCompletion(pk, streamId, options = {}) {
|
|
12
|
-
const apiUrl = options.apiUrl || 'http://localhost:8080/v1/
|
|
12
|
+
const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat_completions';
|
|
13
13
|
const requestBody = {
|
|
14
14
|
...options.request,
|
|
15
15
|
streamId, // always override with provided streamId
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatCompletionStream } from '../types.js';
|
|
2
|
+
export interface CreateChatCompletionStreamOptions {
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new stream by making a POST request to the Fency API.
|
|
8
|
+
*
|
|
9
|
+
* @param pk - The publishable key (used as Bearer token and default name)
|
|
10
|
+
* @param options - Optional configuration (apiUrl, name)
|
|
11
|
+
* @returns A promise that resolves to a ChatCompletionStream
|
|
12
|
+
* @throws Error if the request fails or the response is invalid
|
|
13
|
+
*/
|
|
14
|
+
export declare function createChatCompletionStream(pk: string, options?: CreateChatCompletionStreamOptions): Promise<ChatCompletionStream>;
|
|
15
|
+
//# sourceMappingURL=createChatCompletionStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createChatCompletionStream.d.ts","sourceRoot":"","sources":["../../src/api/createChatCompletionStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,MAAM,aAAa,CAAC;AAE3E,MAAM,WAAW,iCAAiC;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,iCAAsC,GAC9C,OAAO,CAAC,oBAAoB,CAAC,CAsB/B"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isChatCompletionStream } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a new stream by making a POST request to the Fency API.
|
|
4
4
|
*
|
|
5
5
|
* @param pk - The publishable key (used as Bearer token and default name)
|
|
6
6
|
* @param options - Optional configuration (apiUrl, name)
|
|
7
|
-
* @returns A promise that resolves to a
|
|
7
|
+
* @returns A promise that resolves to a ChatCompletionStream
|
|
8
8
|
* @throws Error if the request fails or the response is invalid
|
|
9
9
|
*/
|
|
10
|
-
export async function
|
|
11
|
-
const apiUrl = options.apiUrl || 'http://localhost:8080/v1/
|
|
10
|
+
export async function createChatCompletionStream(pk, options = {}) {
|
|
11
|
+
const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat_completion_streams';
|
|
12
12
|
const name = options.name || pk;
|
|
13
13
|
const response = await fetch(apiUrl, {
|
|
14
14
|
method: 'POST',
|
|
@@ -22,7 +22,7 @@ export async function createStream(pk, options = {}) {
|
|
|
22
22
|
throw new Error(`Failed to create stream: ${response.status} ${response.statusText}`);
|
|
23
23
|
}
|
|
24
24
|
const stream = await response.json();
|
|
25
|
-
if (!
|
|
25
|
+
if (!isChatCompletionStream(stream)) {
|
|
26
26
|
throw new Error('Invalid stream response');
|
|
27
27
|
}
|
|
28
28
|
return stream;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
|
|
2
1
|
import { createChatCompletion } from './api/createChatCompletion.js';
|
|
3
|
-
import {
|
|
2
|
+
import { createChatCompletionStream } from './api/createChatCompletionStream.js';
|
|
3
|
+
import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
|
|
4
4
|
import { loadFency } from './loadFency.js';
|
|
5
|
-
export type {
|
|
6
|
-
export { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
|
|
5
|
+
export type { ChatCompletion, ChatCompletionStream, FencyAvailabilityInfo, FencyInstance, FencyOptions } from './types.js';
|
|
7
6
|
export { createChatCompletion } from './api/createChatCompletion.js';
|
|
8
7
|
export type { CreateChatCompletionOptions } from './api/createChatCompletion.js';
|
|
9
|
-
export {
|
|
10
|
-
export type {
|
|
8
|
+
export { createChatCompletionStream } from './api/createChatCompletionStream.js';
|
|
9
|
+
export type { CreateChatCompletionStreamOptions } from './api/createChatCompletionStream.js';
|
|
10
|
+
export { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
|
|
11
11
|
export { loadFency } from './loadFency.js';
|
|
12
12
|
declare const _default: {
|
|
13
13
|
loadFency: typeof loadFency;
|
|
14
14
|
isFencyAvailable: typeof isFencyAvailable;
|
|
15
15
|
getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
|
|
16
|
-
createStream: typeof createStream;
|
|
17
16
|
createChatCompletion: typeof createChatCompletion;
|
|
17
|
+
createChatCompletionStream: typeof createChatCompletionStream;
|
|
18
18
|
};
|
|
19
19
|
export default _default;
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG3H,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,YAAY,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,YAAY,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EACL,wBAAwB,EAAE,gBAAgB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;;;;;;;AAG3C,wBAME"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var f=t=>typeof t=="object"&&t!==null&&"id"in t,C=t=>typeof t=="object"&&t!==null&&"id"in t;async function a(t,o,e={}){let n=e.apiUrl||"http://localhost:8080/v1/chat_completions",i={...e.request,streamId:o,openai:{model:"gpt-4o-mini",messages:[{role:"user",content:"Hello, how are you?"}],...e.request?.openai}},r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(i)});if(!r.ok)throw new Error(`Failed to create chat completion: ${r.status} ${r.statusText}`);let m=await r.json();if(!C(m))throw new Error("Invalid chat completion response");return m}async function s(t,o={}){let e=o.apiUrl||"http://localhost:8080/v1/chat_completion_streams",n=o.name||t,i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({name:n})});if(!i.ok)throw new Error(`Failed to create stream: ${i.status} ${i.statusText}`);let r=await i.json();if(!f(r))throw new Error("Invalid stream response");return r}function p(){if(typeof window>"u")return!1;let t=["fetch","Promise","JSON"];for(let o of t)if(typeof window[o]>"u")return!1;if(typeof window.location<"u"){let o=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",e=window.location.protocol==="https:";!o&&!e&&console.warn("Fency: For security, we recommend using HTTPS in production.")}return!0}function l(){let t={available:!0,missing:[],warnings:[]};if(typeof window>"u")return t.available=!1,t.missing.push("Browser environment"),t;let o=["fetch","Promise","JSON"];for(let e of o)typeof window[e]>"u"&&(t.available=!1,t.missing.push(`${e} API`));if(typeof window.location<"u"){let e=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",n=window.location.protocol==="https:";!e&&!n&&t.warnings.push("HTTPS is recommended for production use")}return t}function c(t,o={}){return new Promise((e,n)=>{if(!t||typeof t!="string"){n(new Error("Fency: A valid publishable key is required."));return}if(!t.startsWith("pk_")){n(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));return}let i={publishableKey:t,endpoint:o.endpoint||"https://api.fency.ai"};setTimeout(()=>{e(i)},0)})}var P={loadFency:c,isFencyAvailable:p,getFencyAvailabilityInfo:l,createChatCompletion:a,createChatCompletionStream:s};export{a as createChatCompletion,s as createChatCompletionStream,P as default,l as getFencyAvailabilityInfo,p as isFencyAvailable,c as loadFency};
|
package/dist/types.d.ts
CHANGED
|
@@ -26,10 +26,10 @@ export interface FencyAvailabilityInfo {
|
|
|
26
26
|
/** List of warnings */
|
|
27
27
|
warnings: string[];
|
|
28
28
|
}
|
|
29
|
-
export interface
|
|
29
|
+
export interface ChatCompletionStream {
|
|
30
30
|
id: string;
|
|
31
31
|
}
|
|
32
|
-
export declare const
|
|
32
|
+
export declare const isChatCompletionStream: (data: any) => data is ChatCompletionStream;
|
|
33
33
|
export type OpenAiModel = 'gpt-4o' | 'gpt-4o-mini' | 'gpt-3.5-turbo';
|
|
34
34
|
export interface CreateChatCompletionRequest {
|
|
35
35
|
streamId: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,uBAAuB;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,uBAAuB;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,sBAAsB,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,oBAE1D,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAA;AAEpE,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE;QACN,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC,CAAC;KACJ,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,cAEpD,CAAA"}
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Stream } from '../types.js';
|
|
2
|
-
export interface CreateStreamOptions {
|
|
3
|
-
apiUrl?: string;
|
|
4
|
-
name?: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new stream by making a POST request to the Fency API.
|
|
8
|
-
*
|
|
9
|
-
* @param pk - The publishable key (used as Bearer token and default name)
|
|
10
|
-
* @param options - Optional configuration (apiUrl, name)
|
|
11
|
-
* @returns A promise that resolves to a Stream
|
|
12
|
-
* @throws Error if the request fails or the response is invalid
|
|
13
|
-
*/
|
|
14
|
-
export declare function createStream(pk: string, options?: CreateStreamOptions): Promise<Stream>;
|
|
15
|
-
//# sourceMappingURL=createStream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createStream.d.ts","sourceRoot":"","sources":["../../src/api/createStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,MAAM,CAAC,CAsBjB"}
|