@kood/claude-code 0.1.6 → 0.1.9
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/dist/index.js +109 -216
- package/package.json +8 -2
- package/templates/hono/CLAUDE.md +59 -328
- package/templates/hono/docs/architecture/architecture.md +93 -747
- package/templates/hono/docs/deployment/cloudflare.md +59 -513
- package/templates/hono/docs/deployment/docker.md +41 -356
- package/templates/hono/docs/deployment/index.md +54 -190
- package/templates/hono/docs/deployment/railway.md +36 -306
- package/templates/hono/docs/deployment/vercel.md +49 -434
- package/templates/hono/docs/library/ai-sdk/index.md +53 -290
- package/templates/hono/docs/library/ai-sdk/openrouter.md +19 -387
- package/templates/hono/docs/library/ai-sdk/providers.md +28 -394
- package/templates/hono/docs/library/ai-sdk/streaming.md +52 -353
- package/templates/hono/docs/library/ai-sdk/structured-output.md +63 -395
- package/templates/hono/docs/library/ai-sdk/tools.md +62 -431
- package/templates/hono/docs/library/hono/env-setup.md +24 -313
- package/templates/hono/docs/library/hono/error-handling.md +34 -295
- package/templates/hono/docs/library/hono/index.md +29 -121
- package/templates/hono/docs/library/hono/middleware.md +21 -188
- package/templates/hono/docs/library/hono/rpc.md +40 -341
- package/templates/hono/docs/library/hono/validation.md +35 -195
- package/templates/hono/docs/library/pino/index.md +42 -333
- package/templates/hono/docs/library/prisma/cloudflare-d1.md +64 -367
- package/templates/hono/docs/library/prisma/config.md +19 -260
- package/templates/hono/docs/library/prisma/index.md +67 -320
- package/templates/hono/docs/library/zod/index.md +53 -257
- package/templates/npx/CLAUDE.md +62 -274
- package/templates/npx/docs/references/patterns.md +160 -0
- package/templates/tanstack-start/CLAUDE.md +100 -256
- package/templates/tanstack-start/docs/architecture/architecture.md +44 -589
- package/templates/tanstack-start/docs/deployment/cloudflare.md +37 -424
- package/templates/tanstack-start/docs/deployment/index.md +57 -286
- package/templates/tanstack-start/docs/deployment/nitro.md +36 -318
- package/templates/tanstack-start/docs/deployment/railway.md +40 -409
- package/templates/tanstack-start/docs/deployment/vercel.md +43 -465
- package/templates/tanstack-start/docs/design/components.md +77 -311
- package/templates/tanstack-start/docs/design/index.md +113 -69
- package/templates/tanstack-start/docs/design/safe-area.md +51 -250
- package/templates/tanstack-start/docs/design/tailwind-setup.md +45 -359
- package/templates/tanstack-start/docs/guides/conventions.md +103 -0
- package/templates/tanstack-start/docs/guides/env-setup.md +34 -340
- package/templates/tanstack-start/docs/guides/getting-started.md +22 -209
- package/templates/tanstack-start/docs/guides/hooks.md +166 -0
- package/templates/tanstack-start/docs/guides/routes.md +166 -0
- package/templates/tanstack-start/docs/guides/services.md +143 -0
- package/templates/tanstack-start/docs/library/better-auth/2fa.md +27 -115
- package/templates/tanstack-start/docs/library/better-auth/advanced.md +22 -105
- package/templates/tanstack-start/docs/library/better-auth/index.md +17 -66
- package/templates/tanstack-start/docs/library/better-auth/plugins.md +11 -88
- package/templates/tanstack-start/docs/library/better-auth/session.md +12 -92
- package/templates/tanstack-start/docs/library/better-auth/setup.md +9 -91
- package/templates/tanstack-start/docs/library/prisma/cloudflare-d1.md +30 -358
- package/templates/tanstack-start/docs/library/prisma/config.md +27 -327
- package/templates/tanstack-start/docs/library/prisma/crud.md +46 -174
- package/templates/tanstack-start/docs/library/prisma/index.md +23 -113
- package/templates/tanstack-start/docs/library/prisma/relations.md +31 -153
- package/templates/tanstack-start/docs/library/prisma/schema.md +40 -217
- package/templates/tanstack-start/docs/library/prisma/setup.md +12 -112
- package/templates/tanstack-start/docs/library/prisma/transactions.md +20 -110
- package/templates/tanstack-start/docs/library/tanstack-query/index.md +26 -97
- package/templates/tanstack-start/docs/library/tanstack-query/invalidation.md +28 -107
- package/templates/tanstack-start/docs/library/tanstack-query/optimistic-updates.md +44 -146
- package/templates/tanstack-start/docs/library/tanstack-query/use-mutation.md +33 -127
- package/templates/tanstack-start/docs/library/tanstack-query/use-query.md +49 -149
- package/templates/tanstack-start/docs/library/tanstack-start/auth-patterns.md +19 -112
- package/templates/tanstack-start/docs/library/tanstack-start/index.md +33 -80
- package/templates/tanstack-start/docs/library/tanstack-start/middleware.md +28 -106
- package/templates/tanstack-start/docs/library/tanstack-start/routing.md +21 -118
- package/templates/tanstack-start/docs/library/tanstack-start/server-functions.md +34 -246
- package/templates/tanstack-start/docs/library/tanstack-start/setup.md +6 -39
- package/templates/tanstack-start/docs/library/zod/complex-types.md +32 -156
- package/templates/tanstack-start/docs/library/zod/index.md +31 -144
- package/templates/tanstack-start/docs/library/zod/transforms.md +20 -129
- package/templates/tanstack-start/docs/library/zod/validation.md +39 -155
- package/templates/hono/docs/commands/git.md +0 -145
- package/templates/hono/docs/mcp/context7.md +0 -106
- package/templates/hono/docs/mcp/index.md +0 -176
- package/templates/hono/docs/mcp/sequential-thinking.md +0 -101
- package/templates/hono/docs/mcp/serena.md +0 -269
- package/templates/hono/docs/mcp/sgrep.md +0 -105
- package/templates/hono/docs/skills/gemini-review/SKILL.md +0 -220
- package/templates/hono/docs/skills/gemini-review/references/checklists.md +0 -136
- package/templates/hono/docs/skills/gemini-review/references/prompt-templates.md +0 -303
- package/templates/npx/docs/commands/git.md +0 -145
- package/templates/npx/docs/mcp/index.md +0 -60
- package/templates/npx/docs/skills/gemini-review/SKILL.md +0 -220
- package/templates/npx/docs/skills/gemini-review/references/checklists.md +0 -134
- package/templates/npx/docs/skills/gemini-review/references/prompt-templates.md +0 -301
- package/templates/tanstack-start/docs/commands/git.md +0 -145
- package/templates/tanstack-start/docs/design/accessibility.md +0 -433
- package/templates/tanstack-start/docs/design/color.md +0 -235
- package/templates/tanstack-start/docs/design/spacing.md +0 -341
- package/templates/tanstack-start/docs/design/typography.md +0 -324
- package/templates/tanstack-start/docs/guides/best-practices.md +0 -950
- package/templates/tanstack-start/docs/guides/husky-lint-staged.md +0 -303
- package/templates/tanstack-start/docs/guides/prettier.md +0 -189
- package/templates/tanstack-start/docs/guides/project-templates.md +0 -710
- package/templates/tanstack-start/docs/library/tanstack-query/setup.md +0 -107
- package/templates/tanstack-start/docs/library/zod/basic-types.md +0 -186
- package/templates/tanstack-start/docs/mcp/context7.md +0 -204
- package/templates/tanstack-start/docs/mcp/index.md +0 -177
- package/templates/tanstack-start/docs/mcp/sequential-thinking.md +0 -180
- package/templates/tanstack-start/docs/mcp/serena.md +0 -269
- package/templates/tanstack-start/docs/mcp/sgrep.md +0 -174
- package/templates/tanstack-start/docs/skills/gemini-review/SKILL.md +0 -220
- package/templates/tanstack-start/docs/skills/gemini-review/references/checklists.md +0 -144
- package/templates/tanstack-start/docs/skills/gemini-review/references/prompt-templates.md +0 -292
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
# AI SDK - 프로바이더
|
|
1
|
+
# AI SDK - 프로바이더
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 개요
|
|
8
|
-
|
|
9
|
-
AI SDK 프로바이더를 Hono와 함께 사용하는 방법입니다. Cloudflare Workers 환경에서의 설정을 포함합니다.
|
|
3
|
+
> 다양한 AI 프로바이더 설정
|
|
10
4
|
|
|
11
5
|
---
|
|
12
6
|
|
|
@@ -14,8 +8,8 @@ AI SDK 프로바이더를 Hono와 함께 사용하는 방법입니다. Cloudflar
|
|
|
14
8
|
|
|
15
9
|
```bash
|
|
16
10
|
npm install @ai-sdk/openai # OpenAI
|
|
17
|
-
npm install @ai-sdk/anthropic #
|
|
18
|
-
npm install @ai-sdk/google #
|
|
11
|
+
npm install @ai-sdk/anthropic # Claude
|
|
12
|
+
npm install @ai-sdk/google # Gemini
|
|
19
13
|
npm install @ai-sdk/mistral # Mistral
|
|
20
14
|
npm install @ai-sdk/groq # Groq
|
|
21
15
|
```
|
|
@@ -24,445 +18,85 @@ npm install @ai-sdk/groq # Groq
|
|
|
24
18
|
|
|
25
19
|
## OpenAI
|
|
26
20
|
|
|
27
|
-
### 기본 사용
|
|
28
|
-
|
|
29
21
|
```typescript
|
|
30
|
-
import { Hono } from 'hono'
|
|
31
|
-
import { streamText } from 'ai'
|
|
32
22
|
import { openai } from '@ai-sdk/openai'
|
|
33
23
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const { messages } = await c.req.json()
|
|
38
|
-
|
|
39
|
-
const result = streamText({
|
|
40
|
-
model: openai('gpt-4o'),
|
|
41
|
-
messages,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
return result.toUIMessageStreamResponse()
|
|
24
|
+
const result = streamText({
|
|
25
|
+
model: openai('gpt-4o'),
|
|
26
|
+
messages,
|
|
45
27
|
})
|
|
46
28
|
```
|
|
47
29
|
|
|
48
|
-
### Cloudflare Workers
|
|
30
|
+
### Cloudflare Workers
|
|
49
31
|
|
|
50
32
|
```typescript
|
|
51
|
-
import { Hono } from 'hono'
|
|
52
|
-
import { streamText } from 'ai'
|
|
53
33
|
import { createOpenAI } from '@ai-sdk/openai'
|
|
54
34
|
|
|
55
|
-
type Bindings = {
|
|
56
|
-
OPENAI_API_KEY: string
|
|
57
|
-
}
|
|
58
|
-
|
|
35
|
+
type Bindings = { OPENAI_API_KEY: string }
|
|
59
36
|
const app = new Hono<{ Bindings: Bindings }>()
|
|
60
37
|
|
|
61
38
|
app.post('/api/chat', async (c) => {
|
|
62
|
-
const openai = createOpenAI({
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const { messages } = await c.req.json()
|
|
67
|
-
|
|
68
|
-
const result = streamText({
|
|
69
|
-
model: openai('gpt-4o'),
|
|
70
|
-
messages,
|
|
71
|
-
})
|
|
72
|
-
|
|
39
|
+
const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY })
|
|
40
|
+
const result = streamText({ model: openai('gpt-4o'), messages })
|
|
73
41
|
return result.toUIMessageStreamResponse()
|
|
74
42
|
})
|
|
75
43
|
```
|
|
76
44
|
|
|
77
|
-
###
|
|
45
|
+
### 모델
|
|
78
46
|
|
|
79
47
|
| 모델 | 설명 |
|
|
80
48
|
|------|------|
|
|
81
|
-
| `gpt-4o` |
|
|
82
|
-
| `gpt-4o-mini` |
|
|
83
|
-
| `
|
|
84
|
-
| `o1` | 추론 최적화 모델 |
|
|
85
|
-
| `o1-mini` | 경량 추론 모델 |
|
|
49
|
+
| `gpt-4o` | GPT-4 Omni |
|
|
50
|
+
| `gpt-4o-mini` | 경량 GPT-4o |
|
|
51
|
+
| `o1` | 추론 최적화 |
|
|
86
52
|
|
|
87
53
|
---
|
|
88
54
|
|
|
89
55
|
## Anthropic (Claude)
|
|
90
56
|
|
|
91
|
-
### 기본 사용
|
|
92
|
-
|
|
93
57
|
```typescript
|
|
94
|
-
import { Hono } from 'hono'
|
|
95
|
-
import { streamText } from 'ai'
|
|
96
58
|
import { anthropic } from '@ai-sdk/anthropic'
|
|
97
59
|
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const { messages } = await c.req.json()
|
|
102
|
-
|
|
103
|
-
const result = streamText({
|
|
104
|
-
model: anthropic('claude-3-5-sonnet-20241022'),
|
|
105
|
-
messages,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
return result.toUIMessageStreamResponse()
|
|
109
|
-
})
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Cloudflare Workers 설정
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
import { Hono } from 'hono'
|
|
116
|
-
import { streamText } from 'ai'
|
|
117
|
-
import { createAnthropic } from '@ai-sdk/anthropic'
|
|
118
|
-
|
|
119
|
-
type Bindings = {
|
|
120
|
-
ANTHROPIC_API_KEY: string
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const app = new Hono<{ Bindings: Bindings }>()
|
|
124
|
-
|
|
125
|
-
app.post('/api/chat', async (c) => {
|
|
126
|
-
const anthropic = createAnthropic({
|
|
127
|
-
apiKey: c.env.ANTHROPIC_API_KEY,
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
const { messages } = await c.req.json()
|
|
131
|
-
|
|
132
|
-
const result = streamText({
|
|
133
|
-
model: anthropic('claude-3-5-sonnet-20241022'),
|
|
134
|
-
messages,
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
return result.toUIMessageStreamResponse()
|
|
60
|
+
const result = streamText({
|
|
61
|
+
model: anthropic('claude-3-5-sonnet-latest'),
|
|
62
|
+
messages,
|
|
138
63
|
})
|
|
139
64
|
```
|
|
140
65
|
|
|
141
|
-
###
|
|
66
|
+
### 모델
|
|
142
67
|
|
|
143
68
|
| 모델 | 설명 |
|
|
144
69
|
|------|------|
|
|
145
|
-
| `claude-3-5-sonnet-
|
|
146
|
-
| `claude-3-
|
|
147
|
-
| `claude-3-
|
|
70
|
+
| `claude-3-5-sonnet-latest` | Claude 3.5 Sonnet |
|
|
71
|
+
| `claude-3-opus-latest` | Claude 3 Opus |
|
|
72
|
+
| `claude-3-haiku-latest` | 경량 모델 |
|
|
148
73
|
|
|
149
74
|
---
|
|
150
75
|
|
|
151
76
|
## Google (Gemini)
|
|
152
77
|
|
|
153
|
-
### 기본 사용
|
|
154
|
-
|
|
155
78
|
```typescript
|
|
156
|
-
import { Hono } from 'hono'
|
|
157
|
-
import { streamText } from 'ai'
|
|
158
79
|
import { google } from '@ai-sdk/google'
|
|
159
80
|
|
|
160
|
-
const app = new Hono()
|
|
161
|
-
|
|
162
|
-
app.post('/api/chat', async (c) => {
|
|
163
|
-
const { messages } = await c.req.json()
|
|
164
|
-
|
|
165
|
-
const result = streamText({
|
|
166
|
-
model: google('gemini-1.5-pro'),
|
|
167
|
-
messages,
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
return result.toUIMessageStreamResponse()
|
|
171
|
-
})
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Cloudflare Workers 설정
|
|
175
|
-
|
|
176
|
-
```typescript
|
|
177
|
-
import { Hono } from 'hono'
|
|
178
|
-
import { streamText } from 'ai'
|
|
179
|
-
import { createGoogleGenerativeAI } from '@ai-sdk/google'
|
|
180
|
-
|
|
181
|
-
type Bindings = {
|
|
182
|
-
GOOGLE_GENERATIVE_AI_API_KEY: string
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const app = new Hono<{ Bindings: Bindings }>()
|
|
186
|
-
|
|
187
|
-
app.post('/api/chat', async (c) => {
|
|
188
|
-
const google = createGoogleGenerativeAI({
|
|
189
|
-
apiKey: c.env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
const { messages } = await c.req.json()
|
|
193
|
-
|
|
194
|
-
const result = streamText({
|
|
195
|
-
model: google('gemini-1.5-pro'),
|
|
196
|
-
messages,
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
return result.toUIMessageStreamResponse()
|
|
200
|
-
})
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### 사용 가능한 모델
|
|
204
|
-
|
|
205
|
-
| 모델 | 설명 |
|
|
206
|
-
|------|------|
|
|
207
|
-
| `gemini-1.5-pro` | Gemini 1.5 Pro |
|
|
208
|
-
| `gemini-1.5-flash` | Gemini 1.5 Flash (빠름) |
|
|
209
|
-
| `gemini-2.0-flash-exp` | Gemini 2.0 Flash (실험) |
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
## Groq
|
|
214
|
-
|
|
215
|
-
### 기본 사용
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
import { Hono } from 'hono'
|
|
219
|
-
import { streamText } from 'ai'
|
|
220
|
-
import { groq } from '@ai-sdk/groq'
|
|
221
|
-
|
|
222
|
-
const app = new Hono()
|
|
223
|
-
|
|
224
|
-
app.post('/api/chat', async (c) => {
|
|
225
|
-
const { messages } = await c.req.json()
|
|
226
|
-
|
|
227
|
-
const result = streamText({
|
|
228
|
-
model: groq('llama-3.1-70b-versatile'),
|
|
229
|
-
messages,
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
return result.toUIMessageStreamResponse()
|
|
233
|
-
})
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Cloudflare Workers 설정
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
import { Hono } from 'hono'
|
|
240
|
-
import { streamText } from 'ai'
|
|
241
|
-
import { createGroq } from '@ai-sdk/groq'
|
|
242
|
-
|
|
243
|
-
type Bindings = {
|
|
244
|
-
GROQ_API_KEY: string
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const app = new Hono<{ Bindings: Bindings }>()
|
|
248
|
-
|
|
249
|
-
app.post('/api/chat', async (c) => {
|
|
250
|
-
const groq = createGroq({
|
|
251
|
-
apiKey: c.env.GROQ_API_KEY,
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
const { messages } = await c.req.json()
|
|
255
|
-
|
|
256
|
-
const result = streamText({
|
|
257
|
-
model: groq('llama-3.1-70b-versatile'),
|
|
258
|
-
messages,
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
return result.toUIMessageStreamResponse()
|
|
262
|
-
})
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
---
|
|
266
|
-
|
|
267
|
-
## 다중 프로바이더 설정
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
import { Hono } from 'hono'
|
|
271
|
-
import { streamText } from 'ai'
|
|
272
|
-
import { createOpenAI } from '@ai-sdk/openai'
|
|
273
|
-
import { createAnthropic } from '@ai-sdk/anthropic'
|
|
274
|
-
import { createGoogleGenerativeAI } from '@ai-sdk/google'
|
|
275
|
-
|
|
276
|
-
type Bindings = {
|
|
277
|
-
OPENAI_API_KEY: string
|
|
278
|
-
ANTHROPIC_API_KEY: string
|
|
279
|
-
GOOGLE_GENERATIVE_AI_API_KEY: string
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const app = new Hono<{ Bindings: Bindings }>()
|
|
283
|
-
|
|
284
|
-
app.post('/api/chat/:provider', async (c) => {
|
|
285
|
-
const provider = c.req.param('provider')
|
|
286
|
-
const { messages } = await c.req.json()
|
|
287
|
-
|
|
288
|
-
let model
|
|
289
|
-
|
|
290
|
-
switch (provider) {
|
|
291
|
-
case 'openai':
|
|
292
|
-
const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY })
|
|
293
|
-
model = openai('gpt-4o')
|
|
294
|
-
break
|
|
295
|
-
case 'anthropic':
|
|
296
|
-
const anthropic = createAnthropic({ apiKey: c.env.ANTHROPIC_API_KEY })
|
|
297
|
-
model = anthropic('claude-3-5-sonnet-20241022')
|
|
298
|
-
break
|
|
299
|
-
case 'google':
|
|
300
|
-
const google = createGoogleGenerativeAI({
|
|
301
|
-
apiKey: c.env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
302
|
-
})
|
|
303
|
-
model = google('gemini-1.5-pro')
|
|
304
|
-
break
|
|
305
|
-
default:
|
|
306
|
-
return c.json({ error: 'Unknown provider' }, 400)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const result = streamText({ model, messages })
|
|
310
|
-
|
|
311
|
-
return result.toUIMessageStreamResponse()
|
|
312
|
-
})
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
---
|
|
316
|
-
|
|
317
|
-
## 프로바이더 미들웨어
|
|
318
|
-
|
|
319
|
-
```typescript
|
|
320
|
-
import { Hono } from 'hono'
|
|
321
|
-
import { createMiddleware } from 'hono/factory'
|
|
322
|
-
import { streamText } from 'ai'
|
|
323
|
-
import { createOpenAI } from '@ai-sdk/openai'
|
|
324
|
-
import { createAnthropic } from '@ai-sdk/anthropic'
|
|
325
|
-
|
|
326
|
-
type Bindings = {
|
|
327
|
-
OPENAI_API_KEY: string
|
|
328
|
-
ANTHROPIC_API_KEY: string
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
type Variables = {
|
|
332
|
-
providers: {
|
|
333
|
-
openai: ReturnType<typeof createOpenAI>
|
|
334
|
-
anthropic: ReturnType<typeof createAnthropic>
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const providersMiddleware = createMiddleware<{
|
|
339
|
-
Bindings: Bindings
|
|
340
|
-
Variables: Variables
|
|
341
|
-
}>(async (c, next) => {
|
|
342
|
-
c.set('providers', {
|
|
343
|
-
openai: createOpenAI({ apiKey: c.env.OPENAI_API_KEY }),
|
|
344
|
-
anthropic: createAnthropic({ apiKey: c.env.ANTHROPIC_API_KEY }),
|
|
345
|
-
})
|
|
346
|
-
await next()
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()
|
|
350
|
-
|
|
351
|
-
app.use('/api/*', providersMiddleware)
|
|
352
|
-
|
|
353
|
-
app.post('/api/chat', async (c) => {
|
|
354
|
-
const { messages, provider = 'openai' } = await c.req.json()
|
|
355
|
-
const providers = c.get('providers')
|
|
356
|
-
|
|
357
|
-
const model =
|
|
358
|
-
provider === 'anthropic'
|
|
359
|
-
? providers.anthropic('claude-3-5-sonnet-20241022')
|
|
360
|
-
: providers.openai('gpt-4o')
|
|
361
|
-
|
|
362
|
-
const result = streamText({ model, messages })
|
|
363
|
-
|
|
364
|
-
return result.toUIMessageStreamResponse()
|
|
365
|
-
})
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
---
|
|
369
|
-
|
|
370
|
-
## 모델 파라미터
|
|
371
|
-
|
|
372
|
-
```typescript
|
|
373
81
|
const result = streamText({
|
|
374
|
-
model:
|
|
82
|
+
model: google('gemini-1.5-pro'),
|
|
375
83
|
messages,
|
|
376
|
-
|
|
377
|
-
// 공통 파라미터
|
|
378
|
-
temperature: 0.7, // 창의성 (0-2)
|
|
379
|
-
maxTokens: 1000, // 최대 토큰 수
|
|
380
|
-
topP: 0.9, // 핵 샘플링
|
|
381
|
-
frequencyPenalty: 0.5, // 반복 억제
|
|
382
|
-
presencePenalty: 0.5, // 새로운 주제 유도
|
|
383
|
-
stopSequences: ['\n\n'], // 생성 중단 시퀀스
|
|
384
84
|
})
|
|
385
85
|
```
|
|
386
86
|
|
|
387
87
|
---
|
|
388
88
|
|
|
389
|
-
##
|
|
390
|
-
|
|
391
|
-
하나의 API 키로 수백 개 모델에 접근할 수 있는 통합 게이트웨이입니다.
|
|
392
|
-
|
|
393
|
-
### 설치
|
|
394
|
-
|
|
395
|
-
```bash
|
|
396
|
-
npm install @openrouter/ai-sdk-provider
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### Hono 사용
|
|
400
|
-
|
|
401
|
-
```typescript
|
|
402
|
-
import { Hono } from 'hono'
|
|
403
|
-
import { streamText, convertToModelMessages } from 'ai'
|
|
404
|
-
import { createOpenRouter } from '@openrouter/ai-sdk-provider'
|
|
405
|
-
|
|
406
|
-
type Bindings = {
|
|
407
|
-
OPENROUTER_API_KEY: string
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const app = new Hono<{ Bindings: Bindings }>()
|
|
411
|
-
|
|
412
|
-
app.post('/api/chat', async (c) => {
|
|
413
|
-
const openrouter = createOpenRouter({
|
|
414
|
-
apiKey: c.env.OPENROUTER_API_KEY,
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
const { messages, model } = await c.req.json()
|
|
418
|
-
|
|
419
|
-
const result = streamText({
|
|
420
|
-
model: openrouter.chat(model ?? 'anthropic/claude-3.5-sonnet'),
|
|
421
|
-
messages: convertToModelMessages(messages),
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
return result.toUIMessageStreamResponse()
|
|
425
|
-
})
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
### 인기 모델
|
|
429
|
-
|
|
430
|
-
| 모델 ID | 설명 |
|
|
431
|
-
|---------|------|
|
|
432
|
-
| `anthropic/claude-3.5-sonnet` | Claude 3.5 Sonnet |
|
|
433
|
-
| `openai/gpt-4o` | GPT-4o |
|
|
434
|
-
| `google/gemini-pro-1.5` | Gemini Pro 1.5 |
|
|
435
|
-
| `meta-llama/llama-3.1-70b-instruct` | Llama 3.1 70B |
|
|
436
|
-
|
|
437
|
-
자세한 내용: [OpenRouter 가이드](./openrouter.md)
|
|
438
|
-
|
|
439
|
-
---
|
|
440
|
-
|
|
441
|
-
## 환경 변수 설정
|
|
442
|
-
|
|
443
|
-
### .env (로컬 개발)
|
|
89
|
+
## 환경 변수
|
|
444
90
|
|
|
445
91
|
```bash
|
|
446
92
|
OPENAI_API_KEY=sk-...
|
|
447
93
|
ANTHROPIC_API_KEY=sk-ant-...
|
|
448
94
|
GOOGLE_GENERATIVE_AI_API_KEY=...
|
|
449
|
-
GROQ_API_KEY=gsk_...
|
|
450
|
-
MISTRAL_API_KEY=...
|
|
451
|
-
OPENROUTER_API_KEY=sk-or-v1-...
|
|
452
95
|
```
|
|
453
96
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
```toml
|
|
457
|
-
[vars]
|
|
458
|
-
# 민감하지 않은 변수만 여기에
|
|
459
|
-
|
|
460
|
-
# 민감한 키는 Cloudflare 대시보드에서 설정:
|
|
461
|
-
# Settings > Variables > Environment Variables
|
|
462
|
-
```
|
|
97
|
+
---
|
|
463
98
|
|
|
464
|
-
|
|
99
|
+
## 관련 문서
|
|
465
100
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
3. Environment Variables에서 API 키 추가
|
|
101
|
+
- [AI SDK 개요](./index.md)
|
|
102
|
+
- [OpenRouter](./openrouter.md)
|