@nickyzj2023/ai 1.7.5 → 1.7.7
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 +137 -104
- package/dist/cli.mjs +9 -2
- package/dist/index.d.mts +348 -6
- package/dist/index.mjs +1 -1
- package/dist/tools/mcp.d.mts +49 -9
- package/dist/tools/mcp.mjs +1 -1
- package/package.json +7 -26
- package/dist/agent.d.mts +0 -15
- package/dist/agent.mjs +0 -1
- package/dist/interfaces/setup.mjs +0 -2
- package/dist/interfaces/tui.mjs +0 -6
- package/dist/llm.d.mts +0 -18
- package/dist/llm.mjs +0 -1
- package/dist/tools/get-time.d.mts +0 -5
- package/dist/tools/get-time.mjs +0 -1
- package/dist/tools/get-weather.d.mts +0 -5
- package/dist/tools/get-weather.mjs +0 -1
- package/dist/tools/index.d.mts +0 -3
- package/dist/tools/index.mjs +0 -1
- package/dist/types.d.mts +0 -194
- package/dist/utils/clipboard.mjs +0 -1
- package/dist/utils/compact/helper.mjs +0 -1
- package/dist/utils/compact/index.d.mts +0 -15
- package/dist/utils/compact/index.mjs +0 -1
- package/dist/utils/compact/strategy.d.mts +0 -25
- package/dist/utils/compact/strategy.mjs +0 -1
- package/dist/utils/compact/types.d.mts +0 -78
- package/dist/utils/config.mjs +0 -1
- package/dist/utils/helper.d.mts +0 -30
- package/dist/utils/helper.mjs +0 -1
- package/dist/utils/internalHelper.mjs +0 -1
package/dist/utils/helper.d.mts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Message, Model, ToolDefinition } from "../types.mjs";
|
|
2
|
-
//#region src/utils/helper.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* 辅助定义一个POST /chat/completions支持的model参数
|
|
5
|
-
* @remarks 只有baseUrl字段是必须的
|
|
6
|
-
*/
|
|
7
|
-
declare const defineModel: (config: Model) => Model;
|
|
8
|
-
/**
|
|
9
|
-
* 辅助定义一个POST /chat/completions支持的tool对象
|
|
10
|
-
* @param execute 实际执行工具的函数
|
|
11
|
-
*/
|
|
12
|
-
declare const defineTool: (name: ToolDefinition["function"]["name"], description: ToolDefinition["function"]["description"], properties: ToolDefinition["function"]["parameters"]["properties"], execute: ToolDefinition["execute"]) => ToolDefinition;
|
|
13
|
-
declare const estimateTextTokens: (text: string) => number;
|
|
14
|
-
/**
|
|
15
|
-
* 列出GET /models返回的模型id
|
|
16
|
-
* @param baseUrl 接口前缀,如http://127.0.0.1:11434/v1
|
|
17
|
-
* @param apiKey 本地llama.cpp等不校验鉴权的服务可以不传,不传就不带Authorization头
|
|
18
|
-
* @returns 模型的id列表
|
|
19
|
-
* @remarks 请求失败(服务没起、鉴权不过等)会抛异常,由调用方自行兜底
|
|
20
|
-
*/
|
|
21
|
-
declare const listModels: (baseUrl: string, apiKey?: string) => Promise<string[]>;
|
|
22
|
-
/**
|
|
23
|
-
* 根据上下文里的中/英文/多模态消息,估算出可能消耗的token
|
|
24
|
-
* - 单词 ≈ 1.5token
|
|
25
|
-
* - 标点/空白等非词字符每4个 ≈ 1token
|
|
26
|
-
* - 图片/音频/视频/文件 ≈ 4096token(不好估算,取个较大的值)
|
|
27
|
-
*/
|
|
28
|
-
declare const estimateTokens: (messages?: Message[]) => number;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { defineModel, defineTool, estimateTextTokens, estimateTokens, listModels };
|
package/dist/utils/helper.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{fetcher as e}from"@nickyzj2023/utils";const t=e=>({modalities:[`text`],context:131072,...e}),n=(e,t,n,r)=>{let i=[];return{type:`function`,function:{name:e,description:t,parameters:{type:`object`,properties:Object.entries(n).reduce((e,[t,n])=>(`required`in n&&(i.push(t),delete n.required),e[t]=n,e),{}),required:i}},execute:r}},r=new Intl.Segmenter([],{granularity:`word`}),i=e=>{let t=0,n=0;for(let i of r.segment(e))i.isWordLike?t++:n++;return Math.ceil(t*1.5+n/4)},a=async(t,n)=>{let{data:r}=await e(t,{headers:n?{Authorization:`Bearer ${n}`}:void 0}).get(`/models`);return(r??[]).map(e=>e.id).filter(e=>typeof e==`string`)},o=e=>e?.length?e.reduce((e,t)=>{let{content:n,tool_calls:r,...a}=t;if(typeof n==`string`)e+=i(n);else for(let t of n)t.type===`text`?e+=i(t.text):e+=4096;return r&&(e+=i(JSON.stringify(r))),e+=i(JSON.stringify(a)),e},0):0;export{t as defineModel,n as defineTool,i as estimateTextTokens,o as estimateTokens,a as listModels};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{estimateTextTokens as e,estimateTokens as t}from"./helper.mjs";const n=({id:e,function:t,...n})=>({...n,type:`tool_call`,id:e,name:t.name,args:t.arguments}),r=({id:e,name:t,args:n,...r})=>({...r,id:e,type:`function`,function:{name:t,arguments:n}}),i=new Intl.NumberFormat(`en-US`,{notation:`compact`,maximumFractionDigits:1}),a=e=>i.format(e),o=(n,r,i)=>{let a=t(n.slice(-1)),o=e(r+i);return{prompt_tokens:a,completion_tokens:o,total_tokens:t(n)+a+o}},s=(e,t)=>(e.speed=Math.floor(e.completion_tokens/((Date.now()-t)/1e3)),e);export{o as estimateFallbackUsage,a as humanizeNumber,r as toToolCall,n as toToolCallEvent,s as withSpeed};
|