This commit is contained in:
从何开始123
2026-01-12 17:45:36 +08:00
parent 586cf48a5a
commit bd297716b0
6 changed files with 41 additions and 89 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -44,8 +44,7 @@ export const streamExpertResponse = async (
systemInstruction: getExpertSystemInstruction(expert.role, expert.description, context), systemInstruction: getExpertSystemInstruction(expert.role, expert.description, context),
temperature: expert.temperature, temperature: expert.temperature,
thinkingConfig: { thinkingConfig: {
thinkingBudget: budget, thinkingBudget: budget
includeThoughts: true
} }
} }
})); }));
@@ -54,19 +53,8 @@ export const streamExpertResponse = async (
for await (const chunk of (streamResult as any)) { for await (const chunk of (streamResult as any)) {
if (signal.aborted) break; if (signal.aborted) break;
let chunkText = ""; const chunkText = chunk.text || "";
let chunkThought = ""; onChunk(chunkText, "");
if (chunk.candidates?.[0]?.content?.parts) {
for (const part of chunk.candidates[0].content.parts) {
if (part.thought) {
chunkThought += (part.text || "");
} else if (part.text) {
chunkText += part.text;
}
}
onChunk(chunkText, chunkThought);
}
} }
} catch (streamError) { } catch (streamError) {
console.error(`Stream interrupted for expert ${expert.role}:`, streamError); console.error(`Stream interrupted for expert ${expert.role}:`, streamError);

View File

@@ -68,7 +68,6 @@ export const executeManagerAnalysis = async (
responseMimeType: "application/json", responseMimeType: "application/json",
responseSchema: managerSchema, responseSchema: managerSchema,
thinkingConfig: { thinkingConfig: {
includeThoughts: true,
thinkingBudget: budget thinkingBudget: budget
} }
} }
@@ -193,7 +192,6 @@ export const executeManagerReview = async (
responseMimeType: "application/json", responseMimeType: "application/json",
responseSchema: reviewSchema, responseSchema: reviewSchema,
thinkingConfig: { thinkingConfig: {
includeThoughts: true,
thinkingBudget: budget thinkingBudget: budget
} }
} }

View File

@@ -56,8 +56,7 @@ export const generateContent = async (
const requestOptions: any = { const requestOptions: any = {
model: config.model, model: config.model,
messages, messages,
// Clamp temperature to 1.0 max for compatibility with strict providers (NVIDIA, vLLM, etc.) temperature: config.temperature,
temperature: typeof config.temperature === 'number' ? Math.min(config.temperature, 1.0) : undefined,
}; };
if (config.responseFormat === 'json_object') { if (config.responseFormat === 'json_object') {
@@ -66,15 +65,7 @@ export const generateContent = async (
try { try {
const response = await withRetry(() => ai.chat.completions.create(requestOptions)); const response = await withRetry(() => ai.chat.completions.create(requestOptions));
const message = response.choices[0]?.message; const content = response.choices[0]?.message?.content || '';
const content = message?.content || '';
// Check for native reasoning_content field (DeepSeek/NVIDIA style)
const reasoningContent = (message as any)?.reasoning_content;
if (reasoningContent && config.thinkingConfig?.includeThoughts) {
return { text: content, thought: reasoningContent };
}
if (config.thinkingConfig?.includeThoughts) { if (config.thinkingConfig?.includeThoughts) {
const { thought, text } = parseThinkingTokens(content); const { thought, text } = parseThinkingTokens(content);
@@ -109,8 +100,7 @@ export async function* generateContentStream(
const requestOptions: any = { const requestOptions: any = {
model: config.model, model: config.model,
messages, messages,
// Clamp temperature to 1.0 max for compatibility with strict providers temperature: config.temperature,
temperature: typeof config.temperature === 'number' ? Math.min(config.temperature, 1.0) : undefined,
stream: true, stream: true,
}; };
@@ -121,56 +111,44 @@ export async function* generateContentStream(
let currentThought = ''; let currentThought = '';
for await (const chunk of (stream as any)) { for await (const chunk of (stream as any)) {
const delta = chunk.choices[0]?.delta; const delta = chunk.choices[0]?.delta?.content || '';
if (!delta) continue; if (!delta) continue;
const content = delta.content || ''; accumulatedText += delta;
// Check for native reasoning_content field (DeepSeek/NVIDIA style)
const reasoning = delta.reasoning_content || '';
// If native reasoning field exists, emit it immediately if (config.thinkingConfig?.includeThoughts) {
if (reasoning && config.thinkingConfig?.includeThoughts) { if (delta.includes('<thinking>')) {
yield { text: '', thought: reasoning }; inThinking = true;
} continue;
}
if (content) { if (inThinking) {
accumulatedText += content; if (delta.includes('</thinking>')) {
inThinking = false;
const parts = delta.split('</thinking>', 2);
currentThought += parts[0];
if (config.thinkingConfig?.includeThoughts) { if (currentThought.trim()) {
// Fallback to tag parsing if reasoning_content wasn't provided but tags exist yield { text: '', thought: currentThought };
if (content.includes('<thinking>')) { currentThought = '';
inThinking = true; }
continue;
}
if (inThinking) { if (parts[1]) {
if (content.includes('</thinking>')) { yield { text: parts[1], thought: '' };
inThinking = false;
const parts = content.split('</thinking>', 2);
currentThought += parts[0];
if (currentThought.trim()) {
yield { text: '', thought: currentThought };
currentThought = '';
}
if (parts[1]) {
yield { text: parts[1], thought: '' };
}
} else {
currentThought += content;
// Emit thought chunks periodically so it doesn't hang
if (currentThought.length > 50) {
yield { text: '', thought: currentThought };
currentThought = '';
}
} }
} else { } else {
yield { text: content, thought: '' }; currentThought += delta;
if (currentThought.length > 100) {
yield { text: '', thought: currentThought };
currentThought = '';
}
} }
} else { } else {
yield { text: content, thought: '' }; yield { text: delta, thought: '' };
} }
} else {
yield { text: delta, thought: '' };
} }
} }

View File

@@ -5,11 +5,11 @@ export const MANAGER_SYSTEM_PROMPT = `You are the "Dynamic Planning Engine". You
Your job is to create SUPPLEMENTARY experts Your job is to create SUPPLEMENTARY experts
For each expert, you must assign a specific 'temperature' (0.0 to 1.0) based on the nature of their task: For each expert, you must assign a specific 'temperature' (0.0 to 2.0) based on the nature of their task:
* High temperature (0.7 - 1.0) - For creative, brainstorming, or open-ended tasks. * High temperature (1.0 - 2.0)
* Low temperature (0.0 - 0.3) - For code, math, logic, or factual tasks. * Low temperature (0.0 - 0.4)
* Medium temperature (0.3 - 0.7) - For balanced analysis and general explanation.`; * Medium temperature (0.4 - 1.0)`;
export const MANAGER_REVIEW_SYSTEM_PROMPT = ` export const MANAGER_REVIEW_SYSTEM_PROMPT = `
You are the "Quality Assurance & Orchestration Engine". You are the "Quality Assurance & Orchestration Engine".

View File

@@ -44,8 +44,7 @@ export const streamSynthesisResponse = async (
contents: contents, contents: contents,
config: { config: {
thinkingConfig: { thinkingConfig: {
thinkingBudget: budget, thinkingBudget: budget
includeThoughts: true
} }
} }
})); }));
@@ -53,20 +52,9 @@ export const streamSynthesisResponse = async (
try { try {
for await (const chunk of (synthesisStream as any)) { for await (const chunk of (synthesisStream as any)) {
if (signal.aborted) break; if (signal.aborted) break;
let chunkText = ""; const chunkText = chunk.text || "";
let chunkThought = ""; onChunk(chunkText, "");
if (chunk.candidates?.[0]?.content?.parts) {
for (const part of chunk.candidates[0].content.parts) {
if (part.thought) {
chunkThought += (part.text || "");
} else if (part.text) {
chunkText += part.text;
}
}
onChunk(chunkText, chunkThought);
}
} }
} catch (streamError) { } catch (streamError) {
console.error("Synthesis stream interrupted:", streamError); console.error("Synthesis stream interrupted:", streamError);