MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / collectOpenAISources

Function collectOpenAISources

ai/ai.ts:1899–1947  ·  view source on GitHub ↗
(
  data: any,
)

Source from the content-addressed store, hash-verified

1897
1898const collectOpenAISources = (
1899 data: any,
1900): Array<{ url: string; title?: string }> => {
1901 const sources: Array<{ url: string; title?: string }> = [];
1902 const seen = new Set<string>();
1903
1904 const appendEntries = (entries: any[] | undefined, isAnnotation = false) => {
1905 if (!Array.isArray(entries)) return;
1906 for (const entry of entries) {
1907 const url = isAnnotation
1908 ? entry?.url_citation?.url || entry?.url
1909 : entry?.url;
1910 const title = isAnnotation
1911 ? entry?.url_citation?.title || entry?.title
1912 : entry?.title;
1913 if (!url || seen.has(url)) continue;
1914 seen.add(url);
1915 sources.push({ url, title });
1916 }
1917 };
1918
1919 const choice = data?.choices?.[0];
1920
1921 appendEntries(data?.citations);
1922 appendEntries(choice?.citations);
1923 appendEntries(choice?.message?.citations);
1924 appendEntries(choice?.delta?.citations);
1925
1926 appendEntries(
1927 (data?.annotations || []).filter(
1928 (entry: any) => entry?.type === "url_citation" || entry?.url_citation,
1929 ),
1930 true,
1931 );
1932 appendEntries(
1933 (choice?.message?.annotations || []).filter(
1934 (entry: any) => entry?.type === "url_citation" || entry?.url_citation,
1935 ),
1936 true,
1937 );
1938 appendEntries(
1939 (choice?.delta?.annotations || []).filter(
1940 (entry: any) => entry?.type === "url_citation" || entry?.url_citation,
1941 ),
1942 true,
1943 );
1944
1945 return sources;
1946};
1947
1948const aggregateOpenAIResponses = (
1949 payloads: any[],
1950): {

Callers 1

aggregateOpenAIResponsesFunction · 0.85

Calls 1

appendEntriesFunction · 0.85

Tested by

no test coverage detected