Ezmary commited on
Commit
76c3907
·
verified ·
1 Parent(s): a3aa287

Update src/hooks/use-live-api.ts

Browse files
Files changed (1) hide show
  1. src/hooks/use-live-api.ts +8 -4
src/hooks/use-live-api.ts CHANGED
@@ -34,10 +34,15 @@ export type UseLiveAPIResults = {
34
  volume: number;
35
  };
36
 
 
 
 
 
37
  export function useLiveAPI({
38
  url,
39
  apiKey,
40
- }: MultimodalLiveAPIClientConnection): UseLiveAPIResults {
 
41
  const client = useMemo(
42
  () => new MultimodalLiveClient({ url, apiKey }),
43
  [url, apiKey],
@@ -45,7 +50,7 @@ export function useLiveAPI({
45
  const audioStreamerRef = useRef<AudioStreamer | null>(null);
46
 
47
  const [connected, setConnected] = useState(false);
48
- const [config, setConfig] = useState<LiveConfig>({
49
  model: "models/gemini-2.0-flash-exp",
50
  });
51
  const [volume, setVolume] = useState(0);
@@ -90,7 +95,6 @@ export function useLiveAPI({
90
  }, [client]);
91
 
92
  const connect = useCallback(async () => {
93
- console.log(config);
94
  if (!config) {
95
  throw new Error("config has not been set");
96
  }
@@ -113,4 +117,4 @@ export function useLiveAPI({
113
  disconnect,
114
  volume,
115
  };
116
- }
 
34
  volume: number;
35
  };
36
 
37
+ export type UseLiveAPIOptions = MultimodalLiveAPIClientConnection & {
38
+ initialConfig?: LiveConfig;
39
+ };
40
+
41
  export function useLiveAPI({
42
  url,
43
  apiKey,
44
+ initialConfig
45
+ }: UseLiveAPIOptions): UseLiveAPIResults {
46
  const client = useMemo(
47
  () => new MultimodalLiveClient({ url, apiKey }),
48
  [url, apiKey],
 
50
  const audioStreamerRef = useRef<AudioStreamer | null>(null);
51
 
52
  const [connected, setConnected] = useState(false);
53
+ const [config, setConfig] = useState<LiveConfig>(initialConfig || {
54
  model: "models/gemini-2.0-flash-exp",
55
  });
56
  const [volume, setVolume] = useState(0);
 
95
  }, [client]);
96
 
97
  const connect = useCallback(async () => {
 
98
  if (!config) {
99
  throw new Error("config has not been set");
100
  }
 
117
  disconnect,
118
  volume,
119
  };
120
+ }