@positronic/client-anthropic 0.0.3 → 0.0.4
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/package.json +5 -1
- package/src/index.ts +0 -70
- package/tsconfig.json +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positronic/client-anthropic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"main": "dist/src/index.js",
|
|
10
10
|
"types": "dist/types/index.ts",
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"package.json"
|
|
15
|
+
],
|
|
12
16
|
"scripts": {
|
|
13
17
|
"tsc": "tsc --project tsconfig.json",
|
|
14
18
|
"swc": "swc src -d dist",
|
package/src/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { ObjectGenerator } from '@positronic/core';
|
|
2
|
-
import Instructor from '@instructor-ai/instructor';
|
|
3
|
-
import { createLLMClient } from 'llm-polyglot';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { config } from 'dotenv';
|
|
6
|
-
import type { InstructorClient } from '@instructor-ai/instructor';
|
|
7
|
-
|
|
8
|
-
config();
|
|
9
|
-
|
|
10
|
-
const anthropic = createLLMClient({
|
|
11
|
-
provider: 'anthropic',
|
|
12
|
-
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
13
|
-
defaultHeaders: {
|
|
14
|
-
'anthropic-beta': 'output-128k-2025-02-19',
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export class AnthropicClient implements ObjectGenerator {
|
|
19
|
-
private client: InstructorClient<typeof anthropic>;
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
this.client = Instructor({
|
|
23
|
-
client: anthropic,
|
|
24
|
-
mode: 'TOOLS',
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async generateObject<T extends z.AnyZodObject>(params: {
|
|
29
|
-
schema: T;
|
|
30
|
-
schemaName: string;
|
|
31
|
-
schemaDescription?: string;
|
|
32
|
-
prompt?: string;
|
|
33
|
-
messages?: { role: 'user' | 'assistant' | 'system'; content: string }[];
|
|
34
|
-
system?: string;
|
|
35
|
-
}): Promise<z.infer<T>> {
|
|
36
|
-
// Compose messages array according to the interface contract
|
|
37
|
-
let messages = params.messages ? [...params.messages] : [];
|
|
38
|
-
if (params.system) {
|
|
39
|
-
messages = [{ role: 'system', content: params.system }, ...messages];
|
|
40
|
-
}
|
|
41
|
-
if (params.prompt) {
|
|
42
|
-
messages = [...messages, { role: 'user', content: params.prompt }];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const model = 'claude-3-7-sonnet-latest';
|
|
46
|
-
const max_tokens = 64000;
|
|
47
|
-
const temperature = 0.5;
|
|
48
|
-
const top_p = 1;
|
|
49
|
-
const extra_options = {
|
|
50
|
-
thinking: {
|
|
51
|
-
type: 'enabled',
|
|
52
|
-
budget_tokens: max_tokens,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
const response = await this.client.chat.completions.create({
|
|
56
|
-
messages,
|
|
57
|
-
model,
|
|
58
|
-
response_model: {
|
|
59
|
-
schema: params.schema,
|
|
60
|
-
name: params.schemaName,
|
|
61
|
-
description: params.schemaDescription,
|
|
62
|
-
},
|
|
63
|
-
max_tokens,
|
|
64
|
-
...(temperature !== undefined ? { temperature } : {}),
|
|
65
|
-
...(top_p !== undefined ? { top_p } : {}),
|
|
66
|
-
extra_options,
|
|
67
|
-
});
|
|
68
|
-
return response;
|
|
69
|
-
}
|
|
70
|
-
}
|
package/tsconfig.json
DELETED