user-1
(User 1)
November 8, 2023, 6:41pm
1
This topic was automatically generated from Slack. You can find the original thread here .
can you prepare this code to be inserted into the Pipedrive “Code” Module between a “New comment added to Trello card” Trigger and the “Update Trello card description” Module?
import requests
from bing_chat import BingChat
Initialize Bing Chat
chat = BingChat(“”)
Use Bing Chat to generate a response to a message
initial_message = “Hello, Bing!”
messages = chat.run(initial_message)
Use the Bing Search API to perform a web search
headers = {“Ocp-Apim-Subscription-Key”: “your-subscription-key”}
params = {“q”: messages[-1], “textDecorations”: True, “textFormat”: “HTML”}
search_url = “https://api.cognitive.microsoft.com/bing/v7.0/search ”
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()
Use the search results in your workflow
print(search_results)
user-1
(User 1)
November 8, 2023, 6:41pm
2
Here’s the code adapted for a Pipedream component. Make sure to replace your-subscription-key with your actual Bing API subscription key. ```
import { axios } from “@pipedream /platform”; export default defineComponent({ async run({ steps, $ }) { const bingSubscriptionKey = “your-subscription-key”; const initialMessage = “Hello, Bing!”; // Replace this function with the actual BingChat implementation const getBingChatResponse = (message) => { // Implement BingChat logic here return message; }; const messages = getBingChatResponse(initialMessage); const headers = { “Ocp-Apim-Subscription-Key”: bingSubscriptionKey, }; const params = { q: messages, textDecorations: true, textFormat: “HTML”, }; const searchUrl = “https://api.cognitive.microsoft.com/bing/v7.0/search ”; const response = await axios($, { method: “GET”, url: searchUrl, headers: headers, params: params, }); const searchResults = response; console.log(searchResults); return searchResults; }, });
user-1
(User 1)
November 8, 2023, 6:41pm
3
How’s this supposed to look exactly?
// To use any npm package, just import it
// import axios from "axios"
export **default** defineComponent({
**async** run({ steps, $ }) {
// Reference previous step data using the steps object and return data to use it in future steps
**return** steps.trigger.event
},
})
**import** requests
**from** bing_chat **import** BingChat
Initialize Bing Chat
chat = BingChat(“”)
Use Bing Chat to generate a response to a message
initial_message = “Hello, Bing!”
messages = chat.run(initial_message)
Use the Bing Search API to perform a web search
headers = {“Ocp-Apim-Subscription-Key”: “your-subscription-key”}
params = {“q”: messages[-1], “textDecorations”: True, “textFormat”: “HTML”}
search_url = “https://api.cognitive.microsoft.com/bing/v7.0/search ”
response = requests.**get**(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()
Use the search results **in** your workflow
print(search_results)