qualifire 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -18,33 +18,24 @@ npm install my-package-name
18
18
  ## Usage
19
19
 
20
20
  ```ts
21
- import { myPackage } from 'my-package-name';
22
-
23
- myPackage('hello');
24
- //=> 'hello from my package'
21
+ import * as qualifire from 'qualifire';
22
+
23
+ const qualifireClient = qualifire.getClient('#YOUR-SDK-KEY#');
24
+
25
+ const prompt = await qualifireClient.getValueAsync(
26
+ 'isMyAwesomeFeatureEnabled',
27
+ {
28
+ var1: 'val1',
29
+ var2: 'val2',
30
+ }
31
+ );
32
+
33
+ const chatCompletion = await openai.createChatCompletion({
34
+ model: 'gpt-3.5-turbo',
35
+ messages: [{ role: 'user', content: prompt }],
36
+ });
25
37
  ```
26
38
 
27
- ## API
28
-
29
- ### myPackage(input, options?)
30
-
31
- #### input
32
-
33
- Type: `string`
34
-
35
- Lorem ipsum.
36
-
37
- #### options
38
-
39
- Type: `object`
40
-
41
- ##### postfix
42
-
43
- Type: `string`
44
- Default: `rainbows`
45
-
46
- Lorem ipsum.
47
-
48
39
  [build-img]: https://github.com/drorivry/develop/qualifire-typescript-sdk/actions/workflows/release.yml/badge.svg
49
40
  [build-url]: https://github.com/drorivry/qualifire-typescript-sdk/actions/workflows/release.yml
50
41
  [downloads-img]: https://img.shields.io/npm/dt/main/qualifire
package/lib/index.d.ts CHANGED
@@ -1 +1,8 @@
1
- export declare const myPackage: (taco?: string) => string;
1
+ export declare function getClient(sdkKey?: string, qualifireBaseUrl?: string): QualifireClient;
2
+ declare class QualifireClient {
3
+ sdkKey: string;
4
+ baseUrl: string;
5
+ constructor(key: string, baseUrl: string);
6
+ getValueAsync(promptId: string, templateValues?: Record<string, string>, defaultValue?: string | null): Promise<string | null>;
7
+ }
8
+ export {};
package/lib/index.js CHANGED
@@ -1,5 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.myPackage = void 0;
4
- const myPackage = (taco = '') => `${taco} from my package`;
5
- exports.myPackage = myPackage;
3
+ exports.getClient = void 0;
4
+ function getClient(sdkKey, qualifireBaseUrl) {
5
+ const key = sdkKey || process.env.QUALIFIRE_SDK_KEY;
6
+ const baseUrl = qualifireBaseUrl ||
7
+ process.env.QUALIFIRE_BASE_URL ||
8
+ 'https://app.qualifire.xyz';
9
+ if (!key) {
10
+ throw new Error('Missing SDK key, please provide an arg or add the QUALIFIRE_SDK_KEY environment variable.');
11
+ }
12
+ return new QualifireClient(key, baseUrl);
13
+ }
14
+ exports.getClient = getClient;
15
+ class QualifireClient {
16
+ constructor(key, baseUrl) {
17
+ this.sdkKey = key;
18
+ this.baseUrl = baseUrl;
19
+ }
20
+ async getValueAsync(promptId, templateValues, defaultValue = null) {
21
+ const qualifireResponse = await fetch(`${this.baseUrl}/api/studio/prompt?${new URLSearchParams({
22
+ promptId,
23
+ }).toString()}`, {
24
+ headers: new Headers({
25
+ Authorization: 'Bearer ' + this.sdkKey,
26
+ }),
27
+ });
28
+ if (!qualifireResponse.ok) {
29
+ console.error('error while getting the prompt', qualifireResponse.json());
30
+ return defaultValue;
31
+ }
32
+ const { prompt, templateVariables } = (await qualifireResponse.json());
33
+ let parsedPrompt = prompt;
34
+ if (templateValues && templateVariables) {
35
+ for (const variable of templateVariables) {
36
+ parsedPrompt = parsedPrompt.replaceAll(`{${variable}}`, templateValues[variable] || '');
37
+ }
38
+ return parsedPrompt;
39
+ }
40
+ return defaultValue;
41
+ }
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qualifire",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Qualifire client SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -58,7 +58,7 @@
58
58
  "semantic-release": "^21.0.1",
59
59
  "ts-jest": "^27.0.5",
60
60
  "ts-node": "^10.2.1",
61
- "typescript": "^4.2.4"
61
+ "typescript": "^5.1.6"
62
62
  },
63
63
  "config": {
64
64
  "commitizen": {