repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
Yi.Abp.Admin
github_2023
ccnetcore
typescript
StorageProxy.clear
public async clear() { return new Promise<void>((resolve, reject) => { this.storage .clear() .then(() => { resolve(); }) .catch(err => { reject(err); }); }); }
/** * @description 从离线仓库中删除所有的键名,重置数据库 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/localforage/index.ts#L76-L87
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
StorageProxy.keys
public async keys() { return new Promise<string[]>((resolve, reject) => { this.storage .keys() .then(keys => { resolve(keys); }) .catch(err => { reject(err); }); }); }
/** * @description 获取数据仓库中所有的key */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/localforage/index.ts#L92-L103
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleSelectionChange
function handleSelectionChange(val) { selectedNum.value = val.length; // 重置表格高度 tableRef.value.setAdaptive(); }
/** 当CheckBox选择项发生变化时会触发该事件 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/login/hook.tsx#L99-L103
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onSelectionCancel
function onSelectionCancel() { selectedNum.value = 0; // 用于多选表格,清空用户的选择 tableRef.value.getTableRef().clearSelection(); }
/** 取消选择 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/login/hook.tsx#L106-L110
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onbatchDel
function onbatchDel() { // 返回当前选中的行 const curSelected = tableRef.value.getTableRef().getSelectionRows(); // 接下来根据实际业务,通过选中行的某项数据,比如下面的id,调用接口进行批量删除 message(`已删除序号为 ${getKeyList(curSelected, "id")} 的数据`, { type: "success" }); tableRef.value.getTableRef().clearSelection(); onSearch(); }
/** 批量删除 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/login/hook.tsx#L113-L122
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
clearAll
function clearAll() { // 根据实际业务,调用接口删除所有日志数据 message("已删除所有日志数据", { type: "success" }); onSearch(); }
/** 清空日志 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/login/hook.tsx#L125-L131
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleSelectionChange
function handleSelectionChange(val) { selectedNum.value = val.length; // 重置表格高度 tableRef.value.setAdaptive(); }
/** 当CheckBox选择项发生变化时会触发该事件 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/operation/hook.tsx#L105-L109
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onSelectionCancel
function onSelectionCancel() { selectedNum.value = 0; // 用于多选表格,清空用户的选择 tableRef.value.getTableRef().clearSelection(); }
/** 取消选择 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/operation/hook.tsx#L112-L116
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onbatchDel
function onbatchDel() { // 返回当前选中的行 const curSelected = tableRef.value.getTableRef().getSelectionRows(); // 接下来根据实际业务,通过选中行的某项数据,比如下面的id,调用接口进行批量删除 message(`已删除序号为 ${getKeyList(curSelected, "id")} 的数据`, { type: "success" }); tableRef.value.getTableRef().clearSelection(); onSearch(); }
/** 批量删除 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/operation/hook.tsx#L119-L128
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
clearAll
function clearAll() { // 根据实际业务,调用接口删除所有日志数据 message("已删除所有日志数据", { type: "success" }); onSearch(); }
/** 清空日志 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/logs/operation/hook.tsx#L131-L137
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleSelectionChange
function handleSelectionChange(val) { console.log(val); }
/** 当CheckBox选择项发生变化时会触发该事件 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/monitor/online/hook.tsx#L77-L79
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
rowStyle
function rowStyle({ row: { id } }) { return { cursor: "pointer", background: id === curRow.value?.id ? "var(--el-fill-color-light)" : "" }; }
/** 高亮当前权限选中行 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/config/utils/hook.tsx#L31-L36
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
rowStyle
function rowStyle({ row: { id } }) { return { cursor: "pointer", background: id === curRow.value?.id ? "var(--el-fill-color-light)" : "" }; }
/** 高亮当前权限选中行 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/post/utils/hook.tsx#L230-L235
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
filterMethod
const filterMethod = (query: string, node) => { return transformI18n(node.title)!.includes(query); };
/** 数据权限 可自行开发 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/post/utils/hook.tsx#L240-L242
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleMenu
async function handleMenu(row?: any) { const { id } = row; if (id) { curRow.value = (await getRole(id)).data; curRow.value.menuIds = (await getRoleMenuSelect(id)).data.map(m => m.id); isShow.value = true; nextTick(async () => { treeRef.value.setCheckedKeys(curRow.value.menuIds); }); } else { curRow.value = null; isShow.value = false; } }
/** 菜单权限 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/role/utils/hook.tsx#L249-L262
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
rowStyle
function rowStyle({ row: { id } }) { return { cursor: "pointer", background: id === curRow.value?.id ? "var(--el-fill-color-light)" : "" }; }
/** 高亮当前权限选中行 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/role/utils/hook.tsx#L265-L270
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleSave
async function handleSave() { const { id, roleName } = curRow.value; curRow.value.menuIds = treeRef.value.getCheckedKeys(); // 根据用户 id 调用实际项目中菜单权限修改接口 await updateRole(id, curRow.value); message(`角色名称为${roleName}的菜单权限修改成功`, { type: "success" }); }
/** 菜单权限-保存 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/role/utils/hook.tsx#L273-L282
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onQueryChanged
const onQueryChanged = (query: string) => { treeRef.value!.filter(query); };
/** 数据权限 可自行开发 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/role/utils/hook.tsx#L287-L289
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleSelectionChange
function handleSelectionChange(val) { selectedNum.value = val.length; // 重置表格高度 tableRef.value.setAdaptive(); }
/** 当CheckBox选择项发生变化时会触发该事件 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx#L263-L267
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onSelectionCancel
function onSelectionCancel() { selectedNum.value = 0; // 用于多选表格,清空用户的选择 tableRef.value.getTableRef().clearSelection(); }
/** 取消选择 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx#L270-L274
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onbatchDel
async function onbatchDel() { // 返回当前选中的行 const curSelected = tableRef.value.getTableRef().getSelectionRows(); const delIds = getKeyList(curSelected, "id"); await delUser(delIds); // 接下来根据实际业务,通过选中行的某项数据,比如下面的id,调用接口进行批量删除 message(`已删除用户编号为 ${delIds} 的数据`, { type: "success" }); tableRef.value.getTableRef().clearSelection(); onSearch(); }
/** 批量删除 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx#L277-L288
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleUpload
function handleUpload(row) { addDialog({ title: "裁剪、上传头像", width: "40%", closeOnClickModal: false, fullscreen: deviceDetection(), contentRenderer: () => h(ReCropperPreview, { ref: cropRef, imgSrc: getFileUrl(row.avatar, userAvatar), onCropper: info => (avatarInfo.value = info) }), beforeSure: done => { console.log("裁剪后的图片信息:", avatarInfo.value); // 根据实际业务使用avatarInfo.value和row里的某些字段去调用上传头像接口即可 const formData = createFormData({ file: avatarInfo.value // file 文件 }); uploadFile(formData) .then(async response => { let data = { userId: row.id, icon: response.data[0]["id"] }; updateUserIcon(data).then(_response2 => { message(`头像更新成功`, { type: "success" }); done(); // 关闭弹框 onSearch(); // 刷新表格数据 }); }) .catch(error => { message(`头像更新异常 ${error}`, { type: "error" }); }); }, closeCallBack: () => cropRef.value.hidePopover() }); }
/** 上传头像 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx#L393-L429
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
handleReset
function handleReset(row) { addDialog({ title: `重置 ${row.userName} 用户的密码`, width: "30%", draggable: true, closeOnClickModal: false, fullscreen: deviceDetection(), contentRenderer: () => ( <> <ElForm ref={ruleFormRef} model={pwdForm}> <ElFormItem prop="password" rules={[ { required: true, message: "请输入新密码", trigger: "blur" } ]} > <ElInput clearable show-password type="password" v-model={pwdForm.password} placeholder="请输入新密码" /> </ElFormItem> </ElForm> <div class="mt-4 flex"> {pwdProgress.map(({ color, text }, idx) => ( <div class="w-[19vw]" style={{ marginLeft: idx !== 0 ? "4px" : 0 }} > <ElProgress striped striped-flow duration={curScore.value === idx ? 6 : 0} percentage={curScore.value >= idx ? 100 : 0} color={color} stroke-width={10} show-text={false} /> <p class="text-center" style={{ color: curScore.value === idx ? color : "" }} > {text} </p> </div> ))} </div> </> ), closeCallBack: () => (pwdForm.password = ""), beforeSure: done => { ruleFormRef.value.validate(async valid => { if (valid) { await resetUserPwd(row.id, pwdForm.password); // 表单规则校验通过 message(`已成功重置 ${row.username} 用户的密码`, { type: "success" }); // 根据实际业务使用pwdForm.newPwd和row里的某些字段去调用重置用户密码接口即可 done(); // 关闭弹框 onSearch(); // 刷新表格数据 } }); } }); }
/** 重置密码 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx#L438-L509
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
rowStyle
function rowStyle({ row: { name } }) { return { cursor: "pointer", background: name === selectValue.value ? "var(--el-fill-color-light)" : "" }; }
/** 高亮当前选中行 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/table/high/table-select/radio/columns.tsx#L40-L45
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
onRowClick
function onRowClick(row) { selectValue.value = row.name; selectRef.value.blur(); message(`当前选中行的数据为:${JSON.stringify(row)}`, { type: "success" }); }
/** 行点击 */
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/table/high/table-select/radio/columns.tsx#L48-L52
e03895bcb6eca1f1894af1de15784838172956d5
Yi.Abp.Admin
github_2023
ccnetcore
typescript
initToDetail
const initToDetail = (model: "query" | "params") => { if (getParameter) toDetail(getParameter, model); };
// 用于页面刷新,重新获取浏览器地址栏参数并保存到标签页
https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/views/tabs/hooks.ts#L64-L66
e03895bcb6eca1f1894af1de15784838172956d5
react-native-audio-waveform
github_2023
SimformSolutionsPvtLtd
typescript
styles
const styles = (params: StyleSheetParams = {}) => StyleSheet.create({ appContainer: { flex: 1, backgroundColor: useColorScheme() === "dark" ? Colors.gray : Colors.white, }, screenBackground: { flex: 1, paddingBottom: params.bottom, }, container: { flex: 1, paddingTop: params.top, paddingHorizontal: scale(16), marginBottom: scale(24), }, buttonContainer: { flexDirection: 'row', borderRadius: scale(10), alignItems: 'center', overflow: 'hidden', columnGap: scale(8), paddingHorizontal: scale(8), backgroundColor: params.currentUser ? Colors.darkGray : Colors.pink, }, listItemContainer: { marginTop: scale(16), alignItems: params.currentUser ? 'flex-end' : 'flex-start', }, listItemWidth: { width: '90%', }, buttonImage: { height: scale(22), width: scale(22), tintColor: Colors.white, alignSelf: 'flex-end', }, stopButton: { height: scale(22), width: scale(22), alignSelf: 'center', }, pinkButtonImage: { height: scale(22), width: scale(22), tintColor: Colors.pink, alignSelf: 'flex-end', }, staticWaveformView: { flex: 1, height: scale(75), }, playBackControlPressable: { height: scale(30), width: scale(30), justifyContent: 'center', }, recordAudioPressable: { height: scale(40), width: scale(40), padding: scale(8), }, liveWaveformContainer: { flexDirection: 'row', marginBottom: scale(8), borderRadius: scale(8), alignItems: 'center', paddingHorizontal: scale(16), }, simformImage: { height: scale(50), width: scale(200), }, liveWaveformView: { flex: 1, borderWidth: scale(0.5), borderRadius: scale(8), paddingHorizontal: scale(10), }, buttonImageLive: { height: '100%', width: '100%', tintColor: Colors.pink, }, headerContainer: { alignItems: 'center', }, deleteRecordingContainer: { alignItems: 'center', flexDirection: 'row', }, deleteRecordingTitle: { fontSize: scale(20), fontWeight: 'bold', color: Colors.pink, paddingLeft: scale(8), }, loadingText: { color: Colors.black, }, speedBox: { height: scale(28), width: scale(28), borderRadius: scale(14), justifyContent: 'center', tintColor: Colors.white, marginRight: scale(5), }, whiteBackground: { backgroundColor: Colors.white, }, speed: { color: Colors.black, fontSize: scale(10), textAlign: 'center', fontWeight: '600', }, });
/** * A StyleSheet object that contains all of the application's styles. * @param {ThemeMode} theme - The theme of the application. * @returns {StyleSheet} - A StyleSheet object containing all of the application's styles. */
https://github.com/SimformSolutionsPvtLtd/react-native-audio-waveform/blob/2c3282e299affdbd5c403b80671fe681b064fef6/example/src/styles.ts#L19-L137
2c3282e299affdbd5c403b80671fe681b064fef6
react-native-audio-waveform
github_2023
SimformSolutionsPvtLtd
typescript
copyFile
const copyFile = async ( value: string, destinationPath: string ): Promise<boolean> => { const fileExists = await fs.exists(`${destinationPath}/${value}`); if (!fileExists) { try { const file = await fs.readFileRes(`raw/${value}`, 'base64'); await fs.writeFile(`${destinationPath}/${value}`, file, 'base64'); return true; } catch (error) { console.error(`Error copying file ${value}: `, error); return false; } } return true; // File already exists };
/** * Copy a file to the specified destination path if it doesn't exist. * @param {string} value - The name of the file to copy. * @param {string} destinationPath - The destination path to copy the file to. * @returns {Promise<boolean>} A Promise that resolves to true if the file is copied successfully, otherwise false. */
https://github.com/SimformSolutionsPvtLtd/react-native-audio-waveform/blob/2c3282e299affdbd5c403b80671fe681b064fef6/example/src/constants/Audios.ts#L25-L43
2c3282e299affdbd5c403b80671fe681b064fef6
react-native-audio-waveform
github_2023
SimformSolutionsPvtLtd
typescript
copyFilesToNativeResources
const copyFilesToNativeResources = async (): Promise<string[]> => { if (globalMetrics.isAndroid) { const successfulCopies = await Promise.all( audioAssetArray.map(async value => { const isSuccess = await copyFile(value, filePath); return isSuccess ? value : null; }) ); // Filter out unsuccessful file copies return successfulCopies?.filter?.(value => value !== null); } // On iOS, return all files without copying return audioAssetArray; };
/** * Copy all files in the 'audioAssetArray' to the destination path (Android only), or return all files (iOS). * @returns {Promise<string[]>} A Promise that resolves to a list of successfully copied file paths. */
https://github.com/SimformSolutionsPvtLtd/react-native-audio-waveform/blob/2c3282e299affdbd5c403b80671fe681b064fef6/example/src/constants/Audios.ts#L49-L64
2c3282e299affdbd5c403b80671fe681b064fef6
litesvm
github_2023
LiteSVM
typescript
LiteSVM.constructor
constructor() { const inner = new LiteSVMInner(); this.inner = inner; }
/** Create a new LiteSVM instance with standard functionality enabled */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L94-L97
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.default
static default(): LiteSVM { const svm = new LiteSVM(); const inner = LiteSVMInner.default(); svm.inner = inner; return svm; }
/** Create a new LiteSVM instance with minimal functionality enabled */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L101-L106
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withComputeBudget
withComputeBudget(budget: ComputeBudget): LiteSVM { this.inner.setComputeBudget(budget); return this; }
/** * Set the compute budget * @param budget - The new compute budget * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L113-L116
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withSigverify
withSigverify(sigverify: boolean): LiteSVM { this.inner.setSigverify(sigverify); return this; }
/** * Enable or disable sigverify * @param sigverify - if false, transaction signatures will not be checked. * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L123-L126
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withBlockhashCheck
withBlockhashCheck(check: boolean): LiteSVM { this.inner.setBlockhashCheck(check); return this; }
/** * Enables or disables transaction blockhash checking. * @param check - If false, the blockhash check will be skipped * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L133-L136
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withSysvars
withSysvars(): LiteSVM { this.inner.setSysvars(); return this; }
/** * Sets up the standard sysvars. * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L142-L145
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withBuiltins
withBuiltins(featureSet?: FeatureSet): LiteSVM { this.inner.setBuiltins(featureSet); return this; }
/** * Adds the standard builtin programs. * @param featureSet if provided, decides what builtins to add based on what * features are active * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L153-L156
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withLamports
withLamports(lamports: bigint): LiteSVM { this.inner.setLamports(lamports); return this; }
/** * Changes the initial lamports in LiteSVM's airdrop account. * @param lamports - The number of lamports to set in the airdrop account * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L163-L166
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withSplPrograms
withSplPrograms(): LiteSVM { this.inner.setSplPrograms(); return this; }
/** * Adds the standard SPL programs. * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L172-L175
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withTransactionHistory
withTransactionHistory(capacity: bigint): LiteSVM { this.inner.setTransactionHistory(capacity); return this; }
/** * Changes the capacity of the transaction history. * @param capacity - How many transactions to store in history. * Set this to 0 to disable transaction history and allow duplicate transactions. * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L183-L186
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withLogBytesLimit
withLogBytesLimit(limit?: bigint): LiteSVM { this.inner.setLogBytesLimit(limit); return this; }
/** * Set a limit for transaction logs, beyond which they will be truncated. * @param limit - The limit in bytes. If null, no limit is enforced. * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L193-L196
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.withPrecompiles
withPrecompiles(featureSet?: FeatureSet): LiteSVM { this.inner.setPrecompiles(featureSet); return this; }
/** * Adds the standard precompiles. * @param featureSet if provided, decides what precompiles to add based on what * features are active * @returns The modified LiteSVM instance */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L204-L207
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.minimumBalanceForRentExemption
minimumBalanceForRentExemption(dataLen: bigint): bigint { return this.inner.minimumBalanceForRentExemption(dataLen); }
/** * Calculates the minimum balance required to make an account with specified data length rent exempt. * @param dataLen - The number of bytes in the account. * @returns The required balance in lamports */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L214-L216
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getAccount
getAccount(address: PublicKey): AccountInfoBytes | null { const inner = this.inner.getAccount(address.toBytes()); return inner === null ? null : toAccountInfo(inner); }
/** * Return the account at the given address. * If the account is not found, None is returned. * @param address - The account address to look up. * @returns The account object, if the account exists. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L224-L227
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setAccount
setAccount(address: PublicKey, account: AccountInfoBytes) { this.inner.setAccount(address.toBytes(), fromAccountInfo(account)); }
/** * Create or overwrite an account, subverting normal runtime checks. * * This method exists to make it easier to set up artificial situations * that would be difficult to replicate by sending individual transactions. * Beware that it can be used to create states that would not be reachable * by sending transactions! * * @param address - The address to write to. * @param account - The account object to write. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L240-L242
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getBalance
getBalance(address: PublicKey): bigint | null { return this.inner.getBalance(address.toBytes()); }
/** * Gets the balance of the provided account address. * @param address - The account address. * @returns The account's balance in lamports. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L249-L251
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.latestBlockhash
latestBlockhash(): string { return this.inner.latestBlockhash(); }
/** * Gets the latest blockhash. * Since LiteSVM doesn't have blocks, this is an arbitrary value controlled by LiteSVM * @returns The designated latest blockhash. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L258-L260
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getTransaction
getTransaction( signature: Uint8Array, ): TransactionMetadata | FailedTransactionMetadata | null { return this.inner.getTransaction(signature); }
/** * Gets a transaction from the transaction history. * @param signature - The transaction signature bytes * @returns The transaction, if it is found in the history. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L267-L271
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.airdrop
airdrop( address: PublicKey, lamports: bigint, ): TransactionMetadata | FailedTransactionMetadata | null { return this.inner.airdrop(address.toBytes(), lamports); }
/** * Airdrops the lamport amount specified to the given address. * @param address The airdrop recipient. * @param lamports - The amount to airdrop. * @returns The transaction result. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L279-L284
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.addProgramFromFile
addProgramFromFile(programId: PublicKey, path: string) { return this.inner.addProgramFromFile(programId.toBytes(), path); }
/** * Adds an SBF program to the test environment from the file specified. * @param programId - The program ID. * @param path - The path to the .so file. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L291-L293
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.addProgram
addProgram(programId: PublicKey, programBytes: Uint8Array) { return this.inner.addProgram(programId.toBytes(), programBytes); }
/** * Adds am SBF program to the test environment. * @param programId - The program ID. * @param programBytes - The raw bytes of the compiled program. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L300-L302
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.sendTransaction
sendTransaction( tx: Transaction | VersionedTransaction, ): TransactionMetadata | FailedTransactionMetadata { const internal = this.inner; const serialized = tx.serialize({ requireAllSignatures: true, verifySignatures: internal.getSigverify(), }); if (tx instanceof Transaction) { return internal.sendLegacyTransaction(serialized); } else { return internal.sendVersionedTransaction(serialized); } }
/** * Processes a transaction and returns the result. * @param tx - The transaction to send. * @returns TransactionMetadata if the transaction succeeds, else FailedTransactionMetadata */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L309-L323
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.simulateTransaction
simulateTransaction( tx: Transaction | VersionedTransaction, ): FailedTransactionMetadata | SimulatedTransactionInfo { const internal = this.inner; const serialized = tx.serialize({ requireAllSignatures: true, verifySignatures: internal.getSigverify(), }); const inner = tx instanceof Transaction ? internal.simulateLegacyTransaction(serialized) : internal.simulateVersionedTransaction(serialized); return inner instanceof FailedTransactionMetadata ? inner : new SimulatedTransactionInfo(inner); }
/** * Simulates a transaction * @param tx The transaction to simulate * @returns SimulatedTransactionInfo if simulation succeeds, else FailedTransactionMetadata */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L330-L345
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.expireBlockhash
expireBlockhash() { this.inner.expireBlockhash(); }
/** * Expires the current blockhash. * The return value of `latestBlockhash()` will be different after calling this. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L351-L353
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.warpToSlot
warpToSlot(slot: bigint) { this.inner.warpToSlot(slot); }
/** * Warps the clock to the specified slot. This is a convenience wrapper * around `setClock()`. * @param slot - The new slot. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L360-L362
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getClock
getClock(): Clock { return this.inner.getClock(); }
/** * Get the cluster clock. * @returns the clock object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L368-L370
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setClock
setClock(clock: Clock) { this.inner.setClock(clock); }
/** * Overwrite the clock sysvar. * @param clock - The clock object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L376-L378
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getEpochRewards
getEpochRewards(): EpochRewards { return this.inner.getEpochRewards(); }
/** * Get the EpochRewards sysvar. * @returns the EpochRewards object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L384-L386
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setEpochRewards
setEpochRewards(rewards: EpochRewards) { this.inner.setEpochRewards(rewards); }
/** * Overwrite the EpochRewards sysvar. * @param rewards - The EpochRewards object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L392-L394
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getEpochSchedule
getEpochSchedule(): EpochSchedule { return this.inner.getEpochSchedule(); }
/** * Get the EpochSchedule sysvar. * @returns the EpochSchedule object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L400-L402
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setEpochSchedule
setEpochSchedule(schedule: EpochSchedule) { this.inner.setEpochSchedule(schedule); }
/** * Overwrite the EpochSchedule sysvar. * @param schedule - The EpochSchedule object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L408-L410
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getLastRestartSlot
getLastRestartSlot(): bigint { return this.inner.getLastRestartSlot(); }
/** * Get the last restart slot sysvar. * @returns the last restart slot. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L416-L418
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setLastRestartSlot
setLastRestartSlot(slot: bigint) { this.inner.setLastRestartSlot(slot); }
/** * Overwrite the last restart slot sysvar. * @param slot - The last restart slot. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L424-L426
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getRent
getRent(): Rent { return this.inner.getRent(); }
/** * Get the cluster rent. * @returns The rent object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L432-L434
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setRent
setRent(rent: Rent) { this.inner.setRent(rent); }
/** * Overwrite the rent sysvar. * @param rent - The new rent object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L440-L442
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getSlotHashes
getSlotHashes(): SlotHash[] { return this.inner.getSlotHashes(); }
/** * Get the SlotHashes sysvar. * @returns The SlotHash array. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L448-L450
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setSlotHashes
setSlotHashes(hashes: SlotHash[]) { this.inner.setSlotHashes(hashes); }
/** * Overwrite the SlotHashes sysvar. * @param hashes - The SlotHash array. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L456-L458
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getSlotHistory
getSlotHistory(): SlotHistory { return this.inner.getSlotHistory(); }
/** * Get the SlotHistory sysvar. * @returns The SlotHistory object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L464-L466
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setSlotHistory
setSlotHistory(history: SlotHistory) { this.inner.setSlotHistory(history); }
/** * Overwrite the SlotHistory sysvar. * @param history - The SlotHistory object */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L472-L474
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.getStakeHistory
getStakeHistory(): StakeHistory { return this.inner.getStakeHistory(); }
/** * Get the StakeHistory sysvar. * @returns The StakeHistory object. */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L480-L482
8113575d6778163a134d92e48add90fd0c8c5130
litesvm
github_2023
LiteSVM
typescript
LiteSVM.setStakeHistory
setStakeHistory(history: StakeHistory) { this.inner.setStakeHistory(history); }
/** * Overwrite the StakeHistory sysvar. * @param history - The StakeHistory object */
https://github.com/LiteSVM/litesvm/blob/8113575d6778163a134d92e48add90fd0c8c5130/crates/node-litesvm/litesvm/index.ts#L488-L490
8113575d6778163a134d92e48add90fd0c8c5130
siteone-crawler-gui
github_2023
janreges
typescript
CrawlerFormContent.makeCorrections
private makeCorrections(): void { if (this.offlineExportDir !== null && this.offlineExportDir.trim() === '') { this.offlineExportDir = '%domain%'; } if (this.sitemapXmlFile !== null && this.sitemapXmlFile.trim() === '.sitemap.xml') { this.sitemapXmlFile = '%domain%.sitemap.xml'; } if (this.sitemapTxtFile !== null && this.sitemapTxtFile.trim() === '.sitemap.txt') { this.sitemapTxtFile = '%domain%.sitemap.txt'; } }
// }
https://github.com/janreges/siteone-crawler-gui/blob/88f4916d2bb580fc4de63996ea005f92174c9f02/src/renderer/src/types/CrawlerFormContent.ts#L300-L310
88f4916d2bb580fc4de63996ea005f92174c9f02
degital-twin-3d
github_2023
anyone-yuren
typescript
ThreeMobx
function ThreeMobx({ children }: IProps) { return <ThreeStore>{children}</ThreeStore>; }
// 实例化根store
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/mobx-store/modules/three/index.tsx#L12-L14
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
Canva
const Canva = (props) => { return ( <> {/* <Tools /> */} <Canvas shadows gl={{ logarithmicDepthBuffer: true, }} > {/* 场景类 */} <BaseSence /> {/* 工厂类 */} <Factory /> {props.children} {/* 帮助类 */} <Gizmo /> </Canvas> </> ); };
// 创建Canva组件
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/three/Canva/index.tsx#L9-L29
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
BaseSence
const BaseSence = () => { const threeStore = useContext(ThreeStoreContext); // console.log('3D中的', ThreeStore.visible); return ( <group> <Lights /> <Camera /> <SkyBox /> {/* <GridModule /> */} {/* 其他 */} {/* <Man /> */} {/* 建筑 */} <Buildings /> {/* 树 */} <TreeGroup /> </group> ); };
// 创建Canva组件
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/three/Canva/components/BaseSence/index.tsx#L17-L36
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
sleep
const sleep = (time: number | undefined) => // @ts-ignore new Promise<void>((resolve) => { setTimeout(() => { resolve(); }, time); });
/** * @description sleep * @param {number} time */
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/utils/module/common.ts#L15-L21
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
autoAddPrefix
const autoAddPrefix = (key: string) => { const prefix = config.prefix ? config.prefix + '_' : ''; return prefix + key; };
// 名称前自动添加前缀
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/utils/module/storage.ts#L183-L186
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
autoRemovePrefix
const autoRemovePrefix = (key: { substr: (arg: string | number | null) => string }) => { const len = config.prefix ? config.prefix.length + 1 : ''; return key.substr(len); };
// 移除已添加的前缀
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/utils/module/storage.ts#L189-L192
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
encrypt
const encrypt = (data: string) => { if (typeof data === 'object') { try { data = JSON.stringify(data); } catch (error) { console.log('encrypt error:', error); } } const dataHex = CryptoJS.enc.Utf8.parse(data); const encrypted = CryptoJS.AES.encrypt(dataHex, SECRET_KEY, { iv: SECRET_IV, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, }); return encrypted.ciphertext.toString(); };
/** * 加密方法 * @param data * @returns {string} */
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/utils/module/storage.ts#L199-L214
6628c0b3ebe526121982617dd53d07aae9db839f
degital-twin-3d
github_2023
anyone-yuren
typescript
decrypt
const decrypt = (data: string) => { const encryptedHexStr = CryptoJS.enc.Hex.parse(data); const str = CryptoJS.enc.Base64.stringify(encryptedHexStr); const decrypt = CryptoJS.AES.decrypt(str, SECRET_KEY, { iv: SECRET_IV, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, }); const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8); return decryptedStr.toString(); };
/** * 解密方法 * @param data * @returns {string} */
https://github.com/anyone-yuren/degital-twin-3d/blob/6628c0b3ebe526121982617dd53d07aae9db839f/packages/utils/module/storage.ts#L221-L231
6628c0b3ebe526121982617dd53d07aae9db839f
nodejs-vertexai
github_2023
googleapis
typescript
VertexAI.constructor
constructor(init: VertexInit) { const opts = validateGoogleAuthOptions( init.project, init.googleAuthOptions ); this.location = resolveLocation(init.location); this.project = resolveProject(init.project); this.googleAuth = new GoogleAuth(opts); this.apiEndpoint = init.apiEndpoint; this.preview = new VertexAIPreview( this.project, this.location, this.googleAuth, this.apiEndpoint ); }
/** * @constructor * @param init - assign authentication related information, * including the project and location strings, to instantiate a Vertex AI * client. * @throws {IllegalArgumentError} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/vertex_ai.ts#L58-L73
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
VertexAI.getGenerativeModel
getGenerativeModel( modelParams: ModelParams, requestOptions?: RequestOptions ): GenerativeModel { const getGenerativeModelParams: GetGenerativeModelParams = { model: modelParams.model, project: this.project, location: this.location, googleAuth: this.googleAuth, apiEndpoint: this.apiEndpoint, safetySettings: modelParams.safetySettings, generationConfig: modelParams.generationConfig, tools: modelParams.tools, toolConfig: modelParams.toolConfig, requestOptions: requestOptions, systemInstruction: modelParams.systemInstruction, }; return new GenerativeModel(getGenerativeModelParams); }
/** * Gets the GenerativeModel class instance. * * This method creates a new instance of the `GenerativeModel` class with the * platform initialization parameters provided in {@link VertexInit} and model * initialization parameters provided in {@link ModelParams}. You can * optionally provide {@link RequestOptions} to override the default request * options. * * @example * ``` * const project = 'your-cloud-project'; * const location = 'us-central1'; * const textModel = 'gemini-1.0-pro'; * const visionModel = 'gemini-1.0-pro-vision'; * * const vertexAI = new VertexAI({project: project, location: location}); * * // Instantiate models * const generativeModel = vertexAI.getGenerativeModel({ * model: textModel, * // The following parameters are optional * // They can also be passed to individual content generation requests * safetySettings: [{ * category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, * threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE * }], * generationConfig: {maxOutputTokens: 256}, * }); * * const generativeVisionModel = vertexAI.getGenerativeModel({ * model: visionModel, * }); * * const generativeModelPreview = vertexAI.preview.getGenerativeModel({ * model: textModel, * }); * ``` * * @param modelParams - {@link ModelParams} Parameters to * specify the generative model. * @param requestOptions - {@link RequestOptions} Parameters to specify * request options * @returns Instance of the GenerativeModel class. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/vertex_ai.ts#L120-L138
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
VertexAIPreview.constructor
constructor( project: string, location: string, googleAuth: GoogleAuth, apiEndpoint?: string ) { this.project = project; this.location = location; this.googleAuth = googleAuth; this.apiEndpoint = apiEndpoint; this.apiClient = new Resources.ApiClient( this.project, this.location, 'v1beta1', this.googleAuth ); this.cachedContents = new Resources.CachedContents(this.apiClient); }
/** * @constructor * @param project - The Google Cloud project to use for the request * @param location - location The Google Cloud project location to use for the * request * @param googleAuth - The GoogleAuthen class instance from * google-auth-library. * Complete list of authentication options is documented in the * GoogleAuthOptions interface: * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts * @param apiEndpoint - [apiEndpoint] The base Vertex AI endpoint to use for * the request. If * not provided, the default regionalized endpoint * (i.e. us-central1-aiplatform.googleapis.com) will be used. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/vertex_ai.ts#L177-L195
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
VertexAIPreview.getGenerativeModel
getGenerativeModel( modelParams: ModelParams, requestOptions?: RequestOptions ): GenerativeModelPreview { const getGenerativeModelParams: GetGenerativeModelParams = { model: modelParams.model, project: this.project, location: this.location, googleAuth: this.googleAuth, apiEndpoint: this.apiEndpoint, safetySettings: modelParams.safetySettings, generationConfig: modelParams.generationConfig, tools: modelParams.tools, toolConfig: modelParams.toolConfig, requestOptions: requestOptions, systemInstruction: modelParams.systemInstruction, }; return new GenerativeModelPreview(getGenerativeModelParams); }
/** * @param modelParams - {@link ModelParams} Parameters to * specify the generative model. * @returns Instance of the GenerativeModelPreview class. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/vertex_ai.ts#L202-L220
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
getResponseStream
function getResponseStream( inputStream: ReadableStream<string> ): ReadableStream<unknown> { const reader = inputStream.getReader(); const stream = new ReadableStream<unknown>({ start(controller) { let currentText = ''; return pump(); function pump(): Promise<(() => Promise<void>) | undefined> { return reader.read().then(({value, done}) => { if (done) { if (currentText.trim()) { controller.error( new GoogleGenerativeAIError( `Failed to parse final chunk of stream: ${currentText}` ) ); return; } controller.close(); return; } currentText += value; let match = currentText.match(responseLineRE); let parsedResponse: unknown; while (match) { try { parsedResponse = JSON.parse(match[1]); } catch (e) { controller.error( new GoogleGenerativeAIError( `Error parsing JSON response from stream chunk: "${match[1]}"` ) ); return; } controller.enqueue(parsedResponse); currentText = currentText.substring(match[0].length); match = currentText.match(responseLineRE); } return pump(); }); } }, }); return stream; }
/** * Reads a raw stream from the fetch response and join incomplete * chunks, returning a new stream that provides a single complete * GenerateContentResponse in each iteration. * @ignore */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/functions/post_fetch_processing.ts#L133-L180
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSession.constructor
constructor( request: StartChatSessionRequest, requestOptions?: RequestOptions ) { this.project = request.project; this.location = request.location; this.googleAuth = request.googleAuth; this.resourcePath = request.resourcePath; this.historyInternal = request.history ?? []; this.generationConfig = request.generationConfig; this.safetySettings = request.safetySettings; this.tools = request.tools; this.toolConfig = request.toolConfig; this.apiEndpoint = request.apiEndpoint; this.requestOptions = requestOptions ?? {}; if (request.systemInstruction) { this.systemInstruction = formulateSystemInstructionIntoContent( request.systemInstruction ); } }
/** * @constructor * @param request - {@link StartChatSessionRequest} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L73-L93
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSessionPreview.fetchToken
private fetchToken(): Promise<string | null | undefined> { const tokenPromise = this.googleAuth.getAccessToken().catch(e => { throw new GoogleAuthError(constants.CREDENTIAL_ERROR_MESSAGE, e); }); return tokenPromise; }
/** * Gets access token from GoogleAuth. Throws {@link GoogleAuthError} when * fails. * @returns Promise of token. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L100-L105
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSession.sendMessage
async sendMessage( request: string | Array<string | Part> ): Promise<GenerateContentResult> { const newContent: Content[] = formulateNewContentFromSendMessageRequest(request); const generateContentRequest: GenerateContentRequest = { contents: this.historyInternal.concat(newContent), safetySettings: this.safetySettings, generationConfig: this.generationConfig, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, }; const generateContentResult: GenerateContentResult = await generateContent( this.location, this.resourcePath, this.fetchToken(), generateContentRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ).catch(e => { throw e; }); const generateContentResponse = await generateContentResult.response; // Only push the latest message to history if the response returns a result if ( generateContentResponse.candidates && generateContentResponse.candidates.length !== 0 ) { this.historyInternal = this.historyInternal.concat(newContent); const contentFromModel = generateContentResponse.candidates[0].content; this.historyInternal.push(contentFromModel); } return Promise.resolve(generateContentResult); }
/** * Makes an async call to send chat message. * * The response is returned in {@link * GenerateContentResult.response}. * * @example * ``` * const chat = generativeModel.startChat(); * const result1 = await chat.sendMessage("How can I learn more about Node.js?"); * console.log('Response: ', JSON.stringify(result1.response)); * * const result2 = await chat.sendMessage("What about python?"); * console.log('Response: ', JSON.stringify(result2.response)); * ``` * * @param request - send message request. * @returns Promise of {@link GenerateContentResult}. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L126-L166
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSession.sendMessageStream
async sendMessageStream( request: string | Array<string | Part> ): Promise<StreamGenerateContentResult> { const newContent: Content[] = formulateNewContentFromSendMessageRequest(request); const generateContentrequest: GenerateContentRequest = { contents: this.historyInternal.concat(newContent), safetySettings: this.safetySettings, generationConfig: this.generationConfig, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, }; const streamGenerateContentResultPromise = generateContentStream( this.location, this.resourcePath, this.fetchToken(), generateContentrequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ).catch(e => { throw e; }); this.sendStreamPromise = this.appendHistory( streamGenerateContentResultPromise, newContent ).catch(e => { // Errors from remote endpoint will be catchable by user from streamGenerateContentResultPromise // Errors in appendHistory should not throw to cause user's programe exit with code 1 console.error(e); }); return streamGenerateContentResultPromise; }
/** * Makes an async call to stream send message. * * The response is streamed chunk by chunk in * {@link StreamGenerateContentResult.stream}. The aggregated response is * avaliable in {@link StreamGenerateContentResult.response} after all chunks * are returned. * * @example * ``` * const chat = generativeModel.startChat(); * const chatInput = "How can I learn more about Node.js?"; * const result = await chat.sendMessageStream(chatInput); * for await (const item of result.stream) { * console.log(item.candidates[0].content.parts[0].text); * } * const response = await result.response; * console.log('aggregated response: ', JSON.stringify(result.response)); * ``` * * @param request - send message request. * @returns Promise of {@link StreamGenerateContentResult}. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L211-L249
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSessionPreview.constructor
constructor( request: StartChatSessionRequest, requestOptions?: RequestOptions ) { this.project = request.project; this.location = request.location; this.googleAuth = request.googleAuth; this.resourcePath = request.resourcePath; this.historyInternal = request.history ?? []; this.generationConfig = request.generationConfig; this.safetySettings = request.safetySettings; this.tools = request.tools; this.toolConfig = request.toolConfig; this.apiEndpoint = request.apiEndpoint; this.requestOptions = requestOptions ?? {}; this.cachedContent = request.cachedContent; if (request.systemInstruction) { this.systemInstruction = formulateSystemInstructionIntoContent( request.systemInstruction ); } }
/** * @constructor * @param request - {@link StartChatSessionRequest} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L284-L305
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSessionPreview.sendMessage
async sendMessage( request: string | Array<string | Part> ): Promise<GenerateContentResult> { const newContent: Content[] = formulateNewContentFromSendMessageRequest(request); const generateContentRequest: GenerateContentRequest = { contents: this.historyInternal.concat(newContent), safetySettings: this.safetySettings, generationConfig: this.generationConfig, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: this.cachedContent, }; const generateContentResult: GenerateContentResult = await generateContent( this.location, this.resourcePath, this.fetchToken(), generateContentRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ).catch(e => { throw e; }); const generateContentResponse = await generateContentResult.response; // Only push the latest message to history if the response returned a result if ( generateContentResponse.candidates && generateContentResponse.candidates.length !== 0 ) { this.historyInternal = this.historyInternal.concat(newContent); const contentFromAssistant = generateContentResponse.candidates[0].content; this.historyInternal.push(contentFromAssistant); } return Promise.resolve(generateContentResult); }
/** * Makes an async call to send chat message. * * The response is returned in {@link * GenerateContentResult.response}. * * @example * ``` * const chat = generativeModelPreview.startChat(); * const result1 = await chat.sendMessage("How can I learn more about Node.js?"); * console.log('Response: ', JSON.stringify(result1.response)); * * const result2 = await chat.sendMessage("What about python?"); * console.log('Response: ', JSON.stringify(result2.response)); * ``` * * @param request - send message request. * @returns Promise of {@link GenerateContentResult}. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L337-L379
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
ChatSessionPreview.sendMessageStream
async sendMessageStream( request: string | Array<string | Part> ): Promise<StreamGenerateContentResult> { const newContent: Content[] = formulateNewContentFromSendMessageRequest(request); const generateContentRequest: GenerateContentRequest = { contents: this.historyInternal.concat(newContent), safetySettings: this.safetySettings, generationConfig: this.generationConfig, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: this.cachedContent, }; const streamGenerateContentResultPromise = generateContentStream( this.location, this.resourcePath, this.fetchToken(), generateContentRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ).catch(e => { throw e; }); this.sendStreamPromise = this.appendHistory( streamGenerateContentResultPromise, newContent ).catch(e => { // Errors from remote endpoint will be catchable by user from streamGenerateContentResultPromise // Errors in appendHistory should not throw to cause user's programe exit with code 1 console.error(e); }); return streamGenerateContentResultPromise; }
/** * Makes an async call to stream send message. * * The response is streamed chunk by chunk in * {@link StreamGenerateContentResult.stream}. The aggregated response is * avaliable in {@link StreamGenerateContentResult.response} after all chunks * are returned. * * @example * ``` * const chat = generativeModel.startChat(); * const chatInput = "How can I learn more about Node.js?"; * const result = await chat.sendMessageStream(chatInput); * for await (const item of result.stream) { * console.log(item.candidates[0].content.parts[0].text); * } * const response = await result.response; * console.log('aggregated response: ', JSON.stringify(result.response)); * ``` * * @param request - send message request. * @returns Promise of {@link StreamGenerateContentResult}. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L424-L463
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
assignRoleToPartsAndValidateSendMessageRequest
function assignRoleToPartsAndValidateSendMessageRequest( parts: Array<Part> ): Content[] { const userContent: Content = {role: constants.USER_ROLE, parts: []}; const functionContent: Content = {role: constants.USER_ROLE, parts: []}; let hasUserContent = false; let hasFunctionContent = false; for (const part of parts) { if ('functionResponse' in part) { functionContent.parts.push(part); hasFunctionContent = true; } else { userContent.parts.push(part); hasUserContent = true; } } if (hasUserContent && hasFunctionContent) { throw new ClientError( 'Within a single message, FunctionResponse cannot be mixed with other type of part in the request for sending chat message.' ); } if (!hasUserContent && !hasFunctionContent) { throw new ClientError('No content is provided for sending chat message.'); } if (hasUserContent) { return [userContent]; } return [functionContent]; }
/** * When multiple Part types (i.e. FunctionResponsePart and TextPart) are * passed in a single Part array, we may need to assign different roles to each * part. Currently only FunctionResponsePart requires a role other than 'user'. * @ignore * @param parts Array of parts to pass to the model * @returns Array of content items */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/chat_session.ts#L494-L526
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModel.constructor
constructor(getGenerativeModelParams: GetGenerativeModelParams) { this.project = getGenerativeModelParams.project; this.location = getGenerativeModelParams.location; this.apiEndpoint = getGenerativeModelParams.apiEndpoint; this.googleAuth = getGenerativeModelParams.googleAuth; this.model = getGenerativeModelParams.model; this.generationConfig = getGenerativeModelParams.generationConfig; this.safetySettings = getGenerativeModelParams.safetySettings; this.tools = getGenerativeModelParams.tools; this.toolConfig = getGenerativeModelParams.toolConfig; this.requestOptions = getGenerativeModelParams.requestOptions ?? {}; if (getGenerativeModelParams.systemInstruction) { this.systemInstruction = formulateSystemInstructionIntoContent( getGenerativeModelParams.systemInstruction ); } this.resourcePath = formulateResourcePathFromModel( this.model, this.project, this.location ); // publisherModelEndpoint is deprecated this.publisherModelEndpoint = this.resourcePath; }
/** * @constructor * @param getGenerativeModelParams - {@link GetGenerativeModelParams} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L74-L97
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModelPreview.fetchToken
private fetchToken(): Promise<string | null | undefined> { const tokenPromise = this.googleAuth.getAccessToken().catch(e => { throw new GoogleAuthError(constants.CREDENTIAL_ERROR_MESSAGE, e); }); return tokenPromise; }
/** * Gets access token from GoogleAuth. Throws {@link GoogleAuthError} when * fails. * @returns Promise of token string. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L104-L109
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModel.generateContent
async generateContent( request: GenerateContentRequest | string ): Promise<GenerateContentResult> { request = formulateRequestToGenerateContentRequest(request); const formulatedRequest = formulateSystemInstructionIntoGenerateContentRequest( request, this.systemInstruction ); return generateContent( this.location, this.resourcePath, this.fetchToken(), formulatedRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ); }
/** * Makes an async call to generate content. * * The response will be returned in {@link * GenerateContentResult.response}. * * @example * ``` * const request = { * contents: [{role: 'user', parts: [{text: 'How are you doing today?'}]}], * }; * const result = await generativeModel.generateContent(request); * console.log('Response: ', JSON.stringify(result.response)); * ``` * * @param request - A GenerateContentRequest object with the request contents. * @returns The GenerateContentResponse object with the response candidates. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L129-L150
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModel.generateContentStream
async generateContentStream( request: GenerateContentRequest | string ): Promise<StreamGenerateContentResult> { request = formulateRequestToGenerateContentRequest(request); const formulatedRequest = formulateSystemInstructionIntoGenerateContentRequest( request, this.systemInstruction ); return generateContentStream( this.location, this.resourcePath, this.fetchToken(), formulatedRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ); }
/** * Makes an async stream request to generate content. * * The response is returned chunk by chunk as it's being generated in {@link * StreamGenerateContentResult.stream}. After all chunks of the response are * returned, the aggregated response is available in * {@link StreamGenerateContentResult.response}. * * @example * ``` * const request = { * contents: [{role: 'user', parts: [{text: 'How are you doing today?'}]}], * }; * const streamingResult = await generativeModel.generateContentStream(request); * for await (const item of streamingResult.stream) { * console.log('stream chunk: ', JSON.stringify(item)); * } * const aggregatedResponse = await streamingResult.response; * console.log('aggregated response: ', JSON.stringify(aggregatedResponse)); * ``` * * @param request - {@link GenerateContentRequest} * @returns Promise of {@link StreamGenerateContentResult} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L176-L197
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModelPreview.countTokens
async countTokens(request: CountTokensRequest): Promise<CountTokensResponse> { return countTokens( this.location, this.resourcePath, this.fetchToken(), request, this.apiEndpoint, this.requestOptions ); }
/** * Makes an async request to count tokens. * * The `countTokens` function returns the token count and the number of * billable characters for a prompt. * * @example * ``` * const request = { * contents: [{role: 'user', parts: [{text: 'How are you doing today?'}]}], * }; * const resp = await generativeModelPreview.countTokens(request); * console.log('count tokens response: ', resp); * ``` * * @param request - A CountTokensRequest object with the request contents. * @returns The CountTokensResponse object with the token count. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L217-L226
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModel.startChat
startChat(request?: StartChatParams): ChatSession { const startChatRequest: StartChatSessionRequest = { project: this.project, location: this.location, googleAuth: this.googleAuth, publisherModelEndpoint: this.publisherModelEndpoint, resourcePath: this.resourcePath, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, }; if (request) { startChatRequest.history = request.history; startChatRequest.generationConfig = request.generationConfig ?? this.generationConfig; startChatRequest.safetySettings = request.safetySettings ?? this.safetySettings; startChatRequest.tools = request.tools ?? this.tools; startChatRequest.toolConfig = request.toolConfig ?? this.toolConfig; startChatRequest.apiEndpoint = request.apiEndpoint ?? this.apiEndpoint; startChatRequest.systemInstruction = request.systemInstruction ?? this.systemInstruction; } return new ChatSession(startChatRequest, this.requestOptions); }
/** * Instantiates a {@link ChatSession}. * * The {@link ChatSession} class is a stateful class that holds the state of * the conversation with the model and provides methods to interact with the * model in chat mode. Calling this method doesn't make any calls to a remote * endpoint. To make remote call, use {@link ChatSession.sendMessage} or * @link ChatSession.sendMessageStream}. * * @example * ``` * const chat = generativeModel.startChat(); * const result1 = await chat.sendMessage("How can I learn more about Node.js?"); * const response1 = await result1.response; * console.log('Response: ', JSON.stringify(response1)); * * const result2 = await chat.sendMessageStream("What about python?"); * const response2 = await result2.response; * console.log('Response: ', JSON.stringify(await response2)); * ``` * * @param request - {@link StartChatParams} * @returns {@link ChatSession} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L252-L277
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModelPreview.constructor
constructor(getGenerativeModelParams: GetGenerativeModelParams) { this.project = getGenerativeModelParams.project; this.location = getGenerativeModelParams.location; this.apiEndpoint = getGenerativeModelParams.apiEndpoint; this.googleAuth = getGenerativeModelParams.googleAuth; this.model = getGenerativeModelParams.model; this.generationConfig = getGenerativeModelParams.generationConfig; this.safetySettings = getGenerativeModelParams.safetySettings; this.tools = getGenerativeModelParams.tools; this.toolConfig = getGenerativeModelParams.toolConfig; this.cachedContent = getGenerativeModelParams.cachedContent; this.requestOptions = getGenerativeModelParams.requestOptions ?? {}; if (getGenerativeModelParams.systemInstruction) { this.systemInstruction = formulateSystemInstructionIntoContent( getGenerativeModelParams.systemInstruction ); } this.resourcePath = formulateResourcePathFromModel( this.model, this.project, this.location ); // publisherModelEndpoint is deprecated this.publisherModelEndpoint = this.resourcePath; }
/** * @constructor * @param getGenerativeModelParams - {@link GetGenerativeModelParams} */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L306-L330
99f3ee8a4589b97f32fa14e0f3adc01163cd9846
nodejs-vertexai
github_2023
googleapis
typescript
GenerativeModelPreview.generateContent
async generateContent( request: GenerateContentRequest | string ): Promise<GenerateContentResult> { request = formulateRequestToGenerateContentRequest(request); const formulatedRequest = { ...formulateSystemInstructionIntoGenerateContentRequest( request, this.systemInstruction ), cachedContent: this.cachedContent?.name, }; return generateContent( this.location, this.resourcePath, this.fetchToken(), formulatedRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, this.tools, this.toolConfig, this.requestOptions ); }
/** * Makes an async call to generate content. * * The response will be returned in {@link GenerateContentResult.response}. * * @example * ``` * const request = { * contents: [{role: 'user', parts: [{text: 'How are you doing today?'}]}], * }; * const result = await generativeModelPreview.generateContent(request); * console.log('Response: ', JSON.stringify(result.response)); * ``` * * @param request - A GenerateContentRequest object with the request contents. * @returns The GenerateContentResponse object with the response candidates. */
https://github.com/googleapis/nodejs-vertexai/blob/99f3ee8a4589b97f32fa14e0f3adc01163cd9846/src/models/generative_models.ts#L361-L384
99f3ee8a4589b97f32fa14e0f3adc01163cd9846