@ahoo-wang/fetcher-openai 3.15.1 → 3.15.3
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 +36 -27
- package/README.zh-CN.md +7 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -298,9 +298,14 @@ interface ChatRequest {
|
|
|
298
298
|
// Response format
|
|
299
299
|
response_format?: object; // Response format specification
|
|
300
300
|
|
|
301
|
-
// Function calling
|
|
302
|
-
tools?:
|
|
303
|
-
|
|
301
|
+
// Function/Tool calling
|
|
302
|
+
// tools should be an array of tool objects: { type: "function", function: { name: string, description?: string, parameters?: object } }[]
|
|
303
|
+
// Note: The type definition uses string[] but OpenAI expects tool objects
|
|
304
|
+
tools?: string[];
|
|
305
|
+
// tool_choice supports: "auto", "none", or { type: "function", function: { name: string } }
|
|
306
|
+
tool_choice?: { [key: string]: any };
|
|
307
|
+
// Non-standard parameter (not part of OpenAI API) - likely for internal tracking
|
|
308
|
+
seen?: number;
|
|
304
309
|
|
|
305
310
|
// Other OpenAI parameters
|
|
306
311
|
[key: string]: any;
|
|
@@ -313,10 +318,11 @@ Represents a single message in the conversation.
|
|
|
313
318
|
|
|
314
319
|
```typescript
|
|
315
320
|
interface Message {
|
|
316
|
-
role: 'system' | 'user' | 'assistant' | '
|
|
317
|
-
content
|
|
318
|
-
name?: string; // For
|
|
319
|
-
|
|
321
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
322
|
+
content?: string;
|
|
323
|
+
name?: string; // For tool messages
|
|
324
|
+
tool_call_id?: string; // ID of the tool call (for tool role messages)
|
|
325
|
+
tool_calls?: Array<{ id: string; type: 'function'; function: { name: string; arguments: string } }>; // For assistant messages with tool calls
|
|
320
326
|
}
|
|
321
327
|
```
|
|
322
328
|
|
|
@@ -669,7 +675,7 @@ const openai = new OpenAI({
|
|
|
669
675
|
openai.fetcher = customFetcher;
|
|
670
676
|
```
|
|
671
677
|
|
|
672
|
-
### Function Calling
|
|
678
|
+
### Function/Tool Calling
|
|
673
679
|
|
|
674
680
|
```typescript
|
|
675
681
|
import { OpenAI } from '@ahoo-wang/fetcher-openai';
|
|
@@ -679,39 +685,42 @@ const openai = new OpenAI({
|
|
|
679
685
|
apiKey: process.env.OPENAI_API_KEY!,
|
|
680
686
|
});
|
|
681
687
|
|
|
682
|
-
// Define available
|
|
683
|
-
const
|
|
688
|
+
// Define available tools (use 'function' type for OpenAI compatibility)
|
|
689
|
+
const tools = [
|
|
684
690
|
{
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
691
|
+
type: 'function',
|
|
692
|
+
function: {
|
|
693
|
+
name: 'get_weather',
|
|
694
|
+
description: 'Get the current weather for a location',
|
|
695
|
+
parameters: {
|
|
696
|
+
type: 'object',
|
|
697
|
+
properties: {
|
|
698
|
+
location: {
|
|
699
|
+
type: 'string',
|
|
700
|
+
description: 'The city and state, e.g. San Francisco, CA',
|
|
701
|
+
},
|
|
693
702
|
},
|
|
703
|
+
required: ['location'],
|
|
694
704
|
},
|
|
695
|
-
required: ['location'],
|
|
696
705
|
},
|
|
697
706
|
},
|
|
698
707
|
];
|
|
699
708
|
|
|
700
|
-
// Make a request with
|
|
709
|
+
// Make a request with tool calling
|
|
701
710
|
const response = await openai.chat.completions({
|
|
702
711
|
model: 'gpt-4',
|
|
703
712
|
messages: [
|
|
704
713
|
{ role: 'user', content: "What's the weather like in San Francisco?" },
|
|
705
714
|
],
|
|
706
|
-
|
|
707
|
-
|
|
715
|
+
tools: tools,
|
|
716
|
+
tool_choice: 'auto', // Let the model decide when to call tools
|
|
708
717
|
});
|
|
709
718
|
|
|
710
|
-
// Handle
|
|
711
|
-
if (response.choices[0].message.
|
|
712
|
-
const
|
|
713
|
-
console.log('
|
|
714
|
-
console.log('Arguments:', JSON.parse(
|
|
719
|
+
// Handle tool calls
|
|
720
|
+
if (response.choices[0].message.tool_calls) {
|
|
721
|
+
const toolCall = response.choices[0].message.tool_calls[0];
|
|
722
|
+
console.log('Tool called:', toolCall.function.name);
|
|
723
|
+
console.log('Arguments:', JSON.parse(toolCall.function.arguments));
|
|
715
724
|
}
|
|
716
725
|
```
|
|
717
726
|
|
package/README.zh-CN.md
CHANGED
|
@@ -297,8 +297,13 @@ interface ChatRequest {
|
|
|
297
297
|
response_format?: object; // 响应格式规范
|
|
298
298
|
|
|
299
299
|
// 函数调用(测试版)
|
|
300
|
-
tools?:
|
|
301
|
-
|
|
300
|
+
// tools 应该是工具对象数组: { type: "function", function: { name: string, description?: string, parameters?: object } }[]
|
|
301
|
+
// 注意: 类型定义使用 string[] 但 OpenAI 期望工具对象
|
|
302
|
+
tools?: string[];
|
|
303
|
+
// tool_choice 支持: "auto", "none", 或 { type: "function", function: { name: string } }
|
|
304
|
+
tool_choice?: { [key: string]: any };
|
|
305
|
+
// 非标准参数(不属于 OpenAI API)- 可能用于内部跟踪
|
|
306
|
+
seen?: number;
|
|
302
307
|
|
|
303
308
|
// 其他 OpenAI 参数
|
|
304
309
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-openai",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.3",
|
|
4
4
|
"description": "Type-safe OpenAI API client for Fetcher ecosystem. Provides seamless integration with OpenAI's Chat Completions API, supporting both streaming and non-streaming responses with full TypeScript support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openai",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
"@vitest/coverage-v8": "^4.1.4",
|
|
57
57
|
"@vitest/ui": "^4.1.4",
|
|
58
58
|
"eslint": "^9.39.4",
|
|
59
|
-
"globals": "^17.
|
|
59
|
+
"globals": "^17.5.0",
|
|
60
60
|
"prettier": "^3.8.1",
|
|
61
61
|
"typescript": "^6.0.2",
|
|
62
|
-
"typescript-eslint": "^8.58.
|
|
62
|
+
"typescript-eslint": "^8.58.2",
|
|
63
63
|
"unplugin-dts": "1.0.0-beta.6",
|
|
64
64
|
"vite": "^8.0.8",
|
|
65
65
|
"vite-bundle-analyzer": "^1.3.7",
|
|
66
66
|
"vitest": "^4.1.4",
|
|
67
67
|
"msw": "^2.13.2",
|
|
68
|
-
"@ahoo-wang/fetcher-storage": "^3.15.
|
|
69
|
-
"@ahoo-wang/fetcher-
|
|
70
|
-
"@ahoo-wang/fetcher-
|
|
68
|
+
"@ahoo-wang/fetcher-storage": "^3.15.3",
|
|
69
|
+
"@ahoo-wang/fetcher-react": "^3.15.3",
|
|
70
|
+
"@ahoo-wang/fetcher-eventbus": "^3.15.3"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "vite build",
|