Skip to content

Commit 6d6cb89

Browse files
committed
test(llm-tool): add complex structured tool test
1 parent d38f9a7 commit 6d6cb89

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/llm-tool.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GoogleGenAI } from '@google/genai';
77
import { GoogleGenerativeAI } from '@google/generative-ai';
88
import OpenAI from 'openai';
99

10+
import { GameCharacterV2 } from './fixture/complex-class.tool.dto';
1011
import {
1112
ToolMeta,
1213
ToolProp,
@@ -103,6 +104,41 @@ describe('LLM Tool Call and Structured Output Tests', () => {
103104
expect(data.name).toBeDefined();
104105
});
105106

107+
it('OpenAI (Chat Completions API) - Function calling with direct class conversion, with complex structured tool setup', async () => {
108+
const userMessage = `You are a helpful AI assistant. Based on the following JSON schema for a game character, please generate a mock response that follows the schema exactly. Make the data realistic and consistent with a game character context.
109+
`;
110+
const expGameCharV2Tool = classToOpenAITool(GameCharacterV2);
111+
112+
const completion = await openai.chat.completions.create({
113+
model: 'gpt-4o-mini',
114+
messages: [
115+
{
116+
role: 'user',
117+
content: userMessage,
118+
},
119+
],
120+
tools: [expGameCharV2Tool],
121+
tool_choice: 'required',
122+
});
123+
124+
const data3: GameCharacterV2 = JSON.parse(
125+
completion.choices[0].message?.tool_calls[0].function.arguments,
126+
);
127+
expect(data3.location).toBeDefined();
128+
expect(data3.location.city).toBeDefined();
129+
expect(data3.location.country).toBeDefined();
130+
expect(data3.banks[0].account).toBeDefined();
131+
expect(data3.banks[0].bankName).toBeDefined();
132+
expect(data3.level).toBeDefined();
133+
expect(data3.name).toBeDefined();
134+
expect(data3.rank).toBeDefined();
135+
expect(data3.status).toBeDefined();
136+
expect(data3.location).toBeDefined();
137+
expect(data3.titles[0]).toBeDefined();
138+
expect(data3.scores[0]).toBeGreaterThan(0);
139+
expect(data3.availableStatuses[0]).toBeDefined();
140+
});
141+
106142
it('OpenAI (Chat Completions API) - Structured output with response_format', async () => {
107143
const responseFormat = classToOpenAIResponseFormatJsonSchema(CapitalTool, {
108144
// Enable structured output for OpenAI

0 commit comments

Comments
 (0)