精品欧美一区二区三区在线观看 _久久久久国色av免费观看性色_国产精品久久在线观看_亚洲第一综合网站_91精品又粗又猛又爽_小泽玛利亚一区二区免费_91亚洲精品国偷拍自产在线观看 _久久精品视频在线播放_美女精品久久久_欧美日韩国产成人在线

雷軍看了都要哭了的幾行代碼,WPS AI會員的錢又省了

發(fā)布于 2024-11-29 14:42
瀏覽
0收藏

首先,我們可以配置幾乎所有的大模型,而 WPS 卻不可以,其次,這些幾乎都是免費的。

下面,我來給大家分享一下。

這里我們用的是OpenAI,當然你可以用其他的大模型,不過需要修改以下對返回字符串的修改。

你可以先下載文件,然后安裝一下。

您需要做的第一件事是使加載項文件受信任,以便 Microsoft 不會阻止它們運行。此安全警告并非特定于此加載項。這是您需要對從 Internet 下載的每個 excel 加載項執(zhí)行的操作。請參閱以下步驟

右鍵單擊加載項文件,然后選擇 Properties (屬性)。選擇安全選項下的取消阻止復選框,然后單擊確定

請按照以下步驟安裝和激活加載項

  1. 打開 Excel 并單擊文件 標簽。
  2. 單擊選項 ,然后從左側(cè)菜單中選擇 Add-ins。
  3. 在屏幕底部的Manage 下拉菜單中,選擇 Excel Add-ins 并單擊 Go 按鈕。
  4. 單擊瀏覽 按鈕并選擇您下載的加載項文件。點擊 OK 按鈕。
  5. 選中ChatGPT 插件旁邊的框以激活它。

以下是功能介紹

AI 搜索引擎

在 Excel 中使用 ChatGPT 有兩種搜索方法。一個是通過插件按鈕,另一個是通過 Excel 功能。

如果您沒有 ChatGPT 的 API 密鑰, 根據(jù)國內(nèi)的環(huán)境,我們使用的是智譜清言的 API。下一步是生成 API 密鑰并復制它以在加載項中使用它。

AIAssistant

單擊 ChatGPT 選項卡中的 AIAssistant 按鈕,然后選擇輸入提示(問題)的單元格。例如,您在單元格 B2 中有文本 “Capital city of Spain”。您需要在輸入框中選擇單元格 B2。如果您是第一次使用 API Key,它會要求提供 API Key。請確保在此之前已生成 ChatGPT 的 API Key。

對于類似的功能,您還可以 AIAssistant( ) 函數(shù)。使用該函數(shù)的好處是,您可以通過向下拖動該函數(shù)來針對多個提示運行

語法

AIAssistant(“文本”, [word_count])

  1. 文本 : 你想在 ChatGPT 中搜索的文本
  2. word_count :可選。為 ChatGPT 生成的輸出指定所需的字數(shù)

多輪次對話(如聊天)

要在插件中啟用多輪次對話,請按照以下說明操作 - 指南:激活聊天

AIAssistant_Chat(“文本”, [reset])

  1. 文本 : 你想在 ChatGPT 中搜索的文本
  2. reset :可選。是否重置

填充缺失數(shù)據(jù)

函數(shù) AIAssistant_FillData( ) 使用現(xiàn)有數(shù)據(jù)來訓練 ChatGPT 并填充不完整的數(shù)據(jù)。

語法

AIAssistant_FillData(rng_existingdata, rng_fill)

  1. rng_existingdata : 現(xiàn)有數(shù)據(jù)的范圍
  2. rng_fill : 指定需要填寫的數(shù)據(jù)范圍

通過使用 AIAssistant_Extractor( ) 功能,可以從 ChatGPT 中提取姓名、位置、組織詳細信息等重要信息。

語法

AIAssistant_Extractor(提示、關(guān)鍵字)

  1. prompt :要從中提取關(guān)鍵數(shù)據(jù)的文本
  2. 關(guān)鍵字 : 關(guān)鍵字可以是名稱、地點、組織、數(shù)字等。

掌握 Excel 公式

AIAssistant_Explain( ) 函數(shù)可幫助您學習任何 excel 公式。

語法

AIAssistant_Explain(cell_formula, [詳細])

  1. cell_formula :指定包含您需要學習的 excel 公式的單元格
  2. detail :可選。默認值為 TRUE。如果想要更詳細的響應(yīng),請設(shè)置 FALSE

洞察生成

AIAssistant_Insights( ) 函數(shù)可幫助您從數(shù)據(jù)中生成見解。該插件就像分析師一樣,會為您分析數(shù)據(jù)。要了解更多信息,請查看此鏈接 - 使用 ChatGPT 在 Excel 中進行自動數(shù)據(jù)分析

語法

AIAssistant_Insights(rng_data、[提示])

  1. rng_data :指定包含要分析的數(shù)據(jù)的單元格。
  2. prompt :可選。指定要了解的有關(guān)數(shù)據(jù)的信息。

翻譯文本

AIAssistant_Translator( ) 函數(shù)可幫助您翻譯任何文本。這就像在 Excel 中嵌入 Google 翻譯的功能。

語法

AIAssistant_Translator(文本、語言)

  1. text :指定包含需要翻譯的文本的單元格。
  2. language :指定包含語言名稱的單元格。

使用圖像

  • 最新的 ChatGPT 模型可以將圖像作為輸入處理。要在 Excel 中使用它,您可以使用該功能 -=AIAssistant_Image("Explain this image","C:\Downloads\myimage.png")
  • 要在 Excel 中使用 ChatGPT 創(chuàng)建圖像,您可以使用該功能 -=createImage("monk in orange dress", "1024x1024")

Add-In 的其他功能

  • 要修復插件中的非英文字母,請參考本指南:修復編碼問題
  • 您可以通過單擊Update Key (更新密鑰) 按鈕來更新您的 API 密鑰。同樣,您可以通過單擊 Check Key 按鈕來檢查您現(xiàn)有的 API 密鑰。
  • 您可以通過單擊微調(diào)響應(yīng)按鈕來更改溫度參數(shù),從而提高 ChatGPT 的響應(yīng)質(zhì)量。該參數(shù)的值介于 0 和 2 之間。較高的值(如 1.5)將生成更隨機的輸出,而較低的值(如 0.5)將生成更集中的輸出。

API 密鑰存儲在此加載項中的什么位置?

它僅存儲在您的系統(tǒng)中的注冊表中。

我們在Excel 中點開開發(fā)工具,然后輸入以下腳本:


Function AIAssistant(text As String, Optional word_count As Long = 0) As String
  
  Dim API, api_key, DisplayText, error_result As String
  Dim startPos, endPos, status_code As Long
  Dim rng As Range
  Dim myApp As String, Sett As String, secretKey, ModelValue  As String
  Dim TemperatureValue As Double
  Dim json As Object
  Dim jsonObject As Object
  Dim contentValue As String
    
  'API Info
  API = "https://api.openai.com/v1/chat/completions"
  
  'Application name
    myApp = "My Application"
    Sett = "API Keys"
    secretKey = "OpenAI"
   
    'Check registry for existing API key
    api_key = GetSetting(myApp, Sett, secretKey, "No value")

    If api_key = "No value" Or Trim(api_key) = "" Then
      ChatGPTForm.Show vbModal
      api_key = GetSetting(myApp, Sett, secretKey, "No value")
    End If
      
  'Input Text
   If word_count > 0 Then
    text = text & ". Provide response in maximum " & word_count & " words"
   End If
  
  text = Replace(text, Chr(34), Chr(39))
  text = Replace(text, vbLf, "\n")

   'Application name
   myApp = "ChatGPT Excel"
   Sett = "Temperature"
   secretKey = "Params"
   
    'Check registry for existing API key
    TemperatureValue = GetSetting(myApp, Sett, secretKey, 0.7)
    
    'Application name
    myApp = "My Application2"
    Sett = "Model"
    secretKey = "ModelType"
    ModelValue = GetSetting(myApp, Sett, secretKey, "gpt-3.5-turbo")
          
  'Send request to API
    Dim client As New WebClient
    Dim request As New WebRequest
    Dim response As WebResponse
    Dim requestBody As New Dictionary
    Dim responseBody As String
    client.TimeoutMs = 30000
        
    client.BaseUrl = API
    request.RequestFormat = WebFormat.json
    request.Method = HttpPost
    request.AddHeader "Authorization", "Bearer " & api_key

    Dim messagePrompt() As Dictionary
    Dim message As New Dictionary
    message.Add "content", text
    message.Add "role", "user"
    ReDim messagePrompt(0)
    Set messagePrompt(0) = message
    
    requestBody.Add "model", ModelValue
    requestBody.Add "messages", messagePrompt
    requestBody.Add "temperature", TemperatureValue
    requestBody.Add "top_p", 1
    
    Set request.body = requestBody
    Set response = client.Execute(request)
    status_code = response.StatusCode
    responseBody = response.content

  
  'Parse response from API
  If status_code = 200 Then
    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("choices")(1)("message")("content")
  Else
    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("error")("message")
    
    If DisplayText = "" Then
        DisplayText = jsonObject("error")("code")
    End If
  End If
  
    If word_count > 0 And Right(DisplayText, 1) = "." Then
        DisplayText = Left(DisplayText, Len(DisplayText) - 1)
    Else
        DisplayText = DisplayText
    End If
  
  'Return result
  AIAssistant = DisplayText

End Function

將上面的KEY替換成自己的,就可以在Excel里面對話了。

多輪對話

我們還可以進行多輪對話

Public Function AIAssistant_Chat(text As String, Optional reset As Boolean = False) As String
    
  Dim API, api_key, error_result As String
  Dim startPos, endPos, status_code As Long
  Dim myApp As String, Sett As String, secretKey, ModelValue  As String
  Dim TemperatureValue As Double
    Dim json As Object
    Dim jsonObject As Object
    Dim contentValue As String
    Dim DisplayText As String
    Dim DisplayText0 As String
    
    
   API = "https://api.openai.com/v1/chat/completions"
  
  'Application name
    myApp = "My Application"
    Sett = "API Keys"
    secretKey = "OpenAI"
   
    'Check registry for existing API key
    api_key = GetSetting(myApp, Sett, secretKey, "No value")
    
    If api_key = "No value" Or Trim(api_key) = "" Then
      ChatGPTForm.Show vbModal
      api_key = GetSetting(myApp, Sett, secretKey, "No value")
    End If
    
    text = Replace(text, Chr(34), Chr(39))
    text = Replace(text, vbLf, "\n")

   'Application name
    myApp = "ChatGPT Excel"
    Sett = "Temperature"
    secretKey = "Params"
   
    'Check registry for existing API key
    TemperatureValue = GetSetting(myApp, Sett, secretKey, 0.7)
    
    'Application name
    myApp = "My Application2"
    Sett = "Model"
    secretKey = "ModelType"
    ModelValue = GetSetting(myApp, Sett, secretKey, "gpt-3.5-turbo")

    'Send request to API
    Dim client As New WebClient
    Dim request As New WebRequest
    Dim response As WebResponse
    Dim requestBody As New Dictionary
    Dim responseBody As String
    client.TimeoutMs = 30000
        
    client.BaseUrl = API
    request.RequestFormat = WebFormat.json
    request.Method = HttpPost
    request.AddHeader "Authorization", "Bearer " & api_key
    
    If reset Then
        Erase messages
    End If
    Dim message As New Dictionary
    message.Add "content", text
    message.Add "role", "user"
    If IsEmpty(messages) Then
        ReDim messages(0)
    Else
        ReDim Preserve messages(UBound(messages) + 1)
    End If
    Set messages(UBound(messages)) = message
    
    requestBody.Add "model", ModelValue
    requestBody.Add "messages", messages
    requestBody.Add "temperature", TemperatureValue
    requestBody.Add "top_p", 1
    
    Set request.body = requestBody
    Set response = client.Execute(request)
    status_code = response.StatusCode
    responseBody = response.content
  
  'Parse response from API
  If status_code = 200 Then
    

    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("choices")(1)("message")("content")
    DisplayText0 = ExtractContent(DisplayText)
    
    'Update chatHistory
    Dim message2 As New Dictionary
    message2.Add "content", DisplayText0
    message2.Add "role", "assistant"
    ReDim Preserve messages(UBound(messages) + 1)
    Set messages(UBound(messages)) = message2
    
  Else
            Set jsonObject = ParseJson(responseBody)
            DisplayText = jsonObject("error")("message")
            If DisplayText = "" Then
                DisplayText = jsonObject("error")("code")
            End If
  End If

    ' return
    AIAssistant_Chat = DisplayText

End Function

當然我們也可以用它來解釋Excel自帶的函數(shù)

Function AIAssistant_Explain(cell_formula As Range, Optional detail As Boolean = True)
    Dim formulaText, formulaText2 As String
    
    If cell_formula.HasFormula Then
        formulaText = cell_formula.Formula
        If detail Then
            formulaText2 = "Explain this MS Excel Function " & formulaText
        Else
            formulaText2 = "Explain this MS Excel Function. Less Verbose. " & formulaText
        End If
        AIAssistant_Explain = AIAssistant(formulaText2)
    Else
        AIAssistant_Explain = "Cell does not contain MS Excel formula"
    End If
    
End Function

批量翻譯

Function AIAssistant_Translator(text As String, language As String)
    Dim translateText As String
    translateText = "Act like a translator. Translate the following text to " & language & "." & "\n" & text
    AIAssistant_Translator = CleanMsg(AIAssistant(translateText))
End Function

批量生成假數(shù)據(jù)

Function AIAssistant_FillData(rng_existingdata As Range, rng_fill As Range)

    Dim API, api_key, prompt, prompt2 As String
    Dim myData, myData2 As String
    Dim i As Long
    Dim words() As String
    Dim outputText() As String
    Dim myApp As String, Sett As String, secretKey, ModelValue  As String
    Dim TemperatureValue As Double
    Dim json As Object
    Dim jsonObject As Object
    Dim contentValue As String
    Dim delimiter As String
    
    delimiter = "-->"
    
    'API
    API = "https://api.openai.com/v1/chat/completions"
    myData = rng_existingdata.value
        
    'Application name
    myApp = "My Application"
    Sett = "API Keys"
    secretKey = "OpenAI"
   
    'Check registry for existing API key
    api_key = GetSetting(myApp, Sett, secretKey, "No value")

    If api_key = "No value" Or Trim(api_key) = "" Then
      ChatGPTForm.Show vbModal
      api_key = GetSetting(myApp, Sett, secretKey, "No value")
    End If

   'Application name
   myApp = "ChatGPT Excel"
   Sett = "Temperature"
   secretKey = "Params"
   
    'Check registry for existing API key
    TemperatureValue = GetSetting(myApp, Sett, secretKey, 0.7)
    
    'Application name
    myApp = "My Application2"
    Sett = "Model"
    secretKey = "ModelType"
    ModelValue = GetSetting(myApp, Sett, secretKey, "gpt-3.5-turbo")
    
    ' Generate prompt string
    If rng_fill.Count > 1 Then
        AIAssistant_FillData = "second argument can't have range with more than 1 cell"
        Exit Function
     Else
        myData2 = Replace(rng_fill.value, Chr(34), "")
        myData2 = Replace(myData2, vbLf, " ")
        myData2 = Application.Trim(Replace(myData2, Chr(39), ""))

    End If
    
    prompt = ""
    For i = LBound(myData, 1) To UBound(myData, 1)
        cleaned = Application.Trim(Replace(myData(i, 1), vbLf, " "))
        prompt = prompt & cleaned & delimiter & myData(i, 2) & "\n"
    Next i
        prompt = Replace(prompt, Chr(34), "")
        prompt = Replace(prompt, Chr(39), "")
    
    ' query build
    query = "Do not write explanations on replies.\n"
    
    If rng_fill.Count > 1 Then
        AIAssistant_FillData = "second argument can't have range with more than 1 cell"
        Exit Function
     Else
        myData2 = Replace(rng_fill.value, Chr(34), "")
        myData2 = Replace(myData2, vbLf, " ")
        myData2 = Application.Trim(Replace(myData2, Chr(39), ""))

    End If
    
    prompt2 = query & myData2 & delimiter
    
    ' Send POST request to OpenAI API
    Dim client As New WebClient
    Dim request As New WebRequest
    Dim response As WebResponse
    Dim requestBody As New Dictionary
    Dim responseBody As String
    client.TimeoutMs = 30000
        
    client.BaseUrl = API
    request.RequestFormat = WebFormat.json
    'request.Resource = API
    request.Method = HttpPost
    request.AddHeader "Authorization", "Bearer " & api_key
    
    Dim messagePrompt() As Dictionary
    Dim message As New Dictionary
    Dim message2 As New Dictionary
    
    message.Add "content", prompt
    message.Add "role", "system"
    message2.Add "content", prompt2
    message2.Add "role", "user"
    ReDim messagePrompt(1)
    Set messagePrompt(0) = message
    Set messagePrompt(1) = message2
    
    requestBody.Add "model", ModelValue
    requestBody.Add "messages", messagePrompt
    requestBody.Add "temperature", TemperatureValue
    requestBody.Add "top_p", 1
    
    Set request.body = requestBody
    Set response = client.Execute(request)
    status_code = response.StatusCode
    responseBody = response.content

  'Check status code
  If status_code = 200 Then
    
    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("choices")(1)("message")("content")
    DisplayText = Replace(DisplayText, "\\", "\")
    DisplayText = Replace(DisplayText, delimiter, "")
            
    'Extract after line break
    words = Split(DisplayText, "\n")
    x = UBound(words)
    If x >= 1 Then
       If Len(words(1)) >= 1 Then
            ReDim outputText(1 To x + 1)
            outputText(1) = words(1)
            DisplayText = Join(outputText, " ")
        Else
            DisplayText = Replace(DisplayText, "\n", "")
        End If
    End If

    'Check if prompt exists in output
    If InStr(DisplayText, myData2) > 0 Then
        DisplayText = Replace(DisplayText, myData2, "")
    End If

    'Remove full stops at end of the reply
    words = Split(DisplayText, ".")
    x = UBound(words)
    If x = 1 And Right(DisplayText, 1) = "." Then
      DisplayText = Left(DisplayText, Len(DisplayText) - 1)
    End If
    
    Else
        ' ERROR MESSAGE
            Set jsonObject = ParseJson(responseBody)
            DisplayText = jsonObject("error")("message")
            If DisplayText = "" Then
                DisplayText = jsonObject("error")("code")
            End If
    End If

    
     AIAssistant_FillData = DisplayText

End Function

關(guān)鍵信息提取

Function AIAssistant_Extractor(prompt As Range, keyword As String)

    Dim API, api_key, prompt2 As String
    Dim myData, myData2 As String
    Dim i As Long
    Dim words() As String
    Dim outputText() As String
    Dim myApp As String, Sett As String, secretKey, ModelValue  As String
    Dim TemperatureValue As Double
    Dim json As Object
    Dim jsonObject As Object
    Dim contentValue As String
    
    'API
    API = "https://api.openai.com/v1/chat/completions"
    myData = prompt.value
        
    'Application name
    myApp = "My Application"
    Sett = "API Keys"
    secretKey = "OpenAI"
   
    'Check registry for existing API key
    api_key = GetSetting(myApp, Sett, secretKey, "No value")

    If api_key = "No value" Or Trim(api_key) = "" Then
      ChatGPTForm.Show vbModal
      api_key = GetSetting(myApp, Sett, secretKey, "No value")
    End If

   'Application name
    myApp = "ChatGPT Excel"
    Sett = "Temperature"
    secretKey = "Params"
   
    'Check registry for existing API key
    TemperatureValue = GetSetting(myApp, Sett, secretKey, 0.7)
    
    'Application name
    myApp = "My Application2"
    Sett = "Model"
    secretKey = "ModelType"
    ModelValue = GetSetting(myApp, Sett, secretKey, "gpt-3.5-turbo")
    
    ' Generate prompt string
    myData2 = Replace(myData, Chr(34), "")
    myData2 = Application.Trim(Replace(myData2, vbLf, " "))
    prompt2 = "Extract " & keyword & " from " & "\n" & "'" & myData & "'" & ". Be less verbose on replies."
    
    ' Send POST request to OpenAI API
    Dim client As New WebClient
    Dim request As New WebRequest
    Dim response As WebResponse
    Dim requestBody As New Dictionary
    Dim responseBody As String
    client.TimeoutMs = 30000
        
    client.BaseUrl = API
    request.RequestFormat = WebFormat.json
    'request.Resource = API
    request.Method = HttpPost
    request.AddHeader "Authorization", "Bearer " & api_key
    
    Dim messagePrompt() As Dictionary
    Dim message As New Dictionary
    message.Add "content", prompt2
    message.Add "role", "user"
    ReDim messagePrompt(0)
    Set messagePrompt(0) = message
    
    requestBody.Add "model", ModelValue
    requestBody.Add "messages", messagePrompt
    requestBody.Add "temperature", TemperatureValue
    requestBody.Add "top_p", 1
    
    Set request.body = requestBody
    Set response = client.Execute(request)
    status_code = response.StatusCode
    responseBody = response.content
    
    
  'Check status code
  If status_code = 200 Then
    
    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("choices")(1)("message")("content")
            
    'Extract after line break
    words = Split(DisplayText, ":")
    x = UBound(words)
    ReDim outputText(1 To x + 1)
    If x >= 1 Then
        outputText(1) = words(1)
        DisplayText = Join(outputText, " ")
    End If

    ' Check if the string contains a tab character
    hasTab = InStrRev(DisplayText, "\t")
    If hasTab > 0 Then
     DisplayText = Mid(DisplayText, hasTab + 2)
    End If

    If Right(DisplayText, 1) = "." Then
     DisplayText = Left(DisplayText, Len(DisplayText) - 1)
    End If
    
    Else
        
        Set jsonObject = ParseJson(responseBody)
        DisplayText = jsonObject("error")("message")
        If DisplayText = "" Then
            DisplayText = jsonObject("error")("code")
        End If
        
        
    End If

    'Check if prompt exists in output
    If InStr(DisplayText, keyword) > 0 Then
        DisplayText = Replace(DisplayText, keyword, "")
    End If
    
     AIAssistant_Extractor = Application.Trim(DisplayText)

End Function

負責從返回內(nèi)容中提取文本

Function ExtractContent(content As String) As String
        
    content = Replace(content, Chr(34), Chr(39))
        
    'Fix for excel forumulas as response
    If Left(Trim(content), 1) = "=" Then
      content = "'" & content
    End If
    
    If Right(content, 1) = """" Then
      content = Left(content, Len(content) - 1)
    End If
    
    If Right(content, 1) = "\" Then
      content = Left(content, Len(content) - 1)
    End If
    
    ExtractContent = content

End Function

中文支持

雖然我看不懂這段代碼,不過真的管用

Public Function CleanMsg(ByVal strText As String) As String
    Dim i&, l1&, l2&, l3&, l4&, l&
    For i = 1 To Len(strText)
        l1 = AscW(Mid(strText, i, 1))
        If i + 1 <= Len(strText) Then l2 = AscW(Mid(strText, i + 1, 1))
        If i + 2 <= Len(strText) Then l3 = AscW(Mid(strText, i + 2, 1))
        If i + 3 <= Len(strText) Then l4 = AscW(Mid(strText, i + 3, 1))
        Select Case l1
        Case 1 To 127
            l = l1
        Case 194 To 223
            l = ((l1 And &H1F) * 2 ^ 6) Or (l2 And &H3F)
            i = i + 1
        Case 224 To 239
            l = ((l1 And &HF) * 2 ^ 12) Or ((l2 And &H3F) * 2 ^ 6) Or (l3 And &H3F)
            i = i + 2
        Case 240 To 255
            l = ((l1 And &H7) * 2 ^ 18) Or ((l2 And &H3F) * 2 ^ 12) Or ((l3 And &H3F) * 2 ^ 6) Or (l4 And &H3F)
            i = i + 4
        Case Else
            l = 63
        End Select
        CleanMsg = CleanMsg & IIf(l < 55296, WorksheetFunction.Unichar(l), "?")
    Next i
End Function

觀點提煉


Sub AIAssistant_Insights2(Control As IRibbonControl)
    
    Dim mytext As String
    Dim splitArr() As String
    Dim Format As Integer
    Dim promptRange As Range
    Dim rng As Range
    Dim rng2 As Range
    Dim promptArray As Variant
    Dim header As String
    Dim data As String
    Dim i As Long
    
    On Error GoTo errhandler
    Set promptRange = Application.InputBox("Please select cells containing data (including header)", Title:="Select Data (with Header)", Type:=8)
    promptArray = promptRange.value
    
    ' Concatenate header values
    For j = 1 To UBound(promptArray, 2)
        header = header & promptArray(1, j) & "|"
    Next j
    
    ' Concatenate data rows
    Dim value As String
    For i = 2 To UBound(promptArray, 1)
        For j = 1 To UBound(promptArray, 2)
            If promptArray(i, j) = "" Then
                value = "NA"
            Else
                value = promptArray(i, j)
            End If
            data = data & value & "|"
        Next j
        data = data & " "
    Next i

    
    mytext = "Act like analyst. Generate key insights based on the following data." & "\n" & header & "\n" & data
    frmProgressForm.Show
    Result = AIAssistant(mytext)
    Unload frmProgressForm
    
    'Clear multiple line breaks
    Result = Replace(Result, vbCrLf & vbCrLf, vbCrLf)
    
    On Error GoTo errhandler2
    Set rng = Application.InputBox("Please choose a cell where the output will be saved.", Title:="Output", Type:=8)
    splitArr = Split(Result, vbCrLf)
        
    If UBound(splitArr) > 0 Then
            Format = MsgBox("Since output is lengthy, would you like it to be displayed in multiple cells?", vbYesNo)
            If Format = vbNo Then
                rng.value = Result
                With rng
                    .WrapText = True
                    .EntireColumn.AutoFit
                    .VerticalAlignment = xlTop
                End With
            
            Else
                Set rng2 = Range(rng.Offset(1, 0), rng.Offset(10, 0))
                rng2.Clear
                For i = LBound(splitArr) To UBound(splitArr)
                      x = splitArr(i)
                      If Left(Trim(x), 1) = "=" Then
                          x = "'" & x
                      End If
                      rng.Offset(i, 0).value = x
                Next i
        
                With rng2
                    .WrapText = True
                    .EntireColumn.AutoFit
                    .VerticalAlignment = xlTop
                End With
            End If
    Else
        rng.value = Result
    End If
    
Exit Sub

errhandler2:
MsgBox ("No cell is selected to save the output")
Unload frmProgressForm

errhandler:
MsgBox ("No input found")
Unload frmProgressForm

End Sub

Function AIAssistant_Insights(rng_data As Range, Optional prompt As String = "Key Insights")
    
    Dim mytext As String
    Dim splitArr() As String
    Dim Format As Integer
    Dim promptRange As Range
    Dim rng As Range
    Dim rng2 As Range
    Dim promptArray As Variant
    Dim header As String
    Dim data As String
    Dim i As Long
    
    Set promptRange = rng_data
    promptArray = promptRange.value
    
    ' Concatenate header values
    For j = 1 To UBound(promptArray, 2)
        header = header & promptArray(1, j) & "|"
    Next j
    
    ' Concatenate data rows
    Dim value As String
    For i = 2 To UBound(promptArray, 1)
        For j = 1 To UBound(promptArray, 2)
            If promptArray(i, j) = "" Then
                value = "NA"
            Else
                value = promptArray(i, j)
            End If
            data = data & value & "|"
        Next j
        data = data & " "
    Next i

    If prompt = "Key Insights" Then
        mytext = "Act like analyst. Generate key insights based on the following data." & "\n" & header & "\n" & data
    Else
        mytext = "Act like analyst. Do not write explanations on replies. " & prompt & "." & "\n" & header & "\n" & data
    End If

    Result = AIAssistant(mytext)
    AIAssistant_Insights = Result
    
End Function

微調(diào)

Function AIAssistant_QnA(query As Variant, passage As Variant) As String
    Dim prompt As String
    Dim cell As Range
    Dim fullPassage As String
    Dim fullquery As String
    
    ' Concatenate all cells
    If TypeName(passage) = "Range" Then
        For Each cell In passage
            fullPassage = fullPassage & " " & cell.value
        Next cell
    Else
        fullPassage = CStr(passage)
    End If
    
    If TypeName(query) = "Range" Then
        For Each cell In query
            fullquery = fullquery & " " & cell.value
        Next cell
    Else
        fullquery = CStr(query)
    End If


    fullPassage = Replace(Replace(Replace(fullPassage, "'", ""), """", ""), vbLf, " ")
    fullPassage = Trim(fullPassage)
    
    fullquery = Replace(Replace(Replace(fullquery, "'", ""), """", ""), vbLf, " ")
    fullquery = Trim(fullquery)
    
    prompt = "Act like a customer care executive that answers questions using text from the reference passage included below. " & _
             "Be less verbose." & vbLf & _
             "QUESTION: '" & fullquery & "'" & vbLf & _
             "PASSAGE: '" & fullPassage & "'" & vbLf & vbLf & _
             "ANSWER:" & vbLf
    
    AIAssistant_QnA = AIAssistant(prompt)

End Function

圖片生成

Function AIAssistant_Image(prompt As String, image_path As String, Optional detail As String = "high", Optional max_tokens As Long = 300) As String
  
  Dim API, api_key, DisplayText, error_result As String
  Dim startPos, endPos, status_code As Long
  Dim rng As Range
  Dim myApp As String, Sett As String, secretKey, ModelValue  As String
  Dim TemperatureValue As Double
  Dim json As Object
  Dim jsonObject As Object
  Dim contentValue As String
  Dim base64String As String
    
  'API Info
  API = "https://api.openai.com/v1/chat/completions"
  
  'Application name
    myApp = "My Application"
    Sett = "API Keys"
    secretKey = "OpenAI"
   
    'Check registry for existing API key
    api_key = GetSetting(myApp, Sett, secretKey, "No value")

    If api_key = "No value" Or Trim(api_key) = "" Then
      ChatGPTForm.Show vbModal
      api_key = GetSetting(myApp, Sett, secretKey, "No value")
    End If
      
  'Input Text
  text = Replace(prompt, Chr(34), Chr(39))
  text = Replace(text, vbLf, "\n")
   
    'Application name
    myApp = "My Application2"
    Sett = "Model"
    secretKey = "ModelType"
    ModelValue = GetSetting(myApp, Sett, secretKey, "gpt-3.5-turbo")
    
    'Image
    base64String = EncodeImageToBase64(image_path)
    base64String = "data:image/jpeg;base64," + base64String
        
    Dim client As New WebClient
    Dim request As New WebRequest
    Dim response As WebResponse
    Dim requestBody As New Dictionary
    Dim responseBody As String
    client.TimeoutMs = 30000
    
    client.BaseUrl = API
    request.RequestFormat = WebFormat.json
    request.Method = HttpPost
    request.AddHeader "Authorization", "Bearer " & api_key
    
    Dim messagePrompt() As Dictionary
    Dim message As New Dictionary
    Dim contentText As New Dictionary
    Dim contentImageUrl As New Dictionary
    Dim imageUrl As New Dictionary
    contentText.Add "type", "text"
    contentText.Add "text", text
    contentImageUrl.Add "type", "image_url"
    imageUrl.Add "url", base64String
    imageUrl.Add "detail", detail
    contentImageUrl.Add "image_url", imageUrl
    message.Add "role", "user"
    message.Add "content", Array(contentText, contentImageUrl)
    ReDim messagePrompt(0)
    Set messagePrompt(0) = message
    requestBody.Add "model", ModelValue
    requestBody.Add "messages", messagePrompt
    requestBody.Add "max_tokens", max_tokens
    
    Set request.body = requestBody
    Set response = client.Execute(request)
    status_code = response.StatusCode
    responseBody = response.content
    
  'Parse response from API
  If status_code = 200 Then
    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("choices")(1)("message")("content")
  Else
    Set jsonObject = ParseJson(responseBody)
    DisplayText = jsonObject("error")("message")
    
    If DisplayText = "" Then
        DisplayText = jsonObject("error")("code")
    End If
  End If
  
 
  'Return result
  AIAssistant_Image = DisplayText

End Function

Function EncodeImageToBase64(imagePath As String) As String
#If Mac Then
    Dim web_Command As String
    web_Command = "cat " & imagePath & " | openssl base64"
    EncodeImageToBase64 = ExecuteInShell(web_Command).Output
#Else
    Dim stream As Object
    Set stream = CreateObject("ADODB.Stream")
    stream.Type = 1 ' adTypeBinary
    stream.Open
    stream.LoadFromFile imagePath

    Dim xml As Object
    Set xml = CreateObject("MSXML2.DOMDocument")
    Dim node As Object
    Set node = xml.createElement("b64")
    node.DataType = "bin.base64"
    node.nodeTypedValue = stream.Read
    EncodeImageToBase64 = node.text

    stream.Close
    Set stream = Nothing
    Set xml = Nothing
#End If
End Function

Function createImage(prompt As String, Optional size As String = "1024x1024") As String
  
  Dim API, api_key, DisplayText, error_result As String
  Dim startPos, endPos, status_code As Long
  Dim rng As Range
  Dim myApp As String, Sett As String, secretKey, ModelValue  As String
  Dim TemperatureValue As Double
  Dim json As Object
  Dim jsonObject As Object
  Dim contentValue As String

    'API Info
    API = "https://api.openai.com/v1/images/generations"
  
    'Application name
    myApp = "My Application"
    Sett = "API Keys"
    secretKey = "OpenAI"
   
    'Check registry for existing API key
    api_key = GetSetting(myApp, Sett, secretKey, "No value")

    If api_key = "No value" Or Trim(api_key) = "" Then
      ChatGPTForm.Show vbModal
      api_key = GetSetting(myApp, Sett, secretKey, "No value")
    End If
      
    'Input Text
    text = Replace(prompt, Chr(34), Chr(39))
    text = Replace(text, vbLf, "\n")
          
    Dim client As New WebClient
    Dim request As New WebRequest
    Dim response As WebResponse
    Dim requestBody As New Dictionary
    Dim responseBody As String
    client.TimeoutMs = 30000
    
    client.BaseUrl = API
    request.RequestFormat = WebFormat.json
    request.Method = HttpPost
    request.AddHeader "Authorization", "Bearer " & api_key
    
    requestBody.Add "prompt", text
    requestBody.Add "n", 1
    requestBody.Add "size", size
    requestBody.Add "response_format", "url"

    Set request.body = requestBody
    Set response = client.Execute(request)
    status_code = response.StatusCode
    responseBody = response.content
    
  'Parse response from API
    Set jsonObject = ParseJson(responseBody)
    If status_code = 200 Then
      DisplayText = jsonObject("data")(1)("url")
    Else
      DisplayText = jsonObject("error")("message")
      If DisplayText = "" Then
          DisplayText = jsonObject("error")("code")
      End If
    End If
  
  'Return result
  createImage = DisplayText

End Function

Sub createImage2(Control As IRibbonControl)
    
    Dim val As String
    Dim selectedCell, cellr, rng As Range
    Dim splitArr() As String
    Dim delimiter As String
    Dim Format As Integer
    delimiter = "\n"
    
    On Error GoTo errhandler
    Set selectedCell = Application.InputBox("Please select a cell containing the image description", Type:=8)
    
    If selectedCell Is Nothing Then
        MsgBox "No cell selected"
    Else
        
    Set cellr = selectedCell.Offset(1, 0)
        
       If Trim(selectedCell.text) = "" Then
            MsgBox "Seems to be a blank cell."
         Exit Sub
       End If
        
        frmProgressForm.Show
         val = createImage(selectedCell.text)
        Unload frmProgressForm
    
        cellr.value = val
        
   End If
   
Exit Sub
errhandler:
MsgBox ("No input found")


End Sub

本文轉(zhuǎn)載自??AI大模型世界??,作者: rocLv ????

收藏
回復
舉報
回復
相關(guān)推薦
国产精品自拍在线| 一区二区三区视频免费观看| 亚洲激情六月丁香| 3d蒂法精品啪啪一区二区免费| 中文字幕无码日韩专区免费| 精品视频一区二区三区在线观看| 国产精品高潮呻吟久久| 国产91色在线播放| 黑人と日本人の交わりビデオ| 2020国产精品小视频| 香蕉加勒比综合久久| 日韩欧美激情一区二区| 亚洲精品综合网| 日韩精品一级二级| 久久免费福利视频| 乱老熟女一区二区三区| 日本福利一区| 678五月天丁香亚洲综合网| 老太脱裤让老头玩ⅹxxxx| 2017亚洲天堂1024| 99精品视频在线观看免费| 川上优av一区二区线观看| 久久精品视频1| 欧美色图首页| 中文字幕视频在线免费欧美日韩综合在线看 | 永久免费网站在线| 国产日韩欧美制服另类| 国模一区二区三区私拍视频| 国产精品无码免费播放| 日韩av网站在线观看| 国模极品一区二区三区| 加勒比婷婷色综合久久| 久久密一区二区三区| 精品亚洲va在线va天堂资源站| 少妇高潮一69aⅹ| 国外成人福利视频| 欧洲精品在线观看| 亚洲乱码中文字幕久久孕妇黑人| 欧洲性视频在线播放| 自拍偷自拍亚洲精品播放| 欧美日韩在线精品| 五月激情婷婷网| 国产69精品一区二区亚洲孕妇| 91精品久久久久久久久久入口| 亚洲av无码不卡| 美女精品网站| 国产成人精品日本亚洲| 九九热在线免费观看| 一区在线视频观看| 久久久久久久久久国产| 免费中文字幕在线观看| 国精品一区二区| 久久久久久国产三级电影| 欧美日韩精品一区二区三区视频播放 | 超碰99在线| 亚洲一区二区三区四区在线观看| 美女在线免费视频| 综合久久2o19| 夜夜精品浪潮av一区二区三区| 蜜臀av.com| a级网站在线播放| 亚洲激情自拍偷拍| 青青草视频在线视频| 午夜av在线免费观看| 亚洲国产综合在线| 男人用嘴添女人下身免费视频| 99爱在线视频| 色综合av在线| 污污的网站18| 91精品福利观看| 日韩免费一区二区| 日本japanese极品少妇| 亚洲男人都懂第一日本| 一本一本久久a久久精品综合小说 一本一本久久a久久精品牛牛影视 | 欧美日韩国产一区二区三区地区| 日韩高清第一页| 日韩高清在线观看一区二区| 精品国产成人系列| 给我看免费高清在线观看| 国产麻豆一区二区三区精品视频| 亚洲午夜精品视频| 少妇高潮在线观看| 激情综合亚洲| 国产成人在线一区| 97精品久久人人爽人人爽| 国产成人小视频| 久久国产精品久久| 2021av在线| 亚洲一区二区视频| 亚洲乱码中文字幕久久孕妇黑人| 欧美亚洲二区| 精品精品国产高清a毛片牛牛| 欧美bbbbb性bbbbb视频| 日韩三级在线| 欧美精品www| 四虎影院在线免费播放| 激情av综合网| 欧美日韩综合网| 爆操欧美美女| 色呦呦日韩精品| 亚洲一二区在线观看| 日韩美脚连裤袜丝袜在线| 久久韩剧网电视剧| 中文字幕第四页| 国产精品中文字幕日韩精品 | 久久高清免费| 91国产高清在线| 国产精品久久久久久久免费看| av在线播放成人| 综合久久国产| 快播电影网址老女人久久| 欧美不卡123| 亚洲综合欧美综合| 亚洲三级色网| 亚洲在线视频观看| 成人在线二区| 欧美日韩一区二区在线播放| 制服下的诱惑暮生| 欧美丰满老妇| 国产精品第七十二页| 开心激情综合网| 亚洲人吸女人奶水| 牛夜精品久久久久久久| 日韩高清影视在线观看| 欧美激情精品久久久| 亚洲一区二区天堂| 国产日韩精品一区二区浪潮av| 僵尸世界大战2 在线播放| 四虎地址8848精品| 中文字幕av一区二区| 精品免费囯产一区二区三区| 成人福利视频网站| 成人av在线不卡| 国产成人精选| 国产亚洲激情在线| 中文字幕一区在线播放| av资源网一区| av高清在线免费观看| www.丝袜精品| 欧美激情亚洲综合一区| 丰满肉嫩西川结衣av| 一区二区三区四区精品在线视频| 污网站在线免费| 91影院成人| 国产日韩欧美在线视频观看| 又爽又大又黄a级毛片在线视频| 91久久精品一区二区| 久久精品—区二区三区舞蹈| 久久久久国产精品午夜一区| 日韩高清专区| 国产毛片精品久久| 最近2019中文字幕在线高清| 亚洲一区二区激情| 亚洲色图.com| 精品无码av一区二区三区| 激情久久久久久| 国产91亚洲精品一区二区三区| 羞羞视频在线观看不卡| 欧美mv日韩mv| 日韩精品在线观看免费| 久久视频一区二区| 亚洲精品乱码久久久久久自慰| 亚洲自拍电影| 国产精品男女猛烈高潮激情| jyzzz在线观看视频| 欧美日韩极品在线观看一区| 日韩影院一区二区| av色综合久久天堂av综合| 日韩欧美一区三区| 激情五月综合网| 国产日韩欧美视频| 在线观看操人| 亚洲精品国产精品国自产在线| 99精品在线播放| 国产精品久久久久影院亚瑟 | 亚洲超碰在线观看| 亚洲18私人小影院| 韩国福利在线| 日韩亚洲欧美中文三级| 亚洲一区欧美在线| 欧美经典一区二区| 美女被爆操网站| 久久久青草婷婷精品综合日韩| 亚洲mv在线看| 99国产精品免费网站| 2018中文字幕一区二区三区| www.久久热.com| 欧美成人午夜电影| 在线观看污污网站| 亚洲欧美成aⅴ人在线观看 | 国产精品视频线看| 亚洲精品成人无码毛片| 久久综合九色| 国产制服91一区二区三区制服| 亚洲国产欧美日韩在线观看第一区| 国产精品一区二区三区久久久| 精品精品导航| 视频一区视频二区国产精品| 少妇无码一区二区三区| 欧美日韩视频一区二区| 天天操天天干视频| 亚洲婷婷在线视频| 亚洲第一成人网站| 国产精品亚洲а∨天堂免在线| 50路60路老熟妇啪啪| 欧美日韩三区| 中文字幕乱码一区二区三区| 亚洲成aⅴ人片久久青草影院| 97se视频在线观看| 欧美三区四区| 26uuu日韩精品一区二区| gogogogo高清视频在线| 一区二区三区视频免费| 人妻va精品va欧美va| 3d动漫精品啪啪一区二区竹菊| 中文字幕精品无| 午夜精品久久久久久久| 校园春色 亚洲| 国产精品毛片大码女人| 日韩人妻无码一区二区三区| 国产成人精品免费一区二区| 一级黄色录像在线观看| 日韩高清不卡在线| 欧美 日韩 国产一区| 激情文学一区| 伊人久久在线观看| 影音先锋成人在线电影| 亚洲一区尤物| 成人精品视频| 日韩久久不卡| 一本色道久久综合亚洲精品酒店| 国产伦精品一区二区三区在线| 国产精一区二区| 国产色综合天天综合网| 巨胸喷奶水www久久久免费动漫| 欧美一区二区.| 美女福利一区二区 | 欧美男男gaygay1069| 日韩美女毛茸茸| 日韩高清中文字幕一区二区| 国产91色在线|| 日韩av免费| 国产精品久久久久久久久久东京| 欧美激情喷水| 国产成人激情小视频| 日韩高清中文字幕一区二区| 国产91精品网站| 四虎成人在线| 国产精品手机播放| 欧美极品在线| **亚洲第一综合导航网站| 警花av一区二区三区 | 欧美在线关看| 欧美精品亚洲| 欧美综合视频| 国产精品美女在线播放| 在线看片不卡| 草b视频在线观看| 亚洲少妇在线| 日本www高清视频| 美国毛片一区二区三区| 一级黄色片在线免费观看| 国产激情视频一区二区三区欧美| 爱情岛论坛亚洲自拍| 成人永久aaa| 国产精品无码专区| 久久久www免费人成精品| 永久免费毛片在线观看| 亚洲青青青在线视频| 久久精品国产av一区二区三区| 日韩欧美主播在线| 国产精品尤物视频| 3atv一区二区三区| 人妻夜夜爽天天爽| 亚洲欧美日韩国产中文专区| 午夜在线免费观看视频| 色综合久久精品亚洲国产 | 国产精品美女久久久免费| 国产999精品在线观看| 成人自拍爱视频| 国产日产精品一区二区三区四区的观看方式| 亚洲精品美女久久7777777| 中文字幕一区二区三区乱码图片 | 日韩精品亚洲一区二区三区免费| 在线观看日本一区二区| 国产91对白在线观看九色| 成人午夜福利一区二区| 一区二区三区四区在线| 日韩精品一区二区亚洲av| 欧美理论片在线| 色呦呦视频在线| 日韩在线小视频| 男人久久天堂| 成人网页在线免费观看| 牲欧美videos精品| 先锋影音男人资源| 日韩综合一区二区| 一级全黄裸体片| 国产精品视频线看| 在线观看国产亚洲| 欧美一区二区三区的| 黄网在线免费| 欧美—级高清免费播放| 欧美亚洲综合视频| 蜜桃精品久久久久久久免费影院| 亚洲精品va| 日本成人黄色网| 成人97人人超碰人人99| 成人高潮免费视频| 色综合久久88色综合天天免费| 国产丰满美女做爰| 日韩中文娱乐网| 国模套图日韩精品一区二区| 国产精品国产亚洲精品看不卡15| 日韩久久精品| av免费网站观看| www国产精品av| 国产乡下妇女做爰视频| 欧美一区二区在线不卡| yw193.com尤物在线| 日本国产精品视频| 成人h动漫免费观看网站| 激情视频小说图片| 激情久久五月天| 久久视频一区二区三区| 欧美中文字幕一区二区三区| 牛牛热在线视频| 26uuu另类亚洲欧美日本老年| 精品国产18久久久久久洗澡| 91看片淫黄大片91| 国产真实乱子伦精品视频| 亚洲欧美精品久久| 欧美色图在线观看| 午夜小视频在线| 国产精品美女主播| 精品久久网站| 男人女人黄一级| 久久久久国产精品麻豆ai换脸| 亚洲日本视频在线观看| 亚洲精品国产拍免费91在线| free性欧美16hd| 精品国产免费久久久久久尖叫| 亚洲欧洲日本mm| 一出一进一爽一粗一大视频| 亚洲国产精品久久久久婷婷884 | 久久毛片高清国产| yjizz国产| 亚洲欧美日韩成人| 在线成人视屏| 亚洲成人自拍视频| 久久99国产精品免费| 在线免费看av网站| 日韩欧美国产小视频| 麻豆福利在线观看| 国外成人在线视频网站| 99在线观看免费视频精品观看| a级在线观看视频| 日本高清无吗v一区| shkd中文字幕久久在线观看| 国产视频福利一区| 国产精品观看| 少妇大叫太粗太大爽一区二区| 91久久精品一区二区| 浪潮av一区| 成人欧美一区二区三区视频 | 天天干视频在线观看| 日韩**中文字幕毛片| 成久久久网站| 免费不卡av网站| 天天操天天干天天综合网| 精品一二三区视频| 成人黄色免费片| 伊人久久亚洲热| 日本高清黄色片| 欧美一区二区三区四区久久| 瑟瑟视频在线看| 三区精品视频观看| 国产精品99精品久久免费| 国产对白videos麻豆高潮| 国产亚洲精品激情久久| 国产美女精品视频免费播放软件 | 天天干中文字幕| 亚洲国产成人在线播放| 性感美女一区二区在线观看| 国产福利片一区二区| 不卡电影一区二区三区| 中文字幕人妻精品一区| 久久99国产精品自在自在app | 成年人免费高清视频| 综合网中文字幕| 成人免费直播在线| 91av俱乐部| 亚洲成人自拍偷拍| 爱爱爱免费视频在线观看| 国产精品精品软件视频| 美女高潮久久久| 国产做受高潮漫动| 久久久国产精品免费| 国产乱码精品一区二区亚洲 | 天堂一区二区三区四区|