스택큐힙리스트

엑셀 매크로(VBA)에서 ChatGPT에 API를 사용하여 어떻게 요청할 수 있나요? 본문

카테고리 없음

엑셀 매크로(VBA)에서 ChatGPT에 API를 사용하여 어떻게 요청할 수 있나요?

스택큐힙리스트 2023. 3. 29. 01:31
반응형

저는 엑셀을 사용하여 ChatGPT 질문을하는 것이 좋습니다. 그리고 그것들을 다시 다른 셀에서 얻고 싶습니다. A1 셀에 제공되는 API가 있습니다. 질문은 A3에서 가져와야하고 답변은 A6에 있어야합니다.

Sub SendQuestionToGPT3()

'Declare variables

Dim request As Object

Dim response As String

Dim API As String

API = Worksheets(API).Range(A1).Value

'Set the question in a variable

Dim question As String

question = Range(A3).Value

'Create an HTTP request object

Set request = CreateObject(MSXML2.XMLHTTP)

'Set the API endpoint and make the request

request.Open POST, https://api.openai.com/v1/engines/davinci/jobs, False

request.setRequestHeader Content-Type, application/json

request.setRequestHeader Authorization, Bearer & API

request.send {prompt: & question & ,max_tokens:1000}

'Get the response and parse it into a string

response = request.responseText

response = Replace(response, ,choices:[], )

response = Replace(response, text:, )

response = Replace(response, }, )

'Display the response in a cell

Range(A6).Value = response

'Clean up the object

Set request = Nothing

End Sub

하지만 내가 이 오류를 받았습니다:

{

error: {

message: 이 모델에 대한 알 수없는 엔드포인트입니다.,

type: 유효하지 않은 요청 오류,

param: null,

code: null

}

}

이 코드에 어떤 문제가 있나요?

감사합니다!

답변 1

도움이 되는 몇 가지 요령입니다.

the Engines endpoints는 사용하지 마세요. 이제는 사용이 중지된 기능입니다.

GET https://api.openai.com/v1/engines/davinci/

또한 엔진 엔드포인트는 자동 응답을 받지 않습니다. 그것이 하는 일은

현재 사용 가능한 (미세 조정되지 않은) 모델 목록을 제공하며, 각각의 소유자 및 이용 가능성과 같은 기본적인 정보를 제공합니다.

대신 the Completion endpoint을 사용하세요.

POST https://api.openai.com/v1/completions

API를 사용하기 위해서는 요청에 model 를 추가해야 합니다. 이렇게 해보세요.

{

model: text-davinci-003,

prompt: How are you?,

max_tokens: 256

}

그게 도움이 되길 바래요.

답변 2

Excel is a powerful tool for data and analysis, and sometimes we need to integrate other applications or services with it to get our job done effectively. ChatGPT is an AI-powered chatbot platform that can help answer questions, provide recommendations, and automate tasks. In this article, we will explore how to use ChatGPT's API from Excel macros (VBA) to get answers to our questions or automate tasks.

First, let's understand what an API is. An API (Application Programming Interface) is a set of protocols, routines, and tools for building software applications. It provides access to an application's data or functionality in a structured and controlled way. ChatGPT's API enables you to interact with its chatbot platform programmatically.

To use ChatGPT's API from Excel macros, we need to follow these steps:

1. Sign up for ChatGPT API: To use ChatGPT's API, we need to create an account on their website and get an API key.

2. Define a macro in Excel: On the Excel workbook, we define a macro, which is a set of instructions that automate certain tasks. Using VBA (Visual Basic for Applications), we can define a macro that sends a request to ChatGPT's API with our question and receives the answer.

3. Call ChatGPT API: In VBA, we use the XMLHttpRequest object to send a request to ChatGPT's API with our API key, question, and other parameters. We then receive the response in JSON format, which we can parse and extract the answer from.

4. Display the answer in Excel: Once we have the answer, we can display it in Excel, either by writing it to a cell or displaying it in a message box.

Using ChatGPT's API from Excel macros can help automate repetitive tasks like data entry, report generation, or analysis. For example, we can ask ChatGPT to provide recommendations for a product based on customer reviews, or help us understand complex data analysis concepts.

In conclusion, we have seen how to use ChatGPT's API from Excel macros (VBA) to get answers to our questions or automate tasks. With the power of AI-powered chatbots, we can leverage their knowledge and expertise to get our job done effectively. By integrating ChatGPT's API with Excel, we can streamline our workflows and improve our productivity.

반응형
Comments