fix: prompt explorer bugs (#136)
This commit is contained in:
parent
1108cdd9a7
commit
ebc9e0b4fa
@ -28,8 +28,13 @@ import {
|
||||
/** LLM responses are stable enough for a 7-day cache. */
|
||||
const PROMPT_RESPONSE_TTL_SECONDS = 7 * 24 * 60 * 60;
|
||||
|
||||
/** Hard cap on response length to keep payloads sane. */
|
||||
const PROMPT_RESPONSE_MAX_TOKENS = 1024;
|
||||
/**
|
||||
* Hard cap on response length. Set to the DataForSEO per-call maximum because
|
||||
* reasoning models (gpt-5, gemini-2.5-pro) count hidden chain-of-thought
|
||||
* tokens against this budget — at 1024 ChatGPT regularly burns the whole
|
||||
* budget on reasoning and returns a near-empty visible message.
|
||||
*/
|
||||
const PROMPT_RESPONSE_MAX_TOKENS = 4096;
|
||||
|
||||
type DataforseoClient = ReturnType<typeof createDataforseoClient>;
|
||||
|
||||
@ -94,7 +99,7 @@ async function runModel(
|
||||
webSearch: args.input.webSearch,
|
||||
webSearchCountryCode: args.input.webSearchCountryCode ?? null,
|
||||
// Bumped when prompt/payload shape changes — busts stale cache entries.
|
||||
systemPromptV: 4,
|
||||
systemPromptV: 5,
|
||||
});
|
||||
|
||||
const cached = promptExplorerModelResultSchema.safeParse(
|
||||
|
||||
@ -324,13 +324,17 @@ export async function fetchLlmResponseRaw(
|
||||
input: LlmResponsesInput,
|
||||
): Promise<DataforseoApiResponse<LlmResponseResult>> {
|
||||
const path = `/v3/ai_optimization/${input.modelSlug}/llm_responses/live`;
|
||||
// DataForSEO's Gemini endpoint rejects `web_search_country_iso_code` with a
|
||||
// 40501 "Invalid Field" error. The other three models accept it.
|
||||
const supportsCountry = input.modelSlug !== "gemini";
|
||||
const payload = [
|
||||
{
|
||||
user_prompt: input.userPrompt,
|
||||
model_name: input.modelName,
|
||||
web_search: input.webSearch ?? true,
|
||||
max_output_tokens: clampLimit(input.maxOutputTokens ?? 1024, 256, 4096),
|
||||
...(input.webSearchCountryCode && {
|
||||
...(supportsCountry &&
|
||||
input.webSearchCountryCode && {
|
||||
web_search_country_iso_code: input.webSearchCountryCode,
|
||||
}),
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user