Skip to content

Commit b42fc9d

Browse files
committed
fix openai structured format name
1 parent 58c1eff commit b42fc9d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/Providers/OpenAI/HandleStructured.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@
88

99
trait HandleStructured
1010
{
11-
protected function sanitizeClassName(string $name): string
12-
{
13-
// Remove anonymous class markers and special characters
14-
$name = \preg_replace('/class@anonymous.*$/', 'anonymous', $name);
15-
// Replace any non-alphanumeric characters with underscore
16-
$name = \preg_replace('/[^a-zA-Z0-9_-]/', '_', $name);
17-
// Ensure it starts with a letter
18-
if (\preg_match('/^[^a-zA-Z]/', $name)) {
19-
$name = 'class_' . $name;
20-
}
21-
return $name;
22-
}
23-
2411
public function structured(
2512
array $messages,
2613
string $class,
@@ -42,4 +29,17 @@ public function structured(
4229

4330
return $this->chat($messages);
4431
}
32+
33+
protected function sanitizeClassName(string $name): string
34+
{
35+
// Remove anonymous class markers and special characters
36+
$name = \preg_replace('/class@anonymous.*$/', 'anonymous', $name);
37+
// Replace any non-alphanumeric characters with underscore
38+
$name = \preg_replace('/[^a-zA-Z0-9_-]/', '_', (string) $name);
39+
// Ensure it starts with a letter
40+
if (\preg_match('/^[^a-zA-Z]/', (string) $name)) {
41+
return 'class_' . $name;
42+
}
43+
return $name;
44+
}
4545
}

0 commit comments

Comments
 (0)