feat: 添加对新特性(API)的修改;

fix: 修复了代码中的一个错误;
refactor: 重写/重构代码,但没有改变API的行为;
style: 添加了空格、格式化、缺失的分号等;
test: 添加了缺失的测试或修正了现有的测试;
docs: 更新了文档,如readme;
build: 更新了依赖、项目版本;
ops: 影响了基础设施、部署、备份、恢复等操作性组件;
chore: 修改了.gitignore等;

根据以上信息,你的commit message可以是:
This commit is contained in:
zyh 2024-10-11 12:10:07 +00:00
parent ef45e66b17
commit 4baf31d516
6 changed files with 12 additions and 5 deletions

View File

@ -7,3 +7,4 @@ export function getAPIKey(cloudflareEnv: Env) {
*/
return env.ANTHROPIC_API_KEY || cloudflareEnv.ANTHROPIC_API_KEY;
}

View File

@ -0,0 +1,4 @@
import { env } from 'node:process';
export function getBaseURL(cloudflareEnv: Env) {
return env.ANTHROPIC_BASE_URL || cloudflareEnv.ANTHROPIC_BASE_URL;
}

View File

@ -1,7 +1,6 @@
import { createAnthropic } from '@ai-sdk/anthropic';
import { env } from 'node:process';
export function getAnthropicModel(apiKey: string) {
const baseURL = env.ANTHROPIC_BASE_URL;
export function getAnthropicModel(apiKey: string, baseURL: string) {
console.log('baseURL', baseURL);
const anthropic = createAnthropic({
apiKey,
baseURL,

View File

@ -1,6 +1,7 @@
import { streamText as _streamText, convertToCoreMessages } from 'ai';
import { getAPIKey } from '~/lib/.server/llm/api-key';
import { getAnthropicModel } from '~/lib/.server/llm/model';
import { getBaseURL } from '~/lib/.server/llm/base-url';
import { MAX_TOKENS } from './constants';
import { getSystemPrompt } from './prompts';
@ -23,7 +24,7 @@ export type StreamingOptions = Omit<Parameters<typeof _streamText>[0], 'model'>;
export function streamText(messages: Messages, env: Env, options?: StreamingOptions) {
return _streamText({
model: getAnthropicModel(getAPIKey(env)),
model: getAnthropicModel(getAPIKey(env), getBaseURL(env)),
system: getSystemPrompt(),
maxTokens: MAX_TOKENS,
headers: {

View File

@ -9,7 +9,7 @@
"scripts": {
"deploy": "npm run build && wrangler pages deploy",
"build": "remix vite:build",
"dev": "remix vite:dev",
"dev": "remix vite:dev --port 23895",
"test": "vitest --run",
"test:watch": "vitest",
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",

View File

@ -1,3 +1,5 @@
interface Env {
ANTHROPIC_API_KEY: string;
ANTHROPIC_BASE_URL: string;
}