Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@deep-foundation/chatgpt-azure

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deep-foundation/chatgpt-azure - npm Package Compare versions

Comparing version 3.0.4 to 3.0.5

4

deep.json
{
"package": {
"name": "@deep-foundation/chatgpt-azure",
"version": "3.0.4"
"version": "3.0.5"
},

@@ -162,3 +162,3 @@ "data": [

"value": {
"value": "async ({ data: { newLink: reply, triggeredByLinkId }, deep }) => {\n const ml = deep.minilinks;\n\n const startTime = Date.now();\n const axios = await deep.import('axios');\n\n const ChatGPT = await deep.id(deep.linkId, 'ChatGPT');\n const Conversation = await deep.id(deep.linkId, 'Conversation');\n const ApiKey = await deep.id('@deep-foundation/openai', 'ApiKey');\n const UsesApiKey = await deep.id('@deep-foundation/openai', 'UsesApiKey');\n const Model = await deep.id('@deep-foundation/openai', 'Model');\n const UsesModel = await deep.id('@deep-foundation/openai', 'UsesModel');\n const Message = await deep.id('@deep-foundation/messaging', 'Message');\n const Reply = await deep.id('@deep-foundation/chatgpt-azure', 'Reply');\n const Author = await deep.id('@deep-foundation/messaging', 'Author');\n const messagingTree = await deep.id('@deep-foundation/messaging', 'messagingTree');\n const System = await deep.id('@deep-foundation/chatgpt-azure', 'System');\n const Tokens = await deep.id(\"@deep-foundation/tokens\", \"Tokens\")\n const ProvidedBy = await deep.id(\"@deep-foundation/chatgpt-azure\", \"ProvidedBy\")\n\n await deep.await(reply.from_id);\n\n const { data: [message] } = await deep.select({\n id: reply.from_id,\n _not: { out: { to_id: ChatGPT, type_id: Author } },\n });\n if (!message) return 'No need to react to message of this reply.';\n if (!message.value?.value) throw new Error(`Message (##${message?.id}) must have a value`);\n\n ml.apply(await deep.select({\n type_id: ApiKey,\n in: { from_id: triggeredByLinkId, type_id: UsesApiKey },\n return: {\n uses: { relation: 'in', type_id: UsesApiKey },\n },\n }), 'apikey');\n\n const apikeys = ml.select({ type_id: ApiKey });\n const useses = ml.select({ tyoe_id: UsesApiKey, to: { type_id: ApiKey } });\n \n if (!apikeys.length) throw new Error(`ApiKey not founded`);\n if (useses.length > 1) throw new Error(`More than 1 links of type UsesApiKey are found`);\n if (!apikeys[0]?.value?.value) throw new Error(`ApiKey ##${apikeys[0]?.id} has no value`);\n\n const { data: [conversation] } = await deep.select({\n type_id: Conversation,\n down: { tree_id: messagingTree, link_id: reply.id }\n });\n if (!conversation) return 'Conversation upper not founded.';\n\n const messagesByReply = await deep.select({\n type_id: Message,\n down: { tree_id: messagingTree, link_id: reply.from_id },\n order_by: { id: 'desc' },\n return: {\n authors: { relation: 'out', type_id: Author },\n tokens: { relation: 'out', type_id: Tokens },\n }\n });\n ml.apply(messagesByReply, 'messagesByReply');\n\n const messagesById = await deep.select({\n id: { _nin: messagesByReply.data.map(l => l.id) },\n type_id: Message,\n up: { tree_id: messagingTree, parent_id: conversation.id },\n order_by: { id: 'desc' },\n return: {\n authors: { relation: 'out', type_id: Author },\n tokens: { relation: 'out', type_id: Tokens },\n }\n });\n ml.apply(messagesById, 'messagesById');\n\n const messagesToSend = [...messagesByReply.data, ...messagesById.data];\n const models = await deep.select({\n type_id: Model,\n in: { type_id: UsesModel, from_id: { _in: [conversation.id, triggeredByLinkId] } },\n return: {\n usesModel: { relation: 'in', type_id: UsesModel },\n tokens: { relation: 'out', type_id: Tokens },\n providedBy: {\n relation: 'out', type_id: ProvidedBy,\n return: {\n endpoint: { relation: 'to' }\n },\n },\n },\n });\n ml.apply(models, 'models');\n\n const [userLinkedModel] = ml.select({ type_id: Model, in: { type_id: UsesModel, from_id: triggeredByLinkId } });\n if (!userLinkedModel) throw new Error(`UsersModel from triggeredByLinkId ${triggeredByLinkId} to Model not founded.`);\n const [userLinkedModelTokens] = ml.select({ type_id: Tokens, from_id: userLinkedModel?.id });\n const [linkedModel] = ml.select({ type_id: Model, in: { type_id: UsesModel, from_id: conversation.id } });\n \n const MAX_TOKENS = userLinkedModelTokens?.value?.value;\n if (!MAX_TOKENS) throw new Error(`MAX_TOKENS Tokens (##${userLinkedModelTokens?.id}) .value from model not founded.`);\n \n const endpoint = ml.select({ in: { type_id: ProvidedBy } })[0];\n const API_ENDPOINT = endpoint?.value?.value;\n if (!API_ENDPOINT) throw new Error(`API_ENDPOINT Endpoint (##${endpoint?.id}) instance.value nout founded.`);\n \n const model = linkedModel?.value?.value || userLinkedModel?.value?.value;\n if(!model) throw new Error(`UsersModel from conversation.id (##${conversation.id}) to Model not founded.`);\n\n let preparedMessages = messagesToSend.map((link) => {\n const tokens = ml.select({ type_id: Tokens, from_id: link.id })[0]?.value?.value;\n return {\n role: ml.select({ type_id: Author, from_id: link.id })[0]?.to_id === ChatGPT ? 'assistant' : 'user',\n content: link.value.value,\n tokens: ml.select({ type_id: Tokens, from_id: link.id })[0]?.value?.value,\n }\n });\n\n const systems = await deep.select({\n type_id: System, to_id: { _in: [triggeredByLinkId, conversation.id] },\n return: {\n message: { relation: 'from' },\n conversation: { relation: 'to' },\n tokens: { relation: 'in', type_id: Tokens },\n },\n });\n ml.apply(systems, 'systems');\n\n const conversationSystem = ml.select({ type_id: System, to_id: conversation.id })?.[0];\n if (!!conversationSystem && !conversationSystem?.value?.value) throw new Error(`System .value to conversation not defined`);\n const userSystems = ml.select({ type_id: System, to_id: triggeredByLinkId });\n if (userSystems.length > 1) throw new Error(\"Multiple system messages linked to the user are found\");\n const userSystem = userSystems[0];\n\n const systemMessage = conversationSystem?.from || userSystem?.from;\n if (systemMessage) {\n if (!systemMessage?.value?.value) throw new Error(`System (##${systemMessage?.id}) .from Message.value not founded`);\n await deep.await(systemMessage.id);\n const tokens = ml.select({ type_id: Tokens, from_id: systemMessage.id, to_id: systemMessage.id })?.[0];\n if (!tokens?.value?.value) throw new Error(`System (##${systemMessage?.id}) message does not contain tokens`);\n preparedMessages.unshift({ role: 'system', content: systemMessage?.value?.value, tokens: tokens?.value?.value });\n }\n\n const tokenLimit = MAX_TOKENS * 7 / 8;\n let totalTokens = 0;\n let messages = [];\n\n for (let i = preparedMessages.length - 1; i >= 0; i--) {\n const message = preparedMessages[i];\n if (message.role === 'system' || totalTokens + message.tokens <= tokenLimit) {\n messages.unshift({ role: message.role, content: message.content });\n totalTokens += message.tokens;\n } else {\n break;\n }\n }\n\n let response;\n try {\n response = await axios.post(API_ENDPOINT, { messages }, {\n headers: { 'Content-Type': 'application/json', 'api-key': apikeys[0]?.value?.value },\n });\n } catch (error) {\n console.error('Error making API call:', error.response ? error.response.data : error.message);\n }\n\n const content = response.data.choices[0]?.message?.content;\n await deep.insert({\n type_id: Message,\n string: { data: { value: content } },\n out: { data: [\n { type_id: Author, to_id: ChatGPT },\n { type_id: Reply, to_id: reply.from_id },\n ] },\n });\n\n const endTime = Date.now();\n const duration = (endTime - startTime) / 1000;\n\n ml.remove(Object.keys(ml.byId));\n\n return {\n request: { model, messages },\n response: response.data,\n duration, totalTokens,\n };\n};"
"value": "async ({ data: { newLink: reply, triggeredByLinkId }, deep }) => {\n const ml = deep.minilinks;\n\n const startTime = Date.now();\n const axios = await deep.import('axios');\n\n const ChatGPT = await deep.id(deep.linkId, 'ChatGPT');\n const Conversation = await deep.id(deep.linkId, 'Conversation');\n const ApiKey = await deep.id('@deep-foundation/openai', 'ApiKey');\n const UsesApiKey = await deep.id('@deep-foundation/openai', 'UsesApiKey');\n const Model = await deep.id('@deep-foundation/openai', 'Model');\n const UsesModel = await deep.id('@deep-foundation/openai', 'UsesModel');\n const Message = await deep.id('@deep-foundation/messaging', 'Message');\n const Reply = await deep.id('@deep-foundation/chatgpt-azure', 'Reply');\n const Author = await deep.id('@deep-foundation/messaging', 'Author');\n const messagingTree = await deep.id('@deep-foundation/messaging', 'messagingTree');\n const System = await deep.id('@deep-foundation/chatgpt-azure', 'System');\n const Tokens = await deep.id(\"@deep-foundation/tokens\", \"Tokens\")\n const ProvidedBy = await deep.id(\"@deep-foundation/chatgpt-azure\", \"ProvidedBy\")\n\n await deep.await(reply.from_id); const { data: [message] } = await deep.select({\n id: reply.from_id,\n _not: { out: { to_id: ChatGPT, type_id: Author } },\n });\n if (!message) return 'No need to react to message of this reply.';\n if (!message.value?.value) throw new Error(`Message (##${message?.id}) must have a value`);\n\n ml.apply(await deep.select({\n type_id: ApiKey,\n in: { from_id: triggeredByLinkId, type_id: UsesApiKey },\n return: {\n uses: { relation: 'in', type_id: UsesApiKey },\n },\n }), 'apikey');\n\n const apikeys = ml.select({ type_id: ApiKey });\n const useses = ml.select({ tyoe_id: UsesApiKey, to: { type_id: ApiKey } });\n \n if (!apikeys.length) throw new Error(`ApiKey not founded`);\n if (useses.length > 1) throw new Error(`More than 1 links of type UsesApiKey are found`);\n if (!apikeys[0]?.value?.value) throw new Error(`ApiKey ##${apikeys[0]?.id} has no value`);\n\n const { data: [conversation] } = await deep.select({\n type_id: Conversation,\n down: { tree_id: messagingTree, link_id: reply.id }\n });\n if (!conversation) return 'Conversation upper not founded.';\n\n const messagesByReply = await deep.select({\n type_id: Message,\n down: { tree_id: messagingTree, link_id: reply.from_id },\n order_by: { id: 'asc' },\n return: {\n authors: { relation: 'out', type_id: Author },\n tokens: { relation: 'out', type_id: Tokens },\n }\n });\n ml.apply(messagesByReply, 'messagesByReply');\n\n const messagesById = await deep.select({\n id: { _nin: messagesByReply.data.map(l => l.id) },\n type_id: Message,\n up: { tree_id: messagingTree, parent_id: conversation.id },\n order_by: { id: 'asc' },\n return: {\n authors: { relation: 'out', type_id: Author },\n tokens: { relation: 'out', type_id: Tokens },\n }\n });\n ml.apply(messagesById, 'messagesById');\n\n const messagesToSend = [...messagesById.data, ...messagesByReply.data];\n const models = await deep.select({\n type_id: Model,\n in: { type_id: UsesModel, from_id: { _in: [conversation.id, triggeredByLinkId] } },\n return: {\n usesModel: { relation: 'in', type_id: UsesModel },\n tokens: { relation: 'out', type_id: Tokens },\n providedBy: {\n relation: 'out', type_id: ProvidedBy,\n return: {\n endpoint: { relation: 'to' }\n },\n },\n },\n });\n ml.apply(models, 'models');\n\n const [userLinkedModel] = ml.select({ type_id: Model, in: { type_id: UsesModel, from_id: triggeredByLinkId } });\n if (!userLinkedModel) throw new Error(`UsersModel from triggeredByLinkId ${triggeredByLinkId} to Model not founded.`);\n const [userLinkedModelTokens] = ml.select({ type_id: Tokens, from_id: userLinkedModel?.id });\n const [linkedModel] = ml.select({ type_id: Model, in: { type_id: UsesModel, from_id: conversation.id } });\n \n const MAX_TOKENS = userLinkedModelTokens?.value?.value;\n if (!MAX_TOKENS) throw new Error(`MAX_TOKENS Tokens (##${userLinkedModelTokens?.id}) .value from model not founded.`);\n \n const endpoint = ml.select({ in: { type_id: ProvidedBy } })[0];\n const API_ENDPOINT = endpoint?.value?.value;\n if (!API_ENDPOINT) throw new Error(`API_ENDPOINT Endpoint (##${endpoint?.id}) instance.value nout founded.`);\n \n const model = linkedModel?.value?.value || userLinkedModel?.value?.value;\n if(!model) throw new Error(`UsersModel from conversation.id (##${conversation.id}) to Model not founded.`);\n\n let preparedMessages = messagesToSend.map((link) => {\n const tokens = ml.select({ type_id: Tokens, from_id: link.id })[0]?.value?.value;\n return {\n role: ml.select({ type_id: Author, from_id: link.id })[0]?.to_id === ChatGPT ? 'assistant' : 'user',\n content: link.value.value,\n tokens: ml.select({ type_id: Tokens, from_id: link.id })[0]?.value?.value,\n }\n });\n\n const systems = await deep.select({\n type_id: System, to_id: { _in: [triggeredByLinkId, conversation.id] },\n return: {\n message: { relation: 'from' },\n conversation: { relation: 'to' },\n tokens: { relation: 'in', type_id: Tokens },\n },\n });\n ml.apply(systems, 'systems');\n\n const conversationSystem = ml.select({ type_id: System, to_id: conversation.id })?.[0];\n if (!!conversationSystem && !conversationSystem?.value?.value) throw new Error(`System .value to conversation not defined`);\n const userSystems = ml.select({ type_id: System, to_id: triggeredByLinkId });\n if (userSystems.length > 1) throw new Error(\"Multiple system messages linked to the user are found\");\n const userSystem = userSystems[0];\n\n const systemMessage = conversationSystem?.from || userSystem?.from;\n if (systemMessage) {\n if (!systemMessage?.value?.value) throw new Error(`System (##${systemMessage?.id}) .from Message.value not founded`);\n preparedMessages.unshift({ role: 'system', content: systemMessage?.value?.value });\n }\n\n const tokenLimit = MAX_TOKENS * 7 / 8;\n let totalTokens = 0;\n let messages = [];\n\n for (let i = preparedMessages.length - 1; i >= 0; i--) {\n const message = preparedMessages[i];\n if (message.role === 'system' || totalTokens + message.tokens <= tokenLimit) {\n messages.unshift({ role: message.role, content: message.content });\n totalTokens += message.tokens;\n } else {\n break;\n }\n }\n\n let response;\n try {\n response = await axios.post(API_ENDPOINT, { messages }, {\n headers: { 'Content-Type': 'application/json', 'api-key': apikeys[0]?.value?.value },\n });\n } catch (error) {\n console.error('Error making API call:', error.response ? error.response.data : error.message);\n }\n\n const content = response.data.choices[0]?.message?.content;\n await deep.insert({\n type_id: Message,\n string: { data: { value: content } },\n out: { data: [\n { type_id: Author, to_id: ChatGPT },\n { type_id: Reply, to_id: reply.from_id },\n ] },\n });\n\n const endTime = Date.now();\n const duration = (endTime - startTime) / 1000;\n\n ml.remove(Object.keys(ml.byId));\n\n return {\n request: { model, messages },\n response: response.data,\n duration, totalTokens,\n };\n};"
}

@@ -165,0 +165,0 @@ },

@@ -12,3 +12,3 @@ {

},
"version": "3.0.4",
"version": "3.0.5",
"keywords": [

@@ -15,0 +15,0 @@ "deep-package"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc