feat!: require user to provide LLM api. do not fallback to demo LLM
BREAKING CHANGE: LLM API will be required for agent constructor
This commit is contained in:
@@ -50,7 +50,12 @@ setTimeout(() => {
|
|||||||
window.pageAgent = new PageAgent(config)
|
window.pageAgent = new PageAgent(config)
|
||||||
} else {
|
} else {
|
||||||
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
||||||
window.pageAgent = new PageAgent()
|
const config = {
|
||||||
|
model: DEMO_MODEL,
|
||||||
|
baseURL: DEMO_BASE_URL,
|
||||||
|
apiKey: DEMO_API_KEY,
|
||||||
|
}
|
||||||
|
window.pageAgent = new PageAgent(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
||||||
|
|||||||
@@ -1,20 +1,3 @@
|
|||||||
// Dev environment: use .env config if available, otherwise fallback to testing api
|
// Internal constants
|
||||||
export const DEFAULT_MODEL_NAME: string =
|
|
||||||
import.meta.env.DEV && import.meta.env.LLM_MODEL_NAME
|
|
||||||
? import.meta.env.LLM_MODEL_NAME
|
|
||||||
: 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|
||||||
|
|
||||||
export const DEFAULT_API_KEY: string =
|
|
||||||
import.meta.env.DEV && import.meta.env.LLM_API_KEY
|
|
||||||
? import.meta.env.LLM_API_KEY
|
|
||||||
: 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|
||||||
|
|
||||||
export const DEFAULT_BASE_URL: string =
|
|
||||||
import.meta.env.DEV && import.meta.env.LLM_BASE_URL
|
|
||||||
? import.meta.env.LLM_BASE_URL
|
|
||||||
: 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
|
||||||
|
|
||||||
// internal
|
|
||||||
|
|
||||||
export const LLM_MAX_RETRIES = 2
|
export const LLM_MAX_RETRIES = 2
|
||||||
export const DEFAULT_TEMPERATURE = 0.7 // higher randomness helps auto-recovery
|
export const DEFAULT_TEMPERATURE = 0.7 // higher randomness helps auto-recovery
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import { OpenAIClient } from './OpenAIClient'
|
import { OpenAIClient } from './OpenAIClient'
|
||||||
import {
|
import { DEFAULT_TEMPERATURE, LLM_MAX_RETRIES } from './constants'
|
||||||
DEFAULT_API_KEY,
|
|
||||||
DEFAULT_BASE_URL,
|
|
||||||
DEFAULT_MODEL_NAME,
|
|
||||||
DEFAULT_TEMPERATURE,
|
|
||||||
LLM_MAX_RETRIES,
|
|
||||||
} from './constants'
|
|
||||||
import { InvokeError } from './errors'
|
import { InvokeError } from './errors'
|
||||||
import type { InvokeOptions, InvokeResult, LLMClient, LLMConfig, Message, Tool } from './types'
|
import type { InvokeOptions, InvokeResult, LLMClient, LLMConfig, Message, Tool } from './types'
|
||||||
|
|
||||||
export type { InvokeOptions, InvokeResult, LLMClient, LLMConfig, Message, Tool }
|
export type { InvokeOptions, InvokeResult, LLMClient, LLMConfig, Message, Tool }
|
||||||
|
|
||||||
export function parseLLMConfig(config: LLMConfig): Required<LLMConfig> {
|
export function parseLLMConfig(config: LLMConfig): Required<LLMConfig> {
|
||||||
|
// Runtime validation as defensive programming (types already guarantee these)
|
||||||
|
if (!config.baseURL || !config.apiKey || !config.model) {
|
||||||
|
throw new Error(
|
||||||
|
'[PageAgent] LLM configuration required. Please provide: baseURL, apiKey, model. ' +
|
||||||
|
'See: https://alibaba.github.io/page-agent/#/docs/features/models'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
baseURL: config.baseURL,
|
||||||
apiKey: config.apiKey ?? DEFAULT_API_KEY,
|
apiKey: config.apiKey,
|
||||||
model: config.model ?? DEFAULT_MODEL_NAME,
|
model: config.model,
|
||||||
temperature: config.temperature ?? DEFAULT_TEMPERATURE,
|
temperature: config.temperature ?? DEFAULT_TEMPERATURE,
|
||||||
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
|
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
|
||||||
customFetch: (config.customFetch ?? fetch).bind(globalThis), // fetch will be illegal unless bound
|
customFetch: (config.customFetch ?? fetch).bind(globalThis), // fetch will be illegal unless bound
|
||||||
|
|||||||
@@ -87,9 +87,9 @@ export interface InvokeResult<TResult = unknown> {
|
|||||||
* LLM configuration
|
* LLM configuration
|
||||||
*/
|
*/
|
||||||
export interface LLMConfig {
|
export interface LLMConfig {
|
||||||
baseURL?: string
|
baseURL: string
|
||||||
apiKey?: string
|
apiKey: string
|
||||||
model?: string
|
model: string
|
||||||
|
|
||||||
temperature?: number
|
temperature?: number
|
||||||
maxRetries?: number
|
maxRetries?: number
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export class PageAgent extends EventTarget {
|
|||||||
/** History records */
|
/** History records */
|
||||||
history: AgentHistory[] = []
|
history: AgentHistory[] = []
|
||||||
|
|
||||||
constructor(config: PageAgentConfig = {}) {
|
constructor(config: PageAgentConfig) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ setTimeout(() => {
|
|||||||
window.pageAgent = new PageAgent(config)
|
window.pageAgent = new PageAgent(config)
|
||||||
} else {
|
} else {
|
||||||
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
||||||
window.pageAgent = new PageAgent()
|
const config: PageAgentConfig = {
|
||||||
|
model: DEMO_MODEL,
|
||||||
|
baseURL: DEMO_BASE_URL,
|
||||||
|
apiKey: DEMO_API_KEY,
|
||||||
|
}
|
||||||
|
window.pageAgent = new PageAgent(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
||||||
|
|||||||
@@ -7,3 +7,9 @@ export const CDN_DEMO_CN_URL =
|
|||||||
export const CDN_FULL_URL = 'https://cdn.jsdelivr.net/npm/@page-agent/cdn/dist/page-agent.js'
|
export const CDN_FULL_URL = 'https://cdn.jsdelivr.net/npm/@page-agent/cdn/dist/page-agent.js'
|
||||||
export const CDN_FULL_CN_URL =
|
export const CDN_FULL_CN_URL =
|
||||||
'https://registry.npmmirror.com/@page-agent/cdn/latest/files/dist/page-agent.js'
|
'https://registry.npmmirror.com/@page-agent/cdn/latest/files/dist/page-agent.js'
|
||||||
|
|
||||||
|
// Demo LLM for website testing
|
||||||
|
export const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
|
export const DEMO_BASE_URL =
|
||||||
|
'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
||||||
|
export const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
|
|||||||
@@ -12,7 +12,13 @@ import { Highlighter } from '../components/ui/highlighter'
|
|||||||
import { NeonGradientCard } from '../components/ui/neon-gradient-card'
|
import { NeonGradientCard } from '../components/ui/neon-gradient-card'
|
||||||
import { Particles } from '../components/ui/particles'
|
import { Particles } from '../components/ui/particles'
|
||||||
import { SparklesText } from '../components/ui/sparkles-text'
|
import { SparklesText } from '../components/ui/sparkles-text'
|
||||||
import { CDN_DEMO_CN_URL, CDN_DEMO_URL } from '../constants'
|
import {
|
||||||
|
CDN_DEMO_CN_URL,
|
||||||
|
CDN_DEMO_URL,
|
||||||
|
DEMO_API_KEY,
|
||||||
|
DEMO_BASE_URL,
|
||||||
|
DEMO_MODEL,
|
||||||
|
} from '../constants'
|
||||||
|
|
||||||
function getInjection(useCN?: boolean) {
|
function getInjection(useCN?: boolean) {
|
||||||
const cdn = useCN ? CDN_DEMO_CN_URL : CDN_DEMO_URL
|
const cdn = useCN ? CDN_DEMO_CN_URL : CDN_DEMO_URL
|
||||||
@@ -73,13 +79,18 @@ export default function HomePage() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// experimentalScriptExecutionTool: true,
|
model:
|
||||||
|
import.meta.env.DEV && import.meta.env.LLM_MODEL_NAME
|
||||||
// testing server
|
? import.meta.env.LLM_MODEL_NAME
|
||||||
// @note: rate limit. prompt limit.
|
: DEMO_MODEL,
|
||||||
// model: DEMO_MODEL,
|
baseURL:
|
||||||
// baseURL: DEMO_BASE_URL,
|
import.meta.env.DEV && import.meta.env.LLM_BASE_URL
|
||||||
// apiKey: DEMO_API_KEY,
|
? import.meta.env.LLM_BASE_URL
|
||||||
|
: DEMO_BASE_URL,
|
||||||
|
apiKey:
|
||||||
|
import.meta.env.DEV && import.meta.env.LLM_API_KEY
|
||||||
|
? import.meta.env.LLM_API_KEY
|
||||||
|
: DEMO_API_KEY,
|
||||||
})
|
})
|
||||||
win.pageAgent = pageAgent
|
win.pageAgent = pageAgent
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user