Board logo

标题: [文本处理] 可否根据CURL和PHP和Python实例写个vba? [打印本页]

作者: 877    时间: 2023-12-17 14:28     标题: 可否根据CURL和PHP和Python实例写个vba?

本帖最后由 877 于 2023-12-17 21:23 编辑

根据以下实例,写一个excel可用的VBA,有大佬会吗?
CURL 实例
PHP 实例
Python 实例
javascript 实例
typescript 实例
java 实例
go 实例
作者: jyswjjgdwtdtj    时间: 2023-12-17 21:56

什么实例?
作者: 877    时间: 2023-12-17 22:24

回复 2# jyswjjgdwtdtj


    这是一个CURL实例,根据这个实例做一个可以用在excel里面的vba
  1. curl --request POST \
  2.   --url 地址
  3.   --header 'Authorization: Bearer 替换为你的key' \
  4.   -H "Content-Type: application/json" \
  5.   --data '{
  6.     "max_tokens": 1200,
  7.     "model": "gpt-3.5-turbo",
  8.     "temperature": 0.8,
  9.     "top_p": 1,
  10.     "presence_penalty": 1,
  11.     "messages": [
  12.         {
  13.             "role": "system",
  14.             "content": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible."
  15.         },
  16.         {
  17.             "role": "user",
  18.             "content": "你是chatGPT多少?"
  19.         }
  20.     ]
  21. }'
复制代码

作者: 877    时间: 2023-12-17 22:26

回复 2# jyswjjgdwtdtj


    这个一个openai用在excel里面的vba,只修改它的地址和key,用不了。所以要根据上面那个实例修改~
  1. Function ChatGPT(prompt As String) As String
  2. Dim url As String, apiKey As String
  3. Dim response As Object, re As String
  4. Dim midString As String
  5. apiKey = "your_api_key"
  6. url = "https://api.openai.com/v1/engines/text-davinci-003/completions"
  7. Set response = CreateObject("MSXML2.XMLHTTP")
  8. response.Open "POST", url, False
  9. response.setRequestHeader "Content-Type", "application/json"
  10. response.setRequestHeader "Authorization", "Bearer " + apiKey
  11. response.Send "{""prompt"":""" & prompt & """,""max_tokens"":1024, ""temperature"":0.1}"
  12. re = response.responseText
  13. midString = Mid(re, InStr(re, """text"":""") + 8)
  14. ChatGPT = Split(midString, """")(0)
  15. ChatGPT = Replace(ChatGPT, "\n", "")
  16. End Function
复制代码

作者: wanghan519    时间: 2023-12-18 05:06

本帖最后由 wanghan519 于 2023-12-18 05:43 编辑

vba可以通过wscript.shell调用上面任何一个实例,或者打包成xll都行
问题是给出的curl实例连认证都没有,估计是用不了的啊。。。

之后搜了一下,好像是api2d.com的api,还是要收费的啊。。。
作者: 877    时间: 2023-12-18 12:43

回复 5# wanghan519
接口是收费的,还是感谢大佬了~谢谢




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2