Skip to content

Commit 7f01e4b

Browse files
committed
Use context7 api key
1 parent 6735d3b commit 7f01e4b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

backend/src/llm-apis/context7-api.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { withTimeout } from '@codebuff/common/util/promise'
2+
import { env } from '@codebuff/internal/env'
23

34
import { logger } from '../util/logger'
45

@@ -55,7 +56,14 @@ export async function searchLibraries(
5556
url.searchParams.set('query', query)
5657

5758
const fetchStartTime = Date.now()
58-
const response = await withTimeout(fetch(url), FETCH_TIMEOUT_MS)
59+
const response = await withTimeout(
60+
fetch(url, {
61+
headers: {
62+
Authorization: `Bearer ${env.CONTEXT7_API_KEY}`,
63+
},
64+
}),
65+
FETCH_TIMEOUT_MS,
66+
)
5967
const fetchDuration = Date.now() - fetchStartTime
6068

6169
if (!response.ok) {
@@ -181,6 +189,7 @@ export async function fetchContext7LibraryDocumentation(
181189
const response = await withTimeout(
182190
fetch(url, {
183191
headers: {
192+
Authorization: `Bearer ${env.CONTEXT7_API_KEY}`,
184193
'X-Context7-Source': 'codebuff',
185194
},
186195
}),

common/src/tools/params/tool/read-docs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const readDocsParams = {
2222
),
2323
max_tokens: z
2424
.number()
25-
.default(20_000)
25+
.default(10_000)
2626
.optional()
2727
.describe(
2828
`Optional maximum number of tokens to return. Defaults to 20000. Values less than 10000 are automatically increased to 10000.`,

packages/internal/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const envSchema = {
1313
OPEN_ROUTER_API_KEY: z.string().min(1),
1414
RELACE_API_KEY: z.string().min(1),
1515
LINKUP_API_KEY: z.string().min(1),
16+
CONTEXT7_API_KEY: z.string().optional(),
1617
GOOGLE_CLOUD_PROJECT_ID: z.string().min(1),
1718
PORT: z.coerce.number().min(1000),
1819

@@ -54,6 +55,7 @@ const envSchema = {
5455
OPEN_ROUTER_API_KEY: process.env.OPEN_ROUTER_API_KEY,
5556
RELACE_API_KEY: process.env.RELACE_API_KEY,
5657
LINKUP_API_KEY: process.env.LINKUP_API_KEY,
58+
CONTEXT7_API_KEY: process.env.CONTEXT7_API_KEY,
5759
GOOGLE_CLOUD_PROJECT_ID: process.env.GOOGLE_CLOUD_PROJECT_ID,
5860
PORT: process.env.PORT,
5961

0 commit comments

Comments
 (0)