xsai 0.0.3 → 0.0.5

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/index.d.ts CHANGED
@@ -2,13 +2,14 @@ type GenerationModel = 'gemma2' | 'llama3.1' | 'llama3.2' | 'llama3.2-vision' |
2
2
  type EmbedModel = 'all-minilm' | 'mxbai-embed-large' | 'nomic-embed-text' | ({} & string);
3
3
 
4
4
  interface CommonRequestOptions {
5
- /**
6
- * @default `http://localhost:11434/v1`
7
- */
5
+ /** @default `http://localhost:11434/v1` */
8
6
  base?: string;
7
+ /** @default `undefined` */
8
+ headers?: Headers | Record<string, string>;
9
9
  }
10
10
 
11
11
  interface EmbedOptions extends CommonRequestOptions {
12
+ [key: string]: unknown;
12
13
  input: string | string[];
13
14
  model: EmbedModel;
14
15
  /** @default `embeddings` */
@@ -22,7 +23,7 @@ interface EmbedResult {
22
23
  embedding: number[];
23
24
  request: Request;
24
25
  response: Response;
25
- usage?: EmbedResponseUsage;
26
+ usage: EmbedResponseUsage;
26
27
  }
27
28
  declare const embed: (options: EmbedOptions) => Promise<{
28
29
  embedding: number[];
@@ -31,22 +32,31 @@ declare const embed: (options: EmbedOptions) => Promise<{
31
32
  usage: EmbedResponseUsage;
32
33
  }>;
33
34
 
35
+ type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | ({} & string);
36
+
34
37
  interface Message {
35
38
  content: string;
36
39
  role: 'assistant' | 'system' | 'user' | ({} & string);
37
40
  }
38
41
 
39
42
  interface GenerateTextOptions extends CommonRequestOptions {
40
- messages?: Message[];
43
+ [key: string]: unknown;
44
+ messages: Message[];
41
45
  model: GenerationModel;
42
- /** @default `completions` */
43
- path?: 'completions' | ({} & string);
44
- prompt: string;
46
+ /** @default `chat/completions` */
47
+ path?: 'chat/completions' | ({} & string);
48
+ }
49
+ interface GenerateTextResponseUsage {
50
+ completion_tokens: number;
51
+ prompt_tokens: number;
52
+ total_tokens: number;
45
53
  }
46
54
  interface GenerateTextResult {
55
+ finishReason: FinishReason;
47
56
  request: Request;
48
57
  response: Response;
49
58
  text: string;
59
+ usage: GenerateTextResponseUsage;
50
60
  }
51
61
  declare const generateText: (options: GenerateTextOptions) => Promise<GenerateTextResult>;
52
62
 
package/dist/index.js CHANGED
@@ -7,8 +7,13 @@ const embed = async (options) => {
7
7
  body: JSON.stringify(clean({
8
8
  ...options,
9
9
  base: void 0,
10
+ headers: void 0,
10
11
  path: void 0
11
12
  })),
13
+ headers: {
14
+ "Content-Type": "application/json",
15
+ ...options.headers
16
+ },
12
17
  method: "POST"
13
18
  });
14
19
  const response = await fetch(request);
@@ -22,21 +27,28 @@ const embed = async (options) => {
22
27
  };
23
28
 
24
29
  const generateText = async (options) => {
25
- const request = new Request(new URL(options.path ?? "completions", options.base ?? base), {
30
+ const request = new Request(new URL(options.path ?? "chat/completions", options.base ?? base), {
26
31
  body: JSON.stringify(clean({
27
- stream: false,
28
32
  ...options,
29
33
  base: void 0,
30
- path: void 0
34
+ headers: void 0,
35
+ path: void 0,
36
+ stream: false
31
37
  })),
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ ...options.headers
41
+ },
32
42
  method: "POST"
33
43
  });
34
44
  const response = await fetch(request);
35
45
  const json = await response.json();
36
46
  return {
47
+ finishReason: json.choices[0].finish_reason,
37
48
  request,
38
49
  response,
39
- text: json.choices[0].text
50
+ text: json.choices[0].message.content,
51
+ usage: json.usage
40
52
  };
41
53
  };
42
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xsai",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "author": "藍+85CD",
6
6
  "license": "MIT",