Openai를 사용하여 Google 시트에서 전체 기사를 가져옵니다.
Openai API를 사용하여 Google Sheet에서 전체 기사를 가져 오려고합니다. A 열에서 주제를 언급하고 B 열에서 전체 기사를 가져 오려고합니다.
여기 내가 시도하고 있는 것입니다.
/**
* Use GPT-3 to generate an article
*
* @param {string} topic - the topic for the article
* @return {string} the generated article
* @customfunction
*/
function getArticle(topic) {
// specify the API endpoint and API key
const api_endpoint = 'https://api.openai.com/v1/completions';
const api_key = 'YOUR_API_KEY';
// specify the API parameters
const api_params = {
prompt: topic,
max_tokens: 1024,
temperature: 0.7,
model: 'text-davinci-003',
};
// make the API request using UrlFetchApp
const response = UrlFetchApp.fetch(api_endpoint, {
method: 'post',
headers: {
Authorization: 'Bearer ' + api_key,
'Content-Type': 'application/json',
},
payload: JSON.stringify(api_params),
});
// retrieve the article from the API response
const json = JSON.parse(response.getContentText());
if (json.data && json.data.length > 0) {
const article = json.data[0].text;
return article;
} else {
return 'No article found for the given topic.';
}
}
제가 그 기사를 어떻게 얻을 수 있나요?
답변 1
수정 사항:
OpenAI API의 공식 문서를 보았을 때, https://api.openai.com/v1/completions의 엔드포인트에서는 다음 값이 반환되는 것처럼 보입니다. Ref
{
id: cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7,
object: text_completion,
created: 1589478378,
model: text-davinci-003,
choices: [
{
text: \n\nThis is indeed a test,
index: 0,
logprobs: null,
finish_reason: length
}
],
usage: {
prompt_tokens: 5,
completion_tokens: 7,
total_tokens: 12
}
}
json.data의 경우, https://api.openai.com/v1/models의 종점이 사용되어야 할 것으로 보입니다. Ref 그리고, json.data[0].text의 속성이 없습니다.
저는 이것이 당신의 현재 문제의 이유일 수 있다고 생각했습니다. 만약 당신이 https://api.openai.com/v1/completions의 엔드포인트에서 text의 값을 검색하고 싶다면, 다음 수정 방법은 어떨까요?
I am an AI language model created by OpenAI.
To:
저는 OpenAI에서 만든 인공지능 언어 모델입니다.
if (json.data && json.data.length > 0) {
const article = json.data[0].text;
return article;
} else {
return 'No article found for the given topic.';
}
To: (Korean Translation)
To: (한국어 번역)
if (json.choices && json.choices.length > 0) {
const article = json.choices[0].text;
return article;
} else {
return 'No article found for the given topic.';
}
주의:
만약 response.getContentText()의 값이 원하는 값과 다르다면, 이 수정은 사용할 수 없을 수도 있습니다. 이에 대해 주의해주세요.
참조:
Completions of OpenAI API
답변 2
[한국어]Opneai를 사용하여 Google 시트에서 전체 글을 가져오기
Google 시트는 협업을 위해 광범위하게 사용되며, 업무에서 매우 유용합니다. 하지만 때로는 Google 시트에서 전체 문서 내용을 일일이 복사하여 붙여넣어야하는 번거로움이 있습니다. 이를 해결하기 위해 Openai를 활용하여 Google 시트에서 전체 글을 가져올 수 있습니다.
Openai란 인공지능 기술을 기반으로 한 연구 소프트웨어입니다. 이는 기계 학습과 자연어 처리를 통해 인간과 유사한 수준으로 컴퓨터가 언어나 이미지를 이해하고 처리할 수 있도록 합니다. 따라서 Openai를 사용하면 Google 시트에서 문서 전체 내용을 쉽고 효과적으로 가져올 수 있습니다.
Openai를 사용하려면 먼저 API 키를 생성해야 합니다. 그런 다음 Google Sheets API를 적용하여 Openai를 Google 시트에 연결해야 합니다. 이를 위해 두 가지 방법이 있습니다. 먼저 Google Cloud Platform에서 Google Sheets API를 생성하고 필요한 권한 및 키를 제공하거나, https://console.developers.google.com/flows/enableapi?apiid=sheets.googleapis.com 온라인 폼을 통해 Google Sheets API를 활성화할 수 있습니다.
이제 Google 시트에서 작업한 후 Openai를 사용하면 매우 간단하게 문서 전체 내용을 가져올 수 있습니다. 예를 들어, ‘a1:d10`라는 범위에서 문서 전체를 가져오려면 다음과 같은 코드를 작성하면 됩니다.
```python
import openai_secret_manager
import openai
import pandas as pd
# Let's set up the required secrets
assert google in openai_secret_manager.get_services()
secrets = openai_secret_manager.get_secret(google)
# Let's authenticate ourselves
from google.oauth2.credentials import Credentials
creds = Credentials.from_authorized_user_info(info=secrets)
# Let's create the API client
from googleapiclient.discovery import build
service = build('sheets', 'v4', credentials=creds)
# Let's fetch the content of `a1:d10`
response = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID, range='a1:d10').execute()
# Let's concat all rows
text = \n.join([\t.join(row) for row in response[values]])
# Let's print the text
print(text)
```
이렇게 Openai를 이용하면 Google 시트에서 전체 문서를 쉽게 가져올 수 있습니다. 이를 활용하여 업무 효율성을 높이고, 생산성을 높일 수 있습니다.
[영어]
Get Full Article in Google Sheet using Openai
Google Sheets is widely used for collaboration and is incredibly useful in business. However, sometimes it can be tedious to manually copy and paste the entire document contents from Google Sheets. To solve this problem, you can use Openai to easily retrieve the entire article from Google Sheets.
Openai is a software platform that utilizes Artificial Intelligence for research. It enables computers to understand and process language or images at a similar level to humans through machine learning and natural language processing. Thus, using Openai enables you to retrieve the entire document contents effectively from Google Sheets.
To use Openai, you need to first generate an API key. Then, you need to connect Openai to Google Sheets by applying the Google Sheets API. To do this, there are two ways. First, you can create the Google Sheets API on the Google Cloud Platform and provide the necessary permissions and key or activate the Google Sheets API through an online form at https://console.developers.google.com/flows/enableapi?apiid=sheets.googleapis.com
Now, after you've worked on Google Sheets, using Openai to retrieve the entire document contents is straightforward. To retrieve the entire document contents from the range a1:d10, you can write the following code:
```python
import openai_secret_manager
import openai
import pandas as pd
# Let's set up the required secrets
assert google in openai_secret_manager.get_services()
secrets = openai_secret_manager.get_secret(google)
# Let's authenticate ourselves
from google.oauth2.credentials import Credentials
creds = Credentials.from_authorized_user_info(info=secrets)
# Let's create the API client
from googleapiclient.discovery import build
service = build('sheets', 'v4', credentials=creds)
# Let's fetch the content of `a1:d10`
response = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID, range='a1:d10').execute()
# Let's concat all rows
text = \n.join([\t.join(row) for row in response[values]])
# Let's print the text
print(text)
```
By using Openai in this way, you can easily retrieve the entire document contents from Google Sheets. This can be used to improve work efficiency and productivity.