Ezmary commited on
Commit
32d0583
·
verified ·
1 Parent(s): e2bd9e9

Update src/contexts/AppContext.tsx

Browse files
Files changed (1) hide show
  1. src/contexts/AppContext.tsx +28 -5
src/contexts/AppContext.tsx CHANGED
@@ -1,4 +1,4 @@
1
- // src/contexts/AppContext.tsx (نسخه نهایی و تصحیح شده)
2
  import React, { createContext, FC, ReactNode, useContext, useEffect, useState, useCallback } from "react";
3
  import { useLiveAPI, type UseLiveAPIResults } from "../hooks/use-live-api";
4
  import { LiveConfig } from "../multimodal-live-types";
@@ -34,13 +34,36 @@ export const AppProvider: FC<{ children: ReactNode; initialConfig?: LiveConfig;
34
  const [isRestarting, setIsRestarting] = useState(false);
35
 
36
  useEffect(() => {
37
- const personalityInstruction = personalityInstructions[selectedPersonality] || "";
38
- const customDetail = selectedPersonality === 'custom' && customUserName ? `نام کاربر ${customUserName} است. او را با نامش صدا بزن.\n\n${customInstructions}` : "";
39
 
40
- const finalInstruction = `${BASE_INSTRUCTION}\n\n${selectedPersonality === 'custom' ? customDetail : personalityInstruction}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  const newConfig: LiveConfig = {
43
- // ✅ رفع خطا: مدل را به صورت صریح تعریف می‌کنیم
44
  model: initialConfig?.model || "models/gemini-2.0-flash-exp",
45
  tools: [{ googleSearch: {} }],
46
  generationConfig: { responseModalities: "audio" },
 
1
+ // src/contexts/AppContext.tsx (نسخه نهایی با قابلیت شناسایی نام در همه شخصیت‌ها)
2
  import React, { createContext, FC, ReactNode, useContext, useEffect, useState, useCallback } from "react";
3
  import { useLiveAPI, type UseLiveAPIResults } from "../hooks/use-live-api";
4
  import { LiveConfig } from "../multimodal-live-types";
 
34
  const [isRestarting, setIsRestarting] = useState(false);
35
 
36
  useEffect(() => {
37
+ // START: منطق جدید و بهبود یافته برای ساخت دستورالعمل نهایی
 
38
 
39
+ // بخش اول: دستورالعمل پایه و جهانی
40
+ let instructionParts = [BASE_INSTRUCTION];
41
+
42
+ // بخش دوم: اضافه کردن نام کاربر (اگر وجود داشته باشد) برای همه شخصیت‌ها
43
+ if (customUserName) {
44
+ instructionParts.push(`نام کاربر ${customUserName} است. او را با نامش صدا بزن.`);
45
+ }
46
+
47
+ // بخش سوم: اضافه کردن دستورالعمل مخصوص شخصیت انتخاب شده
48
+ if (selectedPersonality === 'custom') {
49
+ // اگر شخصیت اختصاصی بود، از دستورات کاربر استفاده کن
50
+ if (customInstructions) {
51
+ instructionParts.push(customInstructions);
52
+ }
53
+ } else {
54
+ // برای سایر شخصیت‌ها، از دستورالعمل‌های تعریف شده استفاده کن
55
+ const personalityPrompt = personalityInstructions[selectedPersonality];
56
+ if (personalityPrompt) {
57
+ instructionParts.push(personalityPrompt);
58
+ }
59
+ }
60
+
61
+ // تمام بخش‌ها را با دو خط جدید از هم جدا می‌کنیم تا برای مدل خوانا باشد
62
+ const finalInstruction = instructionParts.join('\n\n');
63
+
64
+ // ✅ END: پایان منطق جدید
65
 
66
  const newConfig: LiveConfig = {
 
67
  model: initialConfig?.model || "models/gemini-2.0-flash-exp",
68
  tools: [{ googleSearch: {} }],
69
  generationConfig: { responseModalities: "audio" },